I'm trying to make a single ffmpeg command that will take multiple inputs, seek specific times within them, then output to a single file.

For example, I have inputA.avi and inputB.avi and each is 1 hour long. I want a single output file that takes inputA.avi from 00:00:00 to 00:20:00 for the beginning and inputB.avi from 00:00:00 to 00:10:00 for the end. The end result should be a 30 minute video file that has the first 20 minutes of inputA then the first 10 minutes of inputB.

I currently can do the following three commands to get the job done:

ffmpeg -ss 00:00:00 -t 00:20:00 -i inputA.avi [rest of command] inputA-trim.avi
ffmpeg -ss 00:00:00 -t 00:10:00 -i inputB.avi [rest of command] inputB-trim.avi
ffmpeg -f concat -i inputList.txt [rest of command] final.mp4

where inputList.txt contains only

file inputA-trim.avi
file inputB-trim.avi

This works, but has unnecessary steps and creates intermediary files. I also have to create a batch file and txt file to get everything to run in succession. I'd like to be able to create a single ffmpeg command that can take multiple inputs with individual -ss and -t commands, then put them in a single output.


#1 Using concat filter i.e. without textfile

ffmpeg -ss 0 -t 20:00 -i inputA.avi -ss 0 -t 10:00 -i inputB.avi -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1" out.mp4


#2 Using concat demuxer i.e. with textfile

file inputA-trim.avi
inpoint 0
outpoint 20:00
file inputB-trim.avi
inpoint 0
outpoint 10:00

and then your final command

ffmpeg -f concat -i inputList.txt [rest of command] final.mp4

See https://trac.ffmpeg.org/wiki/Concatenate for details.

  • I have tested the second option listed, with the input txt file. I had to add -safe 0 to avoid an "unsafe filename" error. The final command I used was ffmpeg -f concat -safe 0 -i inputList.txt -vf "scale=1280:720,setsar=1" -crf 30 -an -movflags +faststart final.mp4. I'll test the first option some other time. Thanks. – user24601 Oct 27 '18 at 23:05
  • I guess I had to use -safe 0 because I had absolute full paths in my input txt file. – user24601 Oct 27 '18 at 23:17
  • I've been using the first option for some time now. Just noticed I mentioned I would test it, but never reported back. – user24601 Jul 29 '19 at 21:38
  • Does the concat filter re-encode? – Hashim Aziz Apr 11 at 22:07
  • The concat filter will require a re-encode. All frame filters will lead to a re-encode. – Gyan Apr 12 at 4:05

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.