ffmpeg: concat videos and images

16,461

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.

Share:
16,461
Yosko
Author by

Yosko

Updated on August 05, 2022

Comments

  • Yosko
    Yosko almost 2 years

    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.

  • Yosko
    Yosko almost 11 years
    Sounds like a good idea. But in the example given in your link, ffmpeg expects audio stream in every video. My splitter.mp4 only have video stream. I'm not sure how to handle that...
  • Jared
    Jared almost 11 years
    Just an idea, but are your image videos all different lengths? Otherwise you could always just include a wav (or other) file of silence.
  • Yosko
    Yosko almost 11 years
    Not sure what the "different lenghts" was about, but adding a silent but real stream to the splitter sounds good. I'm trying it. Doesn't seem to work, but I need to search on my own for now. I'll be back tomorrow. Thanks :)
  • Yosko
    Yosko almost 11 years
    The idea was a good one, although it didn't work in the end: I have other issues with the video stream of my splitter... Anyway, I ended installing ubuntu+openshot (yeah, I was that desperate) and it did the trick... Still, thanks for your help