The task here is to edit together videos using just the command line. There is a surprising amount that can be done with just a few simple commands.
You can take a number of source video files, chop them up to just the scenes you want. Then you can put them all together, and encode the final video into virtually any format.
Cutting the clips
First you need to watch the clip through and note down the exact time stamp of the start and end of the section you want. Do a quick subtraction because what you will actually need is the start point and the duration you want to keep. Make sure that the format you encode to is the same as all the other files, it must also use a container that supports concatenation, eg mpg or avi. Try and keep all the intermediate files at original or high quality so you don’t lose much in the encoding stages.
To cut out one portion of the clip you use:
ffmpeg -i sourcemovie.avi -ss 00:00:10 -t 00:00:20 \ -vcodec copy -acodec copy cutsection1.avi
To explain what each part of this command does,
-i sourcemovie.avi sets the input file to be “sourcemovie.avi”. The start time is set with
-ss 00:00:10 in this example starting at 10 seconds, the duration set by
-t 00:00:20 both using the format hours:minutes:seconds. The backslash breaks the line, it just means that the next line continues the first command and will not be executed separately. The
-vcodec copy -acodec copy forces ffmpeg to use the same codecs as the source movie so there is no re-encoding loss of quality. Finally the output filename is specified, here it is “cutsection1.avi”.
Putting them together
Putting videos together is surprisingly easy. All you need to do is simply concatenate the files. Don’t forget that all these clips need to be in the same format, see above.
They are concatenated with this command.
cat cutsection1.avi cutsection2.avi > fullmovie.avi
where you need to replace the filenames with the names of your files.
Finalising the video
Finally to correct the timestamps, you need to re-run ffmpeg on the file. You can also use this step to compress the final video into the desired format.
The final run through can be done with this simple command.
ffmpeg -i fullmovie.avi finished.avi
This will just run through the whole video fixing time stamps. If you want, you can add specifications of the codecs to compress the final video eg.