mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 21:45:02 +03:00
use concat demuxer on FFmpeg >= 1.1, fix #324
This commit is contained in:
parent
1c3c586e4d
commit
f8f9b7778b
@ -9,11 +9,11 @@ def get_usable_ffmpeg(cmd):
|
||||
out, err = p.communicate()
|
||||
vers = str(out, 'utf-8').split('\n')[0].split(' ')
|
||||
assert (vers[0] == 'ffmpeg' and vers[2][0] > '0') or (vers[0] == 'avconv')
|
||||
return cmd
|
||||
return cmd, [int(i) for i in vers[2].split('.')]
|
||||
except:
|
||||
return None
|
||||
|
||||
FFMPEG = get_usable_ffmpeg('ffmpeg') or get_usable_ffmpeg('avconv')
|
||||
FFMPEG, FFMPEG_VERSION = get_usable_ffmpeg('ffmpeg') or get_usable_ffmpeg('avconv')
|
||||
|
||||
def has_ffmpeg_installed():
|
||||
return FFMPEG is not None
|
||||
@ -29,6 +29,24 @@ def ffmpeg_convert_ts_to_mkv(files, output = 'output.mkv'):
|
||||
return
|
||||
|
||||
def ffmpeg_concat_mp4_to_mpg(files, output='output.mpg'):
|
||||
# Use concat demuxer on FFmpeg >= 1.1
|
||||
if FFMPEG == 'ffmpeg' and (FFMPEG_VERSION[0] >= 2 or (FFMPEG_VERSION[0] == 1 and FFMPEG_VERSION[1] >= 1)):
|
||||
concat_list = open(output + '.txt', 'w')
|
||||
for file in files:
|
||||
if os.path.isfile(file):
|
||||
concat_list.write("file '%s'\n" % file)
|
||||
concat_list.close()
|
||||
|
||||
params = [FFMPEG, '-f', 'concat', '-i']
|
||||
params.append(output + '.txt')
|
||||
params += ['-c', 'copy', output]
|
||||
|
||||
if subprocess.call(params) == 0:
|
||||
os.remove(output + '.txt')
|
||||
return True
|
||||
else:
|
||||
raise
|
||||
|
||||
for file in files:
|
||||
if os.path.isfile(file):
|
||||
params = [FFMPEG, '-i']
|
||||
@ -47,11 +65,13 @@ def ffmpeg_concat_mp4_to_mpg(files, output = 'output.mpg'):
|
||||
params.append(output)
|
||||
subprocess.call(params)
|
||||
|
||||
if subprocess.call(params) == 0:
|
||||
for file in files:
|
||||
os.remove(file + '.mpg')
|
||||
os.remove(output + '.mpg')
|
||||
|
||||
return
|
||||
return True
|
||||
else:
|
||||
raise
|
||||
|
||||
def ffmpeg_concat_ts_to_mkv(files, output='output.mkv'):
|
||||
params = [FFMPEG, '-isync', '-i']
|
||||
@ -70,6 +90,24 @@ def ffmpeg_concat_ts_to_mkv(files, output = 'output.mkv'):
|
||||
return False
|
||||
|
||||
def ffmpeg_concat_flv_to_mp4(files, output='output.mp4'):
|
||||
# Use concat demuxer on FFmpeg >= 1.1
|
||||
if FFMPEG == 'ffmpeg' and (FFMPEG_VERSION[0] >= 2 or (FFMPEG_VERSION[0] == 1 and FFMPEG_VERSION[1] >= 1)):
|
||||
concat_list = open(output + '.txt', 'w')
|
||||
for file in files:
|
||||
if os.path.isfile(file):
|
||||
concat_list.write("file '%s'\n" % file)
|
||||
concat_list.close()
|
||||
|
||||
params = [FFMPEG, '-f', 'concat', '-i']
|
||||
params.append(output + '.txt')
|
||||
params += ['-c', 'copy', output]
|
||||
|
||||
if subprocess.call(params) == 0:
|
||||
os.remove(output + '.txt')
|
||||
return True
|
||||
else:
|
||||
raise
|
||||
|
||||
for file in files:
|
||||
if os.path.isfile(file):
|
||||
params = [FFMPEG, '-i']
|
||||
@ -98,6 +136,24 @@ def ffmpeg_concat_flv_to_mp4(files, output = 'output.mp4'):
|
||||
raise
|
||||
|
||||
def ffmpeg_concat_mp4_to_mp4(files, output='output.mp4'):
|
||||
# Use concat demuxer on FFmpeg >= 1.1
|
||||
if FFMPEG == 'ffmpeg' and (FFMPEG_VERSION[0] >= 2 or (FFMPEG_VERSION[0] == 1 and FFMPEG_VERSION[1] >= 1)):
|
||||
concat_list = open(output + '.txt', 'w')
|
||||
for file in files:
|
||||
if os.path.isfile(file):
|
||||
concat_list.write("file '%s'\n" % file)
|
||||
concat_list.close()
|
||||
|
||||
params = [FFMPEG, '-f', 'concat', '-i']
|
||||
params.append(output + '.txt')
|
||||
params += ['-c', 'copy', output]
|
||||
|
||||
if subprocess.call(params) == 0:
|
||||
os.remove(output + '.txt')
|
||||
return True
|
||||
else:
|
||||
raise
|
||||
|
||||
for file in files:
|
||||
if os.path.isfile(file):
|
||||
params = [FFMPEG, '-i']
|
||||
|
Loading…
Reference in New Issue
Block a user