0

I have 2 T-seconds-long videos that are made from PNG images using the following commands:

ffmpeg -i workspace/1.png -vcodec libx264 -t T ./1.mp4
ffmpeg -i workspace/2.png -vcodec libx264 -t T ./2.mp4

Using those videos, I'm trying to create a transition between those 2 videos that lasts for T seconds, where we start with the first video and fade into the second one. Here's a simple ASCII visualization of the transition I have in mind:

Alpha \ Time    0.........T
1.mp4         100.........0
2.mp4           0.......100

So, both the videos, as well as the fade effect should start immediately, and end with the video itself. (i.e., offset is 0 and duration is T)

But when I try to produce such a video, the resulting MP4 just consists of the video of 1.mp4, with no fade effect whatsoever. Here's the command I used for producing the transition video:

ffmpeg -i 1.mp4 -i 2.mp4 -y -filter_complex "xfade=transition=fade:offset=0:duration=T" -t T ./1-2.mp4

I thought the offset and duration parameters in that filter_complex option were enough to get the transition going.

I've looked at similar StackOverflow questions, but in all of those the fade effect was between the videos that run sequentially, not in parallel. Is that what's happening here? How do I make both videos run in parallel from the start, while the fade is being applied to them?

ilim
  • 4,477
  • 7
  • 27
  • 46

1 Answers1

0
  1. You did not loop the images so your videos are only 1 frame long.
  2. xfade offset is the timestamp when you want the transition to occur.

Example. Each image is 5 seconds long. A 1-second crossfade from 1.png to 2.png will occur 4 seconds from the beginning of 1.png. output.mp4 will be 9 seconds long.

ffmpeg -loop 1 -t 5 -i 1.png -loop 1 -t 5 -i 2.png -filter_complex "xfade=transition=fade:offset=4:duration=1,format=yuv420p" -movflags +faststart output.mp4

See:

llogan
  • 121,796
  • 28
  • 232
  • 243