{"id":3008,"date":"2017-06-26T00:00:17","date_gmt":"2017-06-26T07:00:17","guid":{"rendered":"http:\/\/192.168.3.4\/?p=3008"},"modified":"2018-01-09T06:51:50","modified_gmt":"2018-01-09T14:51:50","slug":"ffmpeg-video-splitting-and-splicing","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=3008","title":{"rendered":"FFMpeg Video Splitting and Splicing"},"content":{"rendered":"<p>In the last post I mentioned that I used a 5 second clip from a larger video.\u00a0 More often that not, large videos will contain fluff that will need to be trimmed before they are published.\u00a0 There are several media editor that will do this.\u00a0 I&#8217;ve used OpenShot Video Editor on my system with good results.\u00a0 However, if you had tens if not hundreds of these trim functions to do, using a GUI like OpenShot would be time consuming.\u00a0 Fortunately, FFMpeg can be used in a command line script to achieve the same results.<\/p>\n<p>Here is a simple seek command that splits out a 5 second clip from a much larger hour long video.<\/p>\n<pre>\r\nffmpeg -ss 00:05:35 -i 201207141826.MOV -t 00:00:05 -c copy\u00a020120714172414-19.MOV\r\n<\/pre>\n<p>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.\u00a0 The duration of the cut is set by the -t switch, this example uses 5 seconds.\u00a0 The placement of the -ss switch before the input designation -i determines how the video is processed.\u00a0 In my example above, I have the process begin at my designated time.\u00a0 If it were after, the video stream would play until FFMpeg arrived at the seek time.\u00a0 The trade off is speed versus reliability.\u00a0 Having the seek before means faster processing times.\u00a0 However, if a codec fusses about how how lead frames load, you may end up with artifacts at the beginning of your clipped edit.\u00a0 This can look like still frames until the codec has enough buffer to resume motion, results very.\u00a0 It&#8217;s best to test before you commit.<\/p>\n<p>Joining the clips together is the last step in this post.\u00a0 To do that I&#8217;ll use the following command.<\/p>\n<pre>\r\nffmpeg -f concat -safe 0 -i mylist.txt -c copy 20120714_Splices.MOV\r\n<\/pre>\n<p>The concatenate function is used in FFMpeg.\u00a0 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.\u00a0 Here is the contents of the &#8220;mylist.txt&#8221; file.<\/p>\n<pre>\r\n# Concatenating media files with same codecs - set in order first to last\r\nfile 20120714172414-19.MOV\r\nfile 20120714172618-23.MOV\r\nfile 20120714174725-30.MOV\r\nfile 20120714175619-24..MOV\r\netc....\r\n<\/pre>\n<p>This will create a final video called 20120714_Splices.MOV with all of the earlier splices joined together.\u00a0 If you have sources of varying codecs, resolutions, etc, then reference the FFMpeg site for usage details, here is the link<\/p>\n<p><a href=\"https:\/\/trac.ffmpeg.org\/wiki\/Concatenate\">Concatenating with FFMpeg<\/a><\/p>\n<p>Bulk editing with FFMpeg is a time saver.\u00a0 Some up front work will need to be invested to determine the edit points and writing up the batch script.\u00a0 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.<\/p>\n<p>I hope you have enjoyed this post and I look forward to covering some more basic functions of FFMpeg in future posts.\u00a0 Thank you for joining me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the last post I mentioned that I used a 5 second clip from a larger video.\u00a0 More often that not, large videos will contain fluff that will need to be trimmed before they are published.\u00a0 There are several media editor that will do this.\u00a0 I&#8217;ve used OpenShot Video Editor on my system with good results.\u00a0 However, if you had tens if not hundreds of these trim functions to do, using a GUI like OpenShot would be time consuming.\u00a0 Fortunately,&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=3008\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,3],"tags":[],"class_list":["post-3008","post","type-post","status-publish","format-standard","hentry","category-computer-vision","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3008"}],"version-history":[{"count":7,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3008\/revisions"}],"predecessor-version":[{"id":3010,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/3008\/revisions\/3010"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}