ffmpeg: concat videos and images

18.5k views Asked by At

I have 2 videos (same resolution, same encoding) files that I want to concat and I want to insert some text for 3 seconds between them, as a splitter. I'm doing this with ffmpeg on Windows.

Optional ideas that I would be interested in:

  • avoid reencoding the video in the process
  • having a fade in / fade out at the intersection of each part

For now, I made the text as an image (but I am open to other suggestions). Let's say I have:

  • video1.mp4: 6:33
  • splitter.png (same resolution as video1.mp4)
  • video2.mp4: 16:44

I have tried a few things, but I always end up with the same problem: the video is 23:20 (video1 + 3 seconds + video2), but the 3 seconds gap is just the last video1 frame frozen instead of my image/text...

Any Idea what I did wrong or how I should achieve this?

Here is what I tried so far:

Method 1: image to video

Turn the image into a 3 seconds mp4 film, then concat (demuxer) it with the others:

ffmpeg -loop 1 -f image2 -i splitter.png -r 30 -t 3 splitter.mp4
ffmpeg -f concat -i input.txt -codec copy output.mp4

Where the input.txt looks like:

file 'E:\video1.mp4'
file 'E:\splitter.mp4'
file 'E:\video2.mp4'

The content of splitter.png is visible in the splitter.mp4, but not in the output.mp4. Also I'm not entirely sure the splitter.mp4 respects the exact same encoding as the 2 videos, and I don't know how to verify that.

Method 2: insert image frames

Directly run the concat (demuxer) 90 times (30fps -> 3 seconds) on the image

ffmpeg -f concat -i input.txt -codec copy output.mp4

Where the input.txt looks like:

file 'E:\video1.mp4'
file 'E:\splitter.png'
...
file 'E:\splitter.png'
file 'E:\video2.mp4'

Edit: possible solution?

Since all I'm doing is screencasting, I might as well screencast my splitter image. This way I would be sure of the audio & video encoding and wouldn't have any problem merging and it wouldn't need any reencoding... I know it might sound dumb, but it would probably do the trick...

Note: I didn't have try it, since I already worked through Openshot.

1

There are 1 answers

4
Jared On

My guess is this is all a codec issue -- the PNG turned MP4 is probably not the same codec as your real MP4s.

Try this -- concatenation of files of different codecs.