FFMpeg: merge images with audio for specific durat

2019-08-12 02:32发布

I have been working on FFMpeg from past 7 days. I am required to create a video where I need to perform following:

  1. Concat few images into video picked from android storage.
  2. Add a music file [same picked from android storage].
  3. Set Duration per image to be shown in the video. e.g. if 3 images are picked then total duration of video should be 3*duration choosen by user.

What I have done so far.

I am using implementation 'nl.bravobit:android-ffmpeg:1.1.5' for the FFmpeg prebuild binaries. Following is the command that has been used to concatenation the images and set the duration:

ffmpeg -r 1/duration_selected_by_user -f concat -safe 0 -i path_of_concat_file.txt -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p path_of_output_video_file.mp4 

Note:

  1. By adding the duration chosen by a user as frame rate I am able to set the duration of each image to be shown.
  2. Concat work well and images are merged to for the video.

Problem: When I try to add audio in the same process, progress run for a long time even for small audio by using the following command:

ffmpeg -r 1/duration_selected_by_user -i path_of_audio_file.mp3 -f concat -safe 0 -i path_of_concat_file.txt -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p path_of_output_video_file.mp4

It looks like there is some issue in command as I am not much familiar and experienced with the technology. How can I improve the performance of merging images and audio to get the better results?

Important Links related to context:

https://github.com/bravobit/FFmpeg-Android

1条回答
我命由我不由天
2楼-- · 2019-08-12 03:09

As @HB mentioned in the comments:

Try adding -preset ultrafast after -pix_fmt yuv420p

A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). This means that, for example, if you target a certain file size or constant bit rate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset. The available presets in descending order of speed are:

  • ultrafast
  • superfast
  • veryfast
  • faster
  • fast
  • medium – default preset
  • slow
  • slower
  • veryslow
  • placebo – ignore this as it is not useful

Reference: https://trac.ffmpeg.org/wiki/Encode/H.264#Preset

查看更多
登录 后发表回答