【问题标题】:FFmpeg: calculate time to convert images and .mp3 to a videoFFmpeg:计算将图像和 .mp3 转换为视频的时间
【发布时间】:2013-03-27 16:58:33
【问题描述】:

有没有什么公式可以用来计算 FFmpeg 将单个 .jpg 图像和 .mp3 歌曲转换为视频所用的时间?

我正在使用以下代码:

ffmpeg -loop 1 -r ntsc -i image.jpg -i song.mp3 -c:a copy -c:v libx264 \ -preset fast -threads 0 -shortest

假设我们有一张 X 分辨率和 .mp3 长度为 L 的图像。公式是:

time = X * L(in seconds) ?

感谢任何提示。

【问题讨论】:

    标签: image video ffmpeg


    【解决方案1】:

    首先,使用键“-t 10”运行基准测试,这意味着 10 秒基准测试并计算运行时间。

    ffmpeg -i .......... -t 10 -f null - -benchmark
    

    基准输出,运行时:utime

    bench: utime=3.203s
    bench: maxrss=215036kB
    [aac @ 0000026cb6474600] Qavg: 1569.054
    

    【讨论】:

      【解决方案2】:

      首先从 FFmpeg 监听器的 OnProgress 方法调用这个方法

       public void onProgress(String s) {
                  getProgress(s);
                  Log.e("Editor", "String ==== " + s);
          }
      

      getProgress(s) 是一种查找我们执行的估计时间的方法

       private void getProgress(String message) {
                  Pattern pattern = Pattern.compile("time=([\\d\\w:]{8}[\\w.][\\d]+)");
                  Matcher matcher = pattern.matcher(message);
                  matcher.find();
                  String tempTime = String.valueOf(matcher.group(1));
                  Log.d(TAG, "getProgress: tempTime " + tempTime);
                  String[] arrayTime = tempTime.split("[:|.]");
                  long currentTime =
                          TimeUnit.HOURS.toMillis(Long.parseLong(arrayTime[0]))
                                  + TimeUnit.MINUTES.toMillis(Long.parseLong(arrayTime[1]))
                                  + TimeUnit.SECONDS.toMillis(Long.parseLong(arrayTime[2]))
                                  + Long.parseLong(arrayTime[3]);
      
                  String speed;
                  speed = message.substring(message.indexOf("speed=") + 1, message.indexOf("x")).split("=")[1];
      
                  long percent = 100 * currentTime / videoLengthInMillis;
                  long time = TimeUnit.HOURS.toMillis(Long.parseLong(arrayTime[0])) * 3600 + TimeUnit.MINUTES.toMillis(Long.parseLong(arrayTime[1])) * 60 + TimeUnit.SECONDS.toMillis(Long.parseLong(arrayTime[2])) + Math.round(Long.parseLong(arrayTime[3]));
                  long ETA = Math.round((Math.round(videoLengthInMillis) - time) / Float.valueOf(speed));
                  Log.e(TAG, "currentTime -> " + currentTime + "s % -> " + percent);
                  Log.e(TAG, "ETA -> " + ETA);
      
                  progressBar.setProgress((int) percent);
                  String EstimateTime = convertSecondsToHMmSs(ETA);
                  Log.e(TAG, "EstimateTime -> " + EstimateTime);
                  ProcessTime.setText(EstimateTime);
              } 
      

      ConvertSecondToHMmSs

      public static String convertSecondsToHMmSs(long millis) {
      
          long seconds=(millis/1000);
          long s = seconds % 60;
          long m = (seconds / 60) % 60;
          long h = (seconds / (60 * 60)) % 24;
          return String.format("%d:%02d:%02d", h,m,s);
      }
      

      【讨论】:

        【解决方案3】:

        使用-r 1,更快

        ffmpeg -loop 1 -r 1 -i image.jpg -i song.mp3 -c:a copy -c:v libx264 \ -preset fast -threads 0 -shortest

        ref

        【讨论】:

        • 感谢史蒂文。你能解释一下参数-r 1是什么吗?另外,您对如何计算完成编码所需的时间有任何线索吗?感谢您的帮助
        • r 代表“比特率”
        • 应该是-framerate,而不是image muxer documentation所规定的-r
        猜你喜欢
        • 2017-02-26
        • 2020-08-25
        • 2014-03-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多