Losing seconds on xfade concat

Hello guys i have some issues with xfade concat.

I have 4 videos:

1st has 20 seconds.

2nd has 6 seconds.

3rd has 5 seconds.

4th has 9 seconds.

Total: 40 seconds.

ffmpeg -y -c:v h264_cuvid -i 0.mp4 -i 1.mp4 -i 2.mp4 -i 3.mp4 -filter_complex " [0][1]xfade=transition=fade:duration=1:offset=20,format=yuv420p[1v];[1v][2]xfade=transition=fade:duration=1:offset=26,format=yuv420p[2v];[2v][3]xfade=transition=fade:duration=1:offset=31,format=yuv420p[v] " -c:v h264_nvenc -b:v 10M -r 25 -map "[v]" finalVideo.mp4

With this command I manage to get 40 seconds video, but it blocks in the middle, so it doesn't work.

ffmpeg -y -c:v h264_cuvid -i 0.mp4 -i 1.mp4 -i 2.mp4 -i 3.mp4 -filter_complex " [0][1]xfade=transition=fade:duration=1:offset=19,format=yuv420p[1v];[1v][2]xfade=transition=fade:duration=1:offset=24,format=yuv420p[2v];[2v][3]xfade=transition=fade:duration=1:offset=29,format=yuv420p[v] " -c:v h264_nvenc -b:v 10M -r 25 -map "[v]" finalVideo.mp4

With 2nd command I manage to make it work but now it has 38 seconds.So where does the seconds go? I used this tool, https://romander.github.io/ffmpeg-script-generator/

https://i.stack.imgur.com/LA2se.png

but still not good.

I want to have 40 seconds with with transitions.

Here is another try @llogan

https://i.stack.imgur.com/3XU3X.png


xfade transitions consume time

The transitions in xfade take up time, so the output duration will not equal the sum of the input durations.

Simple illustration: each input is 3 seconds long and the fade transition is 1 second long where the videos overlap. Result is a 5 second output.

12345
===
  ===

Add freeze frame to end of each video

You can use the tpad filter to add more time to the video to be sacrificed to xfade. However, the result might look weird due to the freeze frame effect.

ffmpeg -i input0.mp4 -i input1.mp4 -filter_complex "[0:v]tpad=stop_mode=clone:stop_duration=1[v0];[v0][1:v]xfade=transition=fade:duration=1:offset=10" output.mp4

Use the fade + concat filters

If you want to avoid a shorter output duration then another method is to use black fades (or whatever color you want) with the fade filter and concatenate with the concat filter:

ffmpeg -i 20sec.mp4 -i 6sec.mp4 -i 5sec.mp4 -i 9sec.mp4 -filter_complex "[0]fade=t=out:st=19.5:d=0.5[fade1];[1]fade=t=in:st=0:d=0.5,fade=t=out:st=5.5:d=0.5[fade2];[2]fade=t=in:st=0:d=0.5,fade=t=out:st=4.5:d=0.5[fade3];[3]fade=t=in:st=0:d=0.5[fade4];[fade1][fade2][fade3][fade4]concat=n=4:v=1:a=0" output.mp4