]> git.parisson.com Git - telemeta.git/commitdiff
import transcode scripts from telecaster branch
authorGuillaume Pellerin <yomguy@parisson.com>
Wed, 4 Dec 2013 21:31:15 +0000 (22:31 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Wed, 4 Dec 2013 21:31:15 +0000 (22:31 +0100)
tools/scripts/transcode/remux_fix_media.py
tools/scripts/transcode/transcode.py

index c5691691ae0c42e65a28f6698f194eafe3bab2a9..0d5056725436b08650e0c25918352c2bcf3b722d 100755 (executable)
@@ -6,9 +6,9 @@ from ebml.utils.ebml_data import *
 
 class FixCheckMedia(object):
 
-    def __init__(self, dir):
+    def __init__(self, dir, tmp_dir):
         self.dir = dir
-        self.tmp_dir = '/home/telecaster/tmp/'
+        self.tmp_dir = tmp_dir
         if not os.path.exists(self.tmp_dir):
             os.makedirs(self.tmp_dir)
 
@@ -44,14 +44,15 @@ class FixCheckMedia(object):
                                 self.fix_mp3(source, dest)
                                 f = open(root + os.sep + mp3_fixed_log, 'w')
                                 f.close()
-                                os.remove(root + os.sep + mp3_tofix_log)
+                                if os.path.exists(root + os.sep + mp3_tofix_log):
+                                    os.remove(root + os.sep + mp3_tofix_log)
                                 #break
 
 
     def hard_fix_webm(self, path):
         try:
             tmp_file = self.tmp_dir + 'out.webm '
-            command = 'ffmpeg -loglevel 0 -i '+ path + ' -vcodec libvpx -vb 500k -acodec libvorbis -aq 7 -f webm -y ' + tmp_file + ' > /dev/null'
+            command = 'ffmpeg -loglevel 0 -i "'+ path + '" -vcodec libvpx -vb 500k -acodec libvorbis -aq 7 -f webm -y "' + tmp_file + '" > /dev/null'
             print command
             os.system(command)
             command = 'mv '  + tmp_file + path
@@ -63,12 +64,12 @@ class FixCheckMedia(object):
     def fix_webm(self, path):
         try:
             tmp_file = self.tmp_dir + 'out.webm'
-            command = '/usr/local/bin/ffmpeg -loglevel 0 -i ' + path + ' -vcodec copy -acodec copy -f webm -y ' + tmp_file + ' > /dev/null'
+            command = '/usr/local/bin/ffmpeg -loglevel 0 -i "' + path + '" -vcodec copy -acodec copy -f webm -y "' + tmp_file + '" > /dev/null'
             print command
             os.system(command)
             ebml_obj = EBMLData(tmp_file)
             offset = ebml_obj.get_first_cluster_seconds()
-            command = '/usr/local/bin/ffmpeg -loglevel 0 -ss ' + str(offset) + ' -i ' + tmp_file + ' -vcodec copy -acodec copy -f webm -y ' + path + ' > /dev/null'
+            command = '/usr/local/bin/ffmpeg -loglevel 0 -ss ' + str(offset) + ' -i "' + tmp_file + '" -vcodec copy -acodec copy -f webm -y "' + path + '" > /dev/null'
             print command
             os.system(command)
         except:
@@ -76,7 +77,7 @@ class FixCheckMedia(object):
 
     def fix_mp3(self, source, path):
         try:
-            command = '/usr/local/bin/ffmpeg -loglevel 0 -i '+ source + ' -vn -aq 6 -y ' + path + ' > /dev/null'
+            command = '/usr/local/bin/ffmpeg -loglevel 0 -i "'+ source + '" -vn -aq 6 -y "' + path + '" > /dev/null'
             print command
             os.system(command)
         except:
@@ -95,7 +96,8 @@ def get_pids(name, args=None):
                     pids.append(proc.pid)
     return pids
 
-dir = sys.argv[-1]
+dir = sys.argv[-2]
+tmp_dir = sys.argv[-1]
 
 path =  os.path.abspath(__file__)
 pids = get_pids('python2.6',args=path)
@@ -103,8 +105,9 @@ pids = get_pids('python2.6',args=path)
 print datetime.datetime.now()
 if len(pids) <= 1:
     print 'starting process...'
-    f = FixCheckMedia(dir)
+    f = FixCheckMedia(dir, tmp_dir)
     f.process()
     print 'process finished.\n'
 else:
     print 'already started !\n'
+
index 9d4f38e01c741a33f89cac777b1e17c92e590f99..d648ba84b746c4270e0ccba7d7784a1f4e85d48d 100755 (executable)
@@ -20,10 +20,11 @@ source_format = 'webm'
 preview_tc = '00:00:05'
 threads = 4
 
-ffmpeg_args = {'mp3' : '-i %s -vn -acodec libmp3lame -aq 6 -ac 1',
-               'ogg' : '-i %s -vn -acodec copy',
-               'mp4' : '-i %s -vcodec libx264 -r 24 -b 512k -threads ' + str(threads) + ' -acodec libfaac -ar 48000 -ab 96k -ac 1',
-               'png' : '-ss ' + preview_tc + ' -i %s',
+ffmpeg_args = {
+#               'mp3' : '-i "%s" -vn -acodec libmp3lame -aq 6 -ac 1',
+               'ogg' : '-i "%s" -vn -acodec copy',
+               'mp4' : '-i "%s" -vcodec libx264 -r 30 -b 1024k -threads ' + str(threads) + ' -acodec libfaac -ar 48000 -ab 96k -ac 1',
+#               'png' : '-ss ' + preview_tc + ' -i "%s"',
               }
 
 args = sys.argv[1:]
@@ -41,7 +42,7 @@ for root, dirs, files in os.walk(root_dir):
                 dest = os.path.abspath(root + os.sep + local_file)
                 local_files = os.listdir(root)
                 if not local_file in local_files or '--force' in args:
-                    command = 'ffmpeg ' + ffmpeg_args[format] % path + ' -y ' + dest
+                    command = 'ffmpeg -loglevel 0 ' + ffmpeg_args[format] % path + ' -y "' + dest + '"'
                     logger.logger.info(command)
                     if not '--dry-run' in args:
                         os.system(command)