1

i'm a bit at loss here. My goal is to merge two video files (which might be of different file formats) and i'm already using libffmpeg for other simple tasks. I thought libffmpeg exposed some kind of function to merge files, but i can't find it.

I found these pages on the documentation that might be relevant: http://ffmpeg.org/doxygen/trunk/structConcatStream.html and http://ffmpeg.org/doxygen/trunk/group__lavf__encoding.html

I'm not sure if this is really relevant though? Can anybody point me in the right direction? Do i need to use FFmpeg muxing and manually joins streams? Is there any example that can explain to me what i should do? thanks!

Andrea
  • 495
  • 5
  • 15

2 Answers2

3

For those looking for an example, i ended up using

How to use libavformat to concat 2 video files with same codec (re-muxing)?

there's a nice snippet and it works very well

Community
  • 1
  • 1
Andrea
  • 495
  • 5
  • 15
1

Use ffmpeg to open file 1, start reading frames, converting to target format, and writing to the output file. When there are no more frames, close file 1 (leave output open). Open file 2, start reading frames, converting to target format, and writing to the output file. When there are no more frames, close file 2 and close output.

Merged and formats reconciled.

LawfulEvil
  • 2,267
  • 24
  • 46
  • thanks, but there has to be a better way. I know how to do what you said, and yet, it feels like i'm doing the heavy lifting rather than libffmpeg. Are you saying there is NO out of the box merge system in libffmpeg ? Sorry if i sound skeptical, but i find this very difficult to believe. – Andrea Mar 10 '15 at 13:24
  • 1
    If you want to use the command line tool, use concatenate. https://trac.ffmpeg.org/wiki/Concatenate but if you are doing programmatically... you'd have to do all the frame conversions and file writing and such. You should be able to lift the code for concatenate though as I believe its included with the libffmpeg distribution. Also see http://stackoverflow.com/questions/7333232/concatenate-two-mp4-files-using-ffmpeg – LawfulEvil Mar 10 '15 at 13:44
  • i need to do it via library, can't bundle the ffmpeg executable. I'm pretty sure there is a better way via the muxer, but oh well.. – Andrea Mar 10 '15 at 13:48
  • Depending on the container type, it might be just a matter of copying file 2 to the end of file1. I know MPEG-2 and some other formats allow this sort of concatenation. That said, its easy enough to write a small helper to invoke the ffmpeg stuff and write to a file. But, like I said, check out what 'concat' does from the command line and lift the code for your app. – LawfulEvil Mar 10 '15 at 13:57