{"id":2108,"date":"2019-06-05T12:39:22","date_gmt":"2019-06-05T10:39:22","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=2108"},"modified":"2019-06-05T12:39:22","modified_gmt":"2019-06-05T10:39:22","slug":"join-all-mp4-with-python-and-ffmpeg","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/join-all-mp4-with-python-and-ffmpeg\/","title":{"rendered":"Join all Mp4 with Python and Ffmpeg"},"content":{"rendered":"<p>With the following code you can join all the mp4 in a directory, withou caring of have to input anythong like name of the files or select or other things that takes time. No program needed, just ffmpeg (go to the site and install it, it&#8217;s free).<\/p>\n<pre class=\"lang:default decode:true \">def concatenate():\r\n\tstringa = \"ffmpeg -i \\\"concat:\"\r\n\telenco_video = glob.glob(\"*.mp4\")\r\n\telenco_file_temp = []\r\n\tfor f in elenco_video:\r\n\t\tfile = \"temp\" + str(elenco_video.index(f) + 1) + \".ts\"\r\n\t\tos.system(\"ffmpeg -i \" + f + \" -c copy -bsf:v h264_mp4toannexb -f mpegts \" + file)\r\n\t\telenco_file_temp.append(file)\r\n\tprint(elenco_file_temp)\r\n\tfor f in elenco_file_temp:\r\n\t\tstringa += f\r\n\t\tif elenco_file_temp.index(f) != len(elenco_file_temp)-1:\r\n\t\t\tstringa += \"|\"\r\n\t\telse:\r\n\t\t\tstringa += \"\\\" -c copy  -bsf:a aac_adtstoasc output.mp4\"\r\n\tprint(stringa)\r\n\tos.system(stringa)\r\n \r\nconcatenate()<\/pre>\n<p>&nbsp;<\/p>\n<p><iframe loading=\"lazy\" title=\"How to join many mp4 with python and ffmpeg\" width=\"747\" height=\"420\" src=\"https:\/\/www.youtube.com\/embed\/ch14IFfPtDI?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h2>A little script to trim the video<\/h2>\n<p>You can make this a little more useful (or you can just run the code in the cmd). Later I will make something a little more complex out of this ffmpeg command.<\/p>\n<pre class=\"lang:default decode:true \">import os\r\n\r\nos.system(\"ffmpeg -i joinmp4.mp4 -ss 00:00:03 -to 00:10:50 -c:v copy -c:a copy joinmp4_b.mp4\")<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"Join mp4 video with ffmpeg and Python\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/join-all-mp4-with-python-and-ffmpeg\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":2109,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[50],"tags":[197,413,412,86,4],"class_list":["post-2108","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-video","tag-ffmpeg","tag-join-mp4","tag-join-video","tag-mp4","tag-python"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":false,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=2108"}],"version-history":[{"count":1,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2108\/revisions"}],"predecessor-version":[{"id":2110,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2108\/revisions\/2110"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/2109"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=2108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=2108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=2108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}