1

My intention is to apply an image overlay with fade effect on specific time in the video as well as applying a background audio to the video in a single command. Video will also be limited to only 15 seconds.

Currently, I'm able to achieve this through 2 command, which would in return produce 2 output, how can I merge this 2 commands together?

First Command

ffmpeg -i video.mp4 -loop 1 -i image.png -ss 00:00:00 -t 00:00:15 -filter_complex "[1]format=yuva420p,fade=in:st=12:d=0.5:alpha=1[i]; [0][i]overlay=main_w/2-overlay_w/2-0+0:main_h/2-overlay_h/2-0+0:shortest=1"  incomplete.mp4

Second Command

ffmpeg -i audio.mp3 -i incomplete.mp4 -shortest finalVideo.mp4

This is my attempt in merging the two commands into a single command, however the video is no longer limited at 15 seconds now and the background audio only applies to few video after tested with several mp4 videos.

ffmpeg -i video.mp4 -loop 1 -i image.png -ss 00:00:00 -t 00:00:15 -i audio.mp3 -shortest -filter_complex "[1]format=yuva420p,fade=in:st=12:d=0.5:alpha=1[i]; [0][i]overlay=main_w/2-overlay_w/2-0+0:main_h/2-overlay_h/2-0+0:shortest=1"  finalVideo.mp4
0

Use

ffmpeg -ss 00:00:00 -t 00:00:15 -i video.mp4 -loop 1 -i image.png -i audio.mp3
  -filter_complex "[1]format=yuva420p,fade=in:st=12:d=0.5:alpha=1[i]; 
                   [0][i]overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2:shortest=1[v]"
  -map "[v]" -map 2:a -shortest  incomplete.mp4

In ffmpeg, option placement matters. Any option before an input applies to that input only. In your attempted combined command, you input the audio after the time specifications so they become specific to the audio input only.

FFmpeg uses a mapping system to decide which streams to include into the output. When no map assignments are explicitly set, the default mapping selects one audio from among the inputs. Looks like some of your MP4s had audio streams which got prioritized over the MP3. With explicit assignments, that won't happen.

  • Thank you so much, command works exactly as needed and also thumbs up for the easy-to-understand explanations. – Daryl Mar 18 '17 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.