5

Is there any way to concat two video files with a fading effect using FFmpeg?

Something like this:

ffmpeg -f concat -i input.txt -c copy "--with:fade:out-in" output.ogg

3 Answers 3

11

Your present command specifies stream copy. Since you wish to alter the video frames during the transition, that won't work.

It can be done if you know the duration of the two videos and the duration of fade. Also, for the command below, the resolutions of the two videos should be the same.

ffmpeg -i first.ogg -i second.ogg \
-filter_complex \
"color=black:WxH:d=Video1Length+Video2Length-FadeDuration[base]; \
 [0:v]setpts=PTS-STARTPTS[v0]; \
 [1:v]format=yuva420p,fade=in:st=0:d=FadeDuration:alpha=1, \
      setpts=PTS-STARTPTS+((Video1Length-FadeDuration)/TB)[v1]; \
 [base][v0]overlay[tmp]; \
 [tmp][v1]overlay,format=yuv420p[fv]; \
 [0:a][1:a]acrossfade=d=FadeDuration[fa]" \
-map [fv] -map [fa] \
output.ogg

Replace:

WxH with the resolution of the videos i.e. 640x360

And:

Video1Length, Video2Length, and FadeDuration with their value in seconds.

3
  • what about adding a third, fourth, or nth video? I conceptualize this by running the above on first.ogg and second.ogg, producing output1.ogg. Then I would run the script with output1.ogg and third.ogg to get output2.ogg (and so on up to output[n-1].ogg). Is this efficient or is there a better way to do it all at once? Mar 1, 2019 at 5:44
  • 1
    I tried to use "ffmpeg-gl-transition" and followed all instruction for my mac. The transition works. However, I loose audio on my second video for some reason. My command was: fmpeg -i input1.mp4 -i input2.mp4 -filter_complex "gltransition=duration=4:source=ZoomInCircles.glsl" -y out.mp4
    – Rajesh M
    Nov 29, 2019 at 13:04
  • Why would you overlay the first video over a black screen? It looks like waste of resources as it does nothing.
    – Alexander
    Oct 29, 2020 at 11:49
5

ffmpeg-concat is the easiest way to accomplish what you want and allows you to use a bunch of sexy OpenGL transitions, with the default being crossfade.

ffmpeg-gl-transition is a custom ffmpeg filter which allows you to use GLSL to smoothly transition between two video streams. This filter is significantly easier to use and customize than the alternatives listed here.

This filter supports a large list of transition types, with the default being crossfade.

./ffmpeg -i 0.mp4 -i 1.mp4 -filter_complex "gltransition=duration=4:offset=1.5" out.mp4
5
  • Have you submitted this to ffmpeg-devel for integration?
    – Gyan
    Dec 6, 2017 at 6:11
  • Official patch will be coming soon :)
    – fisch2
    Dec 6, 2017 at 8:27
  • @fisch2 Any updates? Aug 24, 2021 at 12:09
  • Note, ffmpeg-concat requires Python. Jan 24, 2022 at 15:19
  • I installed Python on my Mac, but still it raise many error when installing ffmpeg-concat
    – János
    Feb 11 at 5:48
4

I've created a little site recently for generating the FFmpeg CLI command to create xfade + acrossfade command for several videos. Check it out maybe you find it useful.

https://romander.github.io/ffmpeg-script-generator/

Add also you can check source code or contribute

https://github.com/Romander/ffmpeg-script-generator

3
  • 1
    This is a great idea but it doesn't seem to produce working code. This is what I get after entering two inputs. Mar 2, 2021 at 21:39
  • @HashimAziz Do you really input everything correct it should look like that screenshot, sorry for the inconvenient UI Mar 10, 2021 at 19:53
  • @RomanOgoreltsev I have tried and find that your website is very helpful. Thanks a lot!
    – blackr1234
    Jun 16, 2022 at 18:05

Your Answer

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

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