3

I'm new to the community, as well as novice in the Pi family. I want to stitch several videos (for example 5). I tried using FFmpeg, but the output was only first input video file.

I was running this code:

ffmpeg -i video1.h264 -i video2.h264 output1.mpg
3

You can't specify multiple inputs for FFMPEG like that. You can, however, use the concat option, as described in FFMPEG's documentation. There are different forms depending on whether you're joining files with different codecs or not. It's worth reading all of the documentation - there are more than a few caveats and options in there.

Files with the same codecs:

Create a file mylist.txt with all the files you want to have concatenated in the following form (lines starting with a # are ignored):

# this is a comment 
file '/path/to/file1' 
file '/path/to/file2' 
file '/path/to/file3'

Note that these can be either relative or absolute paths. Then you can stream copy or re-encode your files:

ffmpeg -f concat -safe 0 -i mylist.txt -c copy output

The -safe 0 above is not required if the paths are relative.

Files with different codecs:

ffmpeg -i "concat:input1.mpg|input2.mpg|input3.mpg" -c copy output.mpg  If you have MP4 files, these could be losslessly

concatenated by first transcoding them to mpeg transport streams. With h.264 video and AAC audio, the following can be used:

ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
  • FGITW... Great answer. :) – anonymous2 Feb 2 '17 at 19:42
  • @anonymous2 Ditto! – goobering Feb 2 '17 at 19:49
  • Is there any way I can play with the audio file using command line code ? I mean recognize highest beat of song or lowest beat. Is it possible to cur the audio file using command line ? I'm doing a hobby project. – batman_rising Feb 3 '17 at 17:27
  • I'm not quite sure what you're looking for but it sounds like it would definitely be a whole new question. – goobering Feb 3 '17 at 17:54
2

The -i flag just defines an infiles. You need to define what you are going to do with those infiles, rather than simply exporting them into your outfile. In view of that, according to ffmpeg documentation, the best method is to start by creating a file with your video in-files in it. Here's an example (just call the file mylist.txt):

#this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

Then you can run the following command:

ffmpeg -f concat -safe 0 -i mylist.txt -c copy output

...where output is your output filename.

Two more things bear mentioning. Firstly, the -safe 0 option is not required if the paths are relative. Secondly, you are not just doing a straight copy in your command mentioned. In other words, your outfile looks like it is supposed to be a different format than your infiles. Therefore, you will have to add on the appropriate flags for the -c option (codec) to come up with the codecs you are looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.