0
ffmpeg -y -i intro.mp4 -i video.mp4  -i outro.mp4 -f lavfi -i color=black:s=1280x720 -filter_complex \
"[0:v]format=pix_fmts=yuva420p,fade=t=out:st=10:d=1:alpha=1,setpts=PTS-STARTPTS[v0]; \
 [1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,fade=t=out:st=10:d=1:alpha=1,setpts=PTS-STARTPTS+10/TB[v1]; \
 [2:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,fade=t=out:st=10:d=1:alpha=1,setpts=PTS-STARTPTS+20/TB[v2]; \
 [3:v]trim=duration=30[over]; \
 [over][v0]overlay[over1]; \
 [over1][v1]overlay[over2]; \
 [over2][v2]overlay=format=yuv420[outv]" \
-vcodec libx264 -map '[outv]' merge.mp4

1 Answer 1

0

Your fade out timings are one second too late - the fade out should start at 9 seconds of each clip so that it can end by 10 seconds.

ffmpeg -y -i intro.mp4 -i video.mp4  -i outro.mp4 -f lavfi -i color=black:s=1280x720:d=30 -filter_complex \
"[0:v]format=pix_fmts=yuva420p,fade=t=out:st=9:d=1:alpha=1,setpts=PTS-STARTPTS[v0]; \
 [1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,fade=t=out:st=9:d=1:alpha=1,setpts=PTS-STARTPTS+10/TB[v1]; \
 [2:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,fade=t=out:st=9:d=1:alpha=1,setpts=PTS-STARTPTS+20/TB[v2]; \
 [3][v0]overlay[over1]; \
 [over1][v1]overlay[over2]; \
 [over2][v2]overlay=format=yuv420[outv]" \
-vcodec libx264 -map '[outv]' merge.mp4

If you have audio as well in the 3 files, use

ffmpeg -y -i intro.mp4 -i video.mp4  -i outro.mp4 -f lavfi -i color=black:s=1280x720:d=30 -filter_complex \
"[0:v]format=pix_fmts=yuva420p,fade=t=out:st=9:d=1:alpha=1,setpts=PTS-STARTPTS[v0]; \
 [1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,fade=t=out:st=9:d=1:alpha=1,setpts=PTS-STARTPTS+10/TB[v1]; \
 [2:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,fade=t=out:st=9:d=1:alpha=1,setpts=PTS-STARTPTS+20/TB[v2]; \
 [3][v0]overlay[over1]; \
 [over1][v1]overlay[over2]; \
 [over2][v2]overlay=format=yuv420[outv]; \
 [0][1][2]concat=n=3:v=0:a=1[outa]" \
-vcodec libx264 -map '[outv]' -map '[outa]' merge.mp4

This command assumes that all 3 files have 10 seconds of audio each, eolse sync will be lost.

3
  • this command works but voice is disabled. so how to enable audio? May 11, 2018 at 12:42
  • How to know video file has audio? we will have with audio and without audio so which command do you think is best for this purpose? May 11, 2018 at 13:25
  • Run ffprobe -v 0 -select_streams a -show_entries stream=index -of compact=p=0:nk=1 "$file" | wc -l . If it's zero, no audio in $file
    – Gyan
    May 11, 2018 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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