{"id":61,"date":"2020-12-28T19:19:06","date_gmt":"2020-12-28T18:19:06","guid":{"rendered":"http:\/\/192.168.178.38\/?p=61"},"modified":"2020-12-28T19:19:06","modified_gmt":"2020-12-28T18:19:06","slug":"automatische-konvertierung-von-film-dateien-mittels-ffmpeg","status":"publish","type":"post","link":"https:\/\/lpl-mind.de\/en\/automatische-konvertierung-von-film-dateien-mittels-ffmpeg\/","title":{"rendered":"Automatische Konvertierung von Film Dateien mittels FFmpeg"},"content":{"rendered":"<h4>AutoMovieConverter<\/h4>\n<p> Dieses Script soll mittels FFmpeg Movie Dateien in x265 und .mkv transkodieren und konvertieren. Es kann ein Parameter angegeben werden um den angegebenen Ordner rekursive zu durchlaufen. Falls eine Movie Datei gefunden wird, wird mittels ffmpeg -i gepr\u00fcft ob ein konvertieren notwendig ist. Falls eine Konvertierung notwendig ist, wird eine <filename>-converted.mkv erzeugt. Wenn die Filml\u00e4nge der Original Datei mit der Konvertieren Datei \u00fcbereinstimmt, wird die Original Datei ersetzt. <\/p>\n<h5>Installation:<\/h5>\n<p> Python und FFmpeg m\u00fcssen vorher installiert werden.<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;width:700px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"c codecolorer\">&nbsp;apt<span class=\"sy0\">-<\/span>get install python apt<span class=\"sy0\">-<\/span>get install ffmpeg<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<h5>Installing<\/h45>\nKopiere das Git repository.<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;width:700px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"c codecolorer\">&nbsp;git clone https<span class=\"sy0\">:<\/span><span class=\"co1\">\/\/github.com\/lukaspupkalipinski\/AutoMovieConverter<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>F\u00fchre die folgenden Kommandos aus wenn, Sie dieses Script auf Ihrem System installieren wollen. Das Script wird bei jedem Systemstart ausgef\u00fchrt. Es wird die Arbeit vor dem System Neustart fortfahren.<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;width:700px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"c codecolorer\">&nbsp;cd AutoMovieConverter mv AutoMovieConverter.<span class=\"me1\">py<\/span> <span class=\"sy0\">\/<\/span>usr<span class=\"sy0\">\/<\/span>share<span class=\"sy0\">\/<\/span>automovieconverter<span class=\"sy0\">\/<\/span>automovieconverter.<span class=\"me1\">py<\/span> mv automovieconverter <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>init.<span class=\"me1\">d<\/span><span class=\"sy0\">\/<\/span>automovieconverter update<span class=\"sy0\">-<\/span>rc.<span class=\"me1\">d<\/span> automovieconverter defaults update<span class=\"sy0\">-<\/span>rc.<span class=\"me1\">d<\/span> automovieconverter enable<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Bitte stellen Sie sicher das der pfad \/etc\/init.d\/automovieconverter ge\u00e4ndert wurde.<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;width:700px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"c codecolorer\">&nbsp;DAEMON_ARGS<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;\/usr\/share\/automovieconverter\/automovieconverter.py &lt;your-folder-path&gt; R&quot;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<h5>Get started<\/h5>\n<div class=\"codecolorer-container  default\" style=\"overflow:auto;white-space:nowrap;width:700px;\"><br \/><strong>GeSHi Error:<\/strong> GeSHi could not find the language  (using path \/var\/www\/html\/wp-content\/plugins\/codecolorer\/lib\/geshi\/) (code 2)<br \/><\/div>\n<h5>Ausf\u00fchrung:<\/h5>\n<p> Zum starten des Scrips ist es nur n\u00f6tig den Ordnner anzugeben.<br \/>\nPython und FFmpeg m\u00fcssen vorher installiert werden.<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;width:700px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\" codecolorer\">python automovieconverter.<span class=\"me1\">py<\/span> <span class=\"sy0\">\/<\/span>media<span class=\"sy0\">\/<\/span>hdd<span class=\"sy0\">\/<\/span>movies<span class=\"sy0\">\/<\/span> R<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Der Quellcode ist jederzeit auf Github verf\u00fcgbar.<br \/>\nhttps:\/\/github.com\/lukaspupkalipinski\/AutoMovieConverter<br \/>\nautomovieconverter.py<\/p>\n<div class=\"codecolorer-container python default\" style=\"overflow:auto;white-space:nowrap;width:700px;height:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/><\/div><\/td><td><div class=\"python codecolorer\"><span class=\"co1\">#!\/usr\/bin\/env python &quot;&quot;&quot;Convert all Movie files to a specific format.<\/span><br \/>\nConvert <span class=\"kw2\">all<\/span> Movie files to a specific format. <span class=\"st0\">&quot;&quot;&quot; import argparse from os import walk import os import re import subprocess<br \/>\n__author__ = &quot;Lukas Pupka-Lipinski&quot; __copyright__ = &quot;Copyright 2018, AutoMovieConverter&quot; __credits__ = [&quot;&quot;] __license__ = &quot;GPL&quot; __version__ = &quot;1.0.3&quot; __maintainer__ = &quot;Lukas Pupka-Lipinski&quot; __email__ = &quot;support@lpl-mind.de&quot; __status__ = &quot;Dev&quot;<br \/>\n&nbsp;FFmpegx264command=&quot;ffmpeg -i <span class=\"es0\">\\&quot;<\/span>%s<span class=\"es0\">\\&quot;<\/span> -c:v libx264 -preset slow -crf 22 -c:a copy <span class=\"es0\">\\&quot;<\/span>%s<span class=\"es0\">\\&quot;<\/span>-converted.mkv&quot; FFMpegcheckcommand=&quot;ffmpeg -i <span class=\"es0\">\\&quot;<\/span>%s<span class=\"es0\">\\&quot;<\/span> 2&gt;&amp;1 | grep <span class=\"es0\">\\&quot;<\/span>Duration<span class=\"es0\">\\&quot;<\/span>&quot; FFMpegcheck2command=&quot;ffmpeg -i <span class=\"es0\">\\&quot;<\/span>%s<span class=\"es0\">\\&quot;<\/span> 2&gt;&amp;1 | grep <span class=\"es0\">\\&quot;<\/span>ENCODER<span class=\"es0\">\\&quot;<\/span>&quot; Removecommand=&quot;rm -f <span class=\"es0\">\\&quot;<\/span>%s<span class=\"es0\">\\&quot;<\/span>&quot; Movecommand=&quot;mv <span class=\"es0\">\\&quot;<\/span>%s<span class=\"es0\">\\&quot;<\/span> <span class=\"es0\">\\&quot;<\/span>%s<span class=\"es0\">\\&quot;<\/span>&quot;<br \/>\nfilter=r&quot;.*<span class=\"es0\">\\\\<\/span>.(avi|mkv|flv|flv|avi|MTS|M2TS|mov|wmv|mp4|m4v|mpg|mp2|mpeg|mpe|mpv|mpg|mpeg|m2v|m4v|flv|f4v)&quot;<br \/>\ndef validation(origin, converted): &nbsp; &nbsp; &quot;&quot;&quot;<\/span> &nbsp; &nbsp; Checks <span class=\"kw1\">if<\/span> to media files has the some hour <span class=\"kw1\">and<\/span> minute duration. <span class=\"me1\">seconds<\/span> are <span class=\"kw1\">not<\/span> checked &nbsp; &nbsp; :param origin: the first media <span class=\"kw2\">file<\/span> &nbsp; &nbsp; :param converted: the second media <span class=\"kw2\">file<\/span> &nbsp; &nbsp; :<span class=\"kw1\">return<\/span>: <span class=\"kw1\">if<\/span> files has the same duration &nbsp; &nbsp; <span class=\"st0\">&quot;&quot;&quot; &nbsp; &nbsp; process = subprocess.Popen(FFMpegcheckcommand%origin, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shell=True, stdout=subprocess.PIPE) &nbsp; &nbsp; process.wait() &nbsp; &nbsp; orignoutput = process.communicate()<br \/>\n&nbsp; &nbsp; process = subprocess.Popen(FFMpegcheckcommand % converted, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shell=True, stdout=subprocess.PIPE) &nbsp; &nbsp; process.wait() &nbsp; &nbsp; convertedoutput = process.communicate()<br \/>\n&nbsp; &nbsp; searchtime = r&quot;Duration:<span class=\"es0\">\\\\<\/span>s([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{2}),<span class=\"es0\">\\\\<\/span>sstart&quot;<br \/>\n&nbsp; &nbsp; if (len(orignoutput)==0): &nbsp; &nbsp; &nbsp; &nbsp; return False &nbsp; &nbsp; if (len(convertedoutput)==0): &nbsp; &nbsp; &nbsp; &nbsp; return False<br \/>\n&nbsp; &nbsp; orignoutput=orignoutput[0] &nbsp; &nbsp; convertedoutput=convertedoutput[0]<br \/>\n&nbsp; &nbsp; if (orignoutput==None): &nbsp; &nbsp; &nbsp; &nbsp; return False &nbsp; &nbsp; if (convertedoutput==None): &nbsp; &nbsp; &nbsp; &nbsp; return False<br \/>\n&nbsp; &nbsp; re1 = re.findall(searchtime, orignoutput) &nbsp; &nbsp; re2 = re.findall(searchtime, convertedoutput)<br \/>\n&nbsp; &nbsp; if (not re1 or not re2): &nbsp; &nbsp; &nbsp; &nbsp; return False<br \/>\n&nbsp; &nbsp; if (len(re1)==0 and len(re2)==0): &nbsp; &nbsp; &nbsp; &nbsp; return False<br \/>\n&nbsp; &nbsp; if (len(re1[0])!=4 and len(re2[0])!=4): &nbsp; &nbsp; &nbsp; &nbsp; return False<br \/>\n&nbsp; &nbsp; if (re1[0][0]==re2[0][0] and re1[0][1]==re2[0][1]): &nbsp; &nbsp; &nbsp; &nbsp; return True &nbsp; &nbsp; else: &nbsp; &nbsp; &nbsp; &nbsp; return False<br \/>\ndef checkifneedconvert(file): &nbsp; &nbsp; process = subprocess.Popen(FFMpegcheck2command % file, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shell=True, stdout=subprocess.PIPE) &nbsp; &nbsp; process.wait() &nbsp; &nbsp; output = process.communicate()<br \/>\n&nbsp; &nbsp; if (len(output)&gt;=1): &nbsp; &nbsp; &nbsp; &nbsp; if (&quot;libx264&quot; in output[0]): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return False &nbsp; &nbsp; return True<br \/>\ndef removefile(file): &nbsp; &nbsp; process = subprocess.Popen( &nbsp; &nbsp; &nbsp; &nbsp; Removecommand % (file), shell=True, &nbsp; &nbsp; &nbsp; &nbsp; stdout=subprocess.PIPE) &nbsp; &nbsp; process.wait()<br \/>\ndef renamefile(file,target): &nbsp; &nbsp; process = subprocess.Popen( &nbsp; &nbsp; &nbsp; &nbsp; Movecommand % (file, target), shell=True, &nbsp; &nbsp; &nbsp; &nbsp; stdout=subprocess.PIPE) &nbsp; &nbsp; process.wait()<br \/>\ndef convertfile(file,target): &nbsp; &nbsp; process = subprocess.Popen(FFmpegx264command % (file,target), shell=True, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stdout=subprocess.PIPE) &nbsp; &nbsp; process.wait()<br \/>\nparser = argparse.ArgumentParser(description=<span class=\"es0\">\\'<\/span>Convert all Movie files to a specific format.<span class=\"es0\">\\'<\/span>) parser.add_argument(<span class=\"es0\">\\'<\/span>infile<span class=\"es0\">\\'<\/span>, metavar=<span class=\"es0\">\\'<\/span>inputfile<span class=\"es0\">\\'<\/span>, nargs=1, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;help=<span class=\"es0\">\\'<\/span>input folder<span class=\"es0\">\\'<\/span>) parser.add_argument(<span class=\"es0\">\\'<\/span>R<span class=\"es0\">\\'<\/span>,nargs=<span class=\"es0\">\\'<\/span>?<span class=\"es0\">\\'<\/span>,help=<span class=\"es0\">\\'<\/span>recursive search<span class=\"es0\">\\'<\/span>,default=&quot;R&quot;) parser.add_argument(<span class=\"es0\">\\'<\/span>remove<span class=\"es0\">\\'<\/span>,nargs=<span class=\"es0\">\\'<\/span>?<span class=\"es0\">\\'<\/span>,help=<span class=\"es0\">\\'<\/span>recursive search<span class=\"es0\">\\'<\/span>,default=&quot;&quot;) parser.add_argument(<span class=\"es0\">\\'<\/span>-f<span class=\"es0\">\\'<\/span>,metavar=<span class=\"es0\">\\'<\/span>filter<span class=\"es0\">\\'<\/span>,nargs=&quot;?&quot;,help=<span class=\"es0\">\\'<\/span>file filter expression<span class=\"es0\">\\'<\/span>,default=filter) args = parser.parse_args()<br \/>\n&nbsp;path=vars(args)[<span class=\"es0\">\\'<\/span>infile<span class=\"es0\">\\'<\/span>][0] if (vars(args)[<span class=\"es0\">\\'<\/span>R<span class=\"es0\">\\'<\/span>]!=None): &nbsp; &nbsp; recursive=True else: &nbsp; &nbsp; recursive=False<br \/>\nif (vars(args)[<span class=\"es0\">\\'<\/span>remove<span class=\"es0\">\\'<\/span>]!=None): &nbsp; &nbsp; remove=True else: &nbsp; &nbsp; remove=False filter=vars(args)[<span class=\"es0\">\\'<\/span>f<span class=\"es0\">\\'<\/span>]<br \/>\n&nbsp;f = [] for (dirpath, dirnames, filenames) in walk(path): &nbsp; &nbsp; for filename in filenames:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; match=re.match(filter,filename) &nbsp; &nbsp; &nbsp; &nbsp; if match and checkifneedconvert(dirpath+os.sep+filename): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; justname = filename.split(&quot;.&quot;)[:-1][0] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; orign=dirpath+os.sep+filename &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; convered=dirpath+os.sep+justname+&quot;-converted.mkv&quot;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #remove if convered file exists but is corrupted &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (os.path.isfile(convered)): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not validation(orign,convered)): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removefile(convered)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not os.path.isfile(convered)): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; convertfile(orign, dirpath + os.sep + justname)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #remove file and rename if file is valid &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (remove and validation(orign,convered)): &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removefile(orign) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; renamefile(convered, dirpath + os.sep + justname + &quot;.mkv&quot;)<br \/>\n&nbsp; &nbsp; if(not recursive): &nbsp; &nbsp; &nbsp; &nbsp; break<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<p>AutoMovieConverter Dieses Script soll mittels FFmpeg Movie Dateien in x265 und .mkv transkodieren und konvertieren. Es kann ein Parameter angegeben werden um den angegebenen Ordner rekursive zu durchlaufen. Falls eine Movie Datei gefunden wird, wird mittels ffmpeg -i gepr\u00fcft ob ein konvertieren notwendig ist. Falls eine Konvertierung notwendig ist, wird [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-61","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/posts\/61"}],"collection":[{"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":6,"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/posts\/61\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lpl-mind.de\/en\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}