From 1baec572c005b913529a016276695a2d02bb3443 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 4 Dec 2013 22:31:15 +0100 Subject: [PATCH] import transcode scripts from telecaster branch --- tools/scripts/transcode/remux_fix_media.py | 21 ++++++++++++--------- tools/scripts/transcode/transcode.py | 11 ++++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tools/scripts/transcode/remux_fix_media.py b/tools/scripts/transcode/remux_fix_media.py index c5691691..0d505672 100755 --- a/tools/scripts/transcode/remux_fix_media.py +++ b/tools/scripts/transcode/remux_fix_media.py @@ -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' + diff --git a/tools/scripts/transcode/transcode.py b/tools/scripts/transcode/transcode.py index 9d4f38e0..d648ba84 100755 --- a/tools/scripts/transcode/transcode.py +++ b/tools/scripts/transcode/transcode.py @@ -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) -- 2.39.5