FFMpeg Video Splitting and Splicing

FFMpeg Video Splitting and Splicing

In the last post I mentioned that I used a 5 second clip from a larger video.  More often that not, large videos will contain fluff that will need to be trimmed before they are published.  There are several media editor that will do this.  I’ve used OpenShot Video Editor on my system with good results.  However, if you had tens if not hundreds of these trim functions to do, using a GUI like OpenShot would be time consuming.  Fortunately, FFMpeg can be used in a command line script to achieve the same results.

Here is a simple seek command that splits out a 5 second clip from a much larger hour long video.

ffmpeg -ss 00:05:35 -i 201207141826.MOV -t 00:00:05 -c copy 20120714172414-19.MOV

This instructs FFMpeg to seek 5 minutes and 35 seconds into the video and set the beginning point of the cut with the -ss switch.  The duration of the cut is set by the -t switch, this example uses 5 seconds.  The placement of the -ss switch before the input designation -i determines how the video is processed.  In my example above, I have the process begin at my designated time.  If it were after, the video stream would play until FFMpeg arrived at the seek time.  The trade off is speed versus reliability.  Having the seek before means faster processing times.  However, if a codec fusses about how how lead frames load, you may end up with artifacts at the beginning of your clipped edit.  This can look like still frames until the codec has enough buffer to resume motion, results very.  It’s best to test before you commit.

Joining the clips together is the last step in this post.  To do that I’ll use the following command.

ffmpeg -f concat -safe 0 -i mylist.txt -c copy 20120714_Splices.MOV

The concatenate function is used in FFMpeg.  Since all my source videos use the same codec, I reference a text file that contains a list of all my clips that I want to piece together.  Here is the contents of the “mylist.txt” file.

# Concatenating media files with same codecs - set in order first to last
file 20120714172414-19.MOV
file 20120714172618-23.MOV
file 20120714174725-30.MOV
file 20120714175619-24..MOV

This will create a final video called 20120714_Splices.MOV with all of the earlier splices joined together.  If you have sources of varying codecs, resolutions, etc, then reference the FFMpeg site for usage details, here is the link

Concatenating with FFMpeg

Bulk editing with FFMpeg is a time saver.  Some up front work will need to be invested to determine the edit points and writing up the batch script.  Once all of that is out of the way, you can run it or schedule it, then go on living your life while the computer does the work.

I hope you have enjoyed this post and I look forward to covering some more basic functions of FFMpeg in future posts.  Thank you for joining me.

Comments are closed.