{"id":14994,"date":"2015-03-10T12:17:45","date_gmt":"2015-03-10T17:17:45","guid":{"rendered":"http:\/\/bucktownbell.com\/?p=14994"},"modified":"2015-03-10T12:17:45","modified_gmt":"2015-03-10T17:17:45","slug":"concatenate-mp4-files-using-ffmpeg","status":"publish","type":"post","link":"http:\/\/bucktownbell.com\/?p=14994","title":{"rendered":"Concatenate MP4 files using FFMPEG"},"content":{"rendered":"<blockquote><p>There are two methods within ffmpeg that can be used to concatenate files of the same type: <a class=\"wiki\" href=\"https:\/\/trac.ffmpeg.org\/wiki\/Concatenate#demuxer\">the concat &#8221;demuxer&#8221;<\/a> and <a class=\"wiki\" href=\"https:\/\/trac.ffmpeg.org\/wiki\/Concatenate#protocol\">the concat &#8221;protocol&#8221;<\/a>. The demuxer is more flexible &#8211; it requires the same codecs, but different container formats can be used; and it can be used with any container formats, while the protocol only works with a select few containers. However, the concat protocol is available in older versions of ffmpeg, where the demuxer isn&#8217;t.<\/p><\/blockquote>\n<p>via <a href=\"https:\/\/trac.ffmpeg.org\/wiki\/Concatenate\">Concatenate \u2013 FFmpeg<\/a>.<\/p>\n<p>I needed a way to concatenate mp4 files generated from all the IP cameras connected to the open wifi.\u00a0 I tried compiling <a href=\"http:\/\/www.mp4joiner.org\/en\/\">MP4Joiner<\/a> but there were way too many dodgy dependencies throwing code errors in the compile.\u00a0 Then I read that simple ffmpeg, a package easily loaded onto a Linux box, can merge mp4 files and it works.\u00a0 Unfortunately concat only works on later Fedora releases like Fedora 19 and above but it&#8217;s easier than manually merging them in Avidemux.\u00a0 My main server still runs Fedora 14 for many reasons so merging them simply requires running a command manually in a Fedora 19 or above Virtual Machine.\u00a0 In the future when I migrate to a later release this can all be scripted seamlessly.<\/p>\n<p>Here&#8217;s more as to how it&#8217;s done in ffmpeg&#8230;<\/p>\n<blockquote><p>Create a file <tt>mylist.txt<\/tt> with all the files you want to have concatenated in the following form (lines starting with a <tt>#<\/tt> are ignored):<\/p>\n<pre class=\"wiki\"># this is a comment\r\nfile '\/path\/to\/file1'\r\nfile '\/path\/to\/file2'\r\nfile '\/path\/to\/file3'\r\n<\/pre>\n<p>Note that these can be either relative or absolute paths. Then you can <a href=\"https:\/\/ffmpeg.org\/ffmpeg.html#Stream-copy\">stream copy<\/a> or re-encode your files:<\/p>\n<pre class=\"wiki\">ffmpeg -f concat -i mylist.txt -c copy output\r\n<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>There are two methods within ffmpeg that can be used to concatenate files of the same type: the concat &#8221;demuxer&#8221; and the concat &#8221;protocol&#8221;. The demuxer is more flexible &#8211; it requires the same codecs, but different container formats can &hellip; <a href=\"http:\/\/bucktownbell.com\/?p=14994\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1078],"tags":[852,234,408],"class_list":["post-14994","post","type-post","status-publish","format-standard","hentry","category-applications","tag-ffmpeg","tag-media-server","tag-video"],"_links":{"self":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/14994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14994"}],"version-history":[{"count":1,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/14994\/revisions"}],"predecessor-version":[{"id":14995,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=\/wp\/v2\/posts\/14994\/revisions\/14995"}],"wp:attachment":[{"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14994"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bucktownbell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}