Compare commits

..

No commits in common. "a7520a05b857e61f561706e426fc7475dd665db6" and "3d18d786b03380f08f644b1945eeefd580c84730" have entirely different histories.

1 changed files with 8 additions and 15 deletions

23
main.py
View File

@ -6,13 +6,10 @@ import os
@click.command() @click.command()
@click.argument('infile') @click.argument('infile')
@click.argument('outdir') @click.argument('outdir')
@click.option('--audio', help="Audio language or stream number") @click.option('--audio-lang')
@click.option('--hardcode', help="Hardcode target sub stream (language or stream number)") @click.option('--hardcode')
@click.option('--overwrite/--no-overwrite', default=True) def main(infile, outdir, hardcode=None, audio_lang='eng'):
def main(infile, outdir, hardcode=None, audio='eng', overwrite=True):
outfile = os.path.join(outdir, os.path.splitext(os.path.split(infile)[1])[0]+'.mp4') outfile = os.path.join(outdir, os.path.splitext(os.path.split(infile)[1])[0]+'.mp4')
if os.path.exists(outfile) and not overwrite:
click.abort(0)
probe = ffmpeg.probe(infile) probe = ffmpeg.probe(infile)
audio_streams, sub_streams = [], [] audio_streams, sub_streams = [], []
@ -22,20 +19,16 @@ def main(infile, outdir, hardcode=None, audio='eng', overwrite=True):
elif stream['codec_type'] == 'subtitle': elif stream['codec_type'] == 'subtitle':
sub_streams.append(stream) sub_streams.append(stream)
if audio.isdigit(): if len(audio_streams) == 1:
audio_index = audio
elif len(audio_streams) == 1:
audio_index = str(audio_streams[0]['index']) audio_index = str(audio_streams[0]['index'])
else: else:
audio_index = next(str(stream['index']) for stream in audio_streams if stream['tags'].get('language') == audio) audio_index = next(str(stream['index']) for stream in audio_streams if stream['tags'].get('language') == audio_lang)
if hardcode: if hardcode:
if hardcode.isdigit(): if len(sub_streams) == 1:
sub_stream = hardcode
elif len(sub_streams) == 1:
sub_stream = sub_streams[0] sub_stream = sub_streams[0]
else: else:
sub_stream = next(stream for stream in sub_streams if stream['tags'].get('language') == hardcode) sub = next(stream['index'] for stream in sub_streams if stream['tags'].get('language') == hardcode)
raw = ffmpeg.input(infile) raw = ffmpeg.input(infile)
if hardcode: if hardcode:
@ -47,7 +40,7 @@ def main(infile, outdir, hardcode=None, audio='eng', overwrite=True):
else: else:
video = raw.video video = raw.video
ffmpeg.output(video, raw[audio_index], outfile, acodec='aac', vcodec='libx264', crf='18', preset='slow').run(overwrite_output=True) ffmpeg.output(video, raw[audio_index], outfile, acodec='aac', vcodec='libx264', crf='18', preset='slow').run()
if __name__ == '__main__': if __name__ == '__main__':
main() main()