diff --git a/src/you_get/processor/ffmpeg.py b/src/you_get/processor/ffmpeg.py index 50172071..0d6c309a 100644 --- a/src/you_get/processor/ffmpeg.py +++ b/src/you_get/processor/ffmpeg.py @@ -3,21 +3,25 @@ import os.path import subprocess -def has_ffmpeg_installed(): +def get_usable_ffmpeg(cmd): try: - p = subprocess.Popen(['ffmpeg', '-version'], stdout=subprocess.PIPE) + p = subprocess.Popen([cmd, '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - import re - assert re.search('Libav', str(out, 'utf-8').split('\n')[0]) is None + vers = str(out, 'utf-8').split('\n')[0].split(' ') + assert (vers[0] == 'ffmpeg' and vers[2][0] > '0') or (vers[0] == 'avconv') + return cmd except: - return False - else: - return True + return None + +FFMPEG = get_usable_ffmpeg('ffmpeg') or get_usable_ffmpeg('avconv') + +def has_ffmpeg_installed(): + return FFMPEG is not None def ffmpeg_convert_ts_to_mkv(files, output = 'output.mkv'): for file in files: if os.path.isfile(file): - params = ['ffmpeg', '-i'] + params = [FFMPEG, '-i'] params.append(file) params.append(output) subprocess.call(params) @@ -27,7 +31,7 @@ def ffmpeg_convert_ts_to_mkv(files, output = 'output.mkv'): def ffmpeg_concat_mp4_to_mpg(files, output = 'output.mpg'): for file in files: if os.path.isfile(file): - params = ['ffmpeg', '-i'] + params = [FFMPEG, '-i'] params.append(file) params.append(file + '.mpg') subprocess.call(params) @@ -37,7 +41,7 @@ def ffmpeg_concat_mp4_to_mpg(files, output = 'output.mpg'): for input in inputs: o.write(input.read()) - params = ['ffmpeg', '-i'] + params = [FFMPEG, '-i'] params.append(output + '.mpg') params += ['-vcodec', 'copy', '-acodec', 'copy'] params.append(output) @@ -50,7 +54,7 @@ def ffmpeg_concat_mp4_to_mpg(files, output = 'output.mpg'): return def ffmpeg_concat_ts_to_mkv(files, output = 'output.mkv'): - params = ['ffmpeg', '-isync', '-i'] + params = [FFMPEG, '-isync', '-i'] params.append('concat:') for file in files: if os.path.isfile(file): @@ -68,20 +72,23 @@ def ffmpeg_concat_ts_to_mkv(files, output = 'output.mkv'): def ffmpeg_concat_flv_to_mp4(files, output = 'output.mp4'): for file in files: if os.path.isfile(file): - params = ['ffmpeg', '-i'] + params = [FFMPEG, '-i'] params.append(file) params += ['-map', '0', '-c', 'copy', '-f', 'mpegts', '-bsf:v', 'h264_mp4toannexb'] params.append(file + '.ts') subprocess.call(params) - params = ['ffmpeg', '-i'] + params = [FFMPEG, '-i'] params.append('concat:') for file in files: f = file + '.ts' if os.path.isfile(f): params[-1] += f + '|' - params += ['-c', 'copy', '-absf', 'aac_adtstoasc', output] + if FFMPEG == 'avconv': + params += ['-c', 'copy', output] + else: + params += ['-c', 'copy', '-absf', 'aac_adtstoasc', output] if subprocess.call(params) == 0: for file in files: