add ffmpeg_concat_mp4_to_mp4

This commit is contained in:
Mort Yao 2013-04-28 22:22:07 +02:00
parent f8ac919be1
commit bc759b0a27
2 changed files with 30 additions and 2 deletions

View File

@ -444,8 +444,8 @@ def download_urls(urls, title, ext, total_size, output_dir = '.', refer = None,
except:
from .processor.ffmpeg import has_ffmpeg_installed
if has_ffmpeg_installed():
from .processor.ffmpeg import ffmpeg_concat_mp4_to_mpg
ffmpeg_concat_mp4_to_mpg(parts, os.path.join(output_dir, title + '.mp4'))
from .processor.ffmpeg import ffmpeg_concat_mp4_to_mp4
ffmpeg_concat_mp4_to_mp4(parts, os.path.join(output_dir, title + '.mp4'))
for part in parts:
os.remove(part)
else:

View File

@ -96,3 +96,31 @@ def ffmpeg_concat_flv_to_mp4(files, output = 'output.mp4'):
return True
else:
raise
def ffmpeg_concat_mp4_to_mp4(files, output = 'output.mp4'):
for file in files:
if os.path.isfile(file):
params = [FFMPEG, '-i']
params.append(file)
params += ['-c', 'copy', '-f', 'mpegts', '-bsf:v', 'h264_mp4toannexb']
params.append(file + '.ts')
subprocess.call(params)
params = [FFMPEG, '-i']
params.append('concat:')
for file in files:
f = file + '.ts'
if os.path.isfile(f):
params[-1] += f + '|'
if FFMPEG == 'avconv':
params += ['-c', 'copy', output]
else:
params += ['-c', 'copy', '-absf', 'aac_adtstoasc', output]
if subprocess.call(params) == 0:
for file in files:
os.remove(file + '.ts')
return True
else:
raise