Is there any formula that I can use to calculate the time that FFmpeg uses to convert a single .jpg image and .mp3 song to a video?
I am using the following code:
ffmpeg -loop 1 -r ntsc -i image.jpg -i song.mp3 -c:a copy -c:v libx264 \
-preset fast -threads 0 -shortest
Lets say we have an image with X resolution and .mp3 length of L. Would the formula be:
time = X * L(in seconds) ?
Thanks for any tips.
Use -r 1
, it is faster
ffmpeg -loop 1 -r 1 -i image.jpg -i song.mp3 -c:a copy -c:v libx264 \
-preset fast -threads 0 -shortest
ref
First, run benchmark with key "-t 10" this mean 10 seconds benchmark and calculate run time.
ffmpeg -i .......... -t 10 -f null - -benchmark
Benchmark output, with runtime: utime:
bench: utime=3.203s
bench: maxrss=215036kB
[aac @ 0000026cb6474600] Qavg: 1569.054
First Of All Call this method from OnProgress Method of FFmpeg Listener
public void onProgress(String s) {
getProgress(s);
Log.e("Editor", "String ==== " + s);
}
getProgress(s) is a method that find Estimate Time of Our execution
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);
}