Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg: concat videos and images

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.

like image 759
Yosko Avatar asked Aug 26 '13 19:08

Yosko


People also ask

How do I combine two videos with FFmpeg?

Use FFmpeg concat to merge videos When using FFmpeg to merge a series of video clips, the process is called concatenation, or concat for short. There are several ways that videos can be concatenated, depending on whether the individual videos share the same codec or not.

How do I combine two videos in android programmatically FFmpeg?

ffmpeg -f concat -i mylist.txt -c copy output.mp4 This process is a way of concatenating the files and not re-encoding. Hence, it should be done speedily & conveniently. If there is no error message, you are sure to receive a final merged video named by 'output. mp4' in the MP4 folder.


1 Answers

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.

like image 167
Jared Avatar answered Sep 22 '22 15:09

Jared