Search code examples
videoffmpegvideo-processing

Concatenate multiple videos with a black screen loop into one video


I am using ffmpeg to join a bunch of videos together.
I am using the classic join ffmpeg code:

ffmpeg -f concat -i joinlist.txt -c copy joinedfile.mp4

but the problem is that the videos are of different formats, encodings, but the same size: all 640x480. I want to join them all and put a black screen video with no sound every other video:

video1 + black_screen_video + video2 + black_screen_video + video3 ...

I generated a black screen video of 2 seconds duration using:

ffmpeg -f lavfi -i color=c=black:s=640x480:d=2 black_screen_video.mp4

so all of the videos are of the same size: 640x480, and 25 fps but different codecs. The videos have sound, except for the black screen video. I can't do anything manual, because the number of videos are around several hundred. So it has got to be an automatic way to do all this.

When I joined them together using the above code, the resulting video does not play correctly at all.

I know that I have to re-encode them, but how to do this to all these videos at once, with one line of code?

Update: I am already using with success this code to join them together, but only three, if I have more than one hundred, it is time consuming to write down one by one:

ffmpeg -i vid1.avi -i vid2.avi -i vid3.avi -filter_complex "[0:v:0] [0:a:0] [1:v:0] [1:a:0] [2:v:0] [2:a:0] concat=n=3:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4

but this is joining only the videos, not looping the black screen video. When I do with black screen, ffmpeg gives me stream matching errors.

update:


here is the console image: enter image description here

2nd update:

a very long list of errors in red, of which a screenshot here: enter image description here


Solution

  • Use the concat demuxer, as before.

    Your text file will be:

    file 'vid1.avi'
    file 'black_screen_video.mp4'
    file 'vid2.avi'
    file 'black_screen_video.mp4'
    file 'vid3.avi'
    file 'black_screen_video.mp4'
    ...
    

    And your command:

    ffmpeg -f concat -i joinlist.txt joinedfile.mp4
    

    You also need to include a dummy audio in the black screen video.

    ffmpeg -f lavfi -i color=c=black:s=640x480:d=2 -f lavfi -i aevalsrc=0:c=2:d=2 black_screen_video.mp4