Compare commits
2 Commits
3d18d786b0
...
a7520a05b8
Author | SHA1 | Date |
---|---|---|
Derek | a7520a05b8 | |
Derek | 6cab95e962 |
23
main.py
23
main.py
|
@ -6,10 +6,13 @@ import os
|
|||
@click.command()
|
||||
@click.argument('infile')
|
||||
@click.argument('outdir')
|
||||
@click.option('--audio-lang')
|
||||
@click.option('--hardcode')
|
||||
def main(infile, outdir, hardcode=None, audio_lang='eng'):
|
||||
@click.option('--audio', help="Audio language or stream number")
|
||||
@click.option('--hardcode', help="Hardcode target sub stream (language or stream number)")
|
||||
@click.option('--overwrite/--no-overwrite', default=True)
|
||||
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')
|
||||
if os.path.exists(outfile) and not overwrite:
|
||||
click.abort(0)
|
||||
probe = ffmpeg.probe(infile)
|
||||
|
||||
audio_streams, sub_streams = [], []
|
||||
|
@ -19,16 +22,20 @@ def main(infile, outdir, hardcode=None, audio_lang='eng'):
|
|||
elif stream['codec_type'] == 'subtitle':
|
||||
sub_streams.append(stream)
|
||||
|
||||
if len(audio_streams) == 1:
|
||||
if audio.isdigit():
|
||||
audio_index = audio
|
||||
elif len(audio_streams) == 1:
|
||||
audio_index = str(audio_streams[0]['index'])
|
||||
else:
|
||||
audio_index = next(str(stream['index']) for stream in audio_streams if stream['tags'].get('language') == audio_lang)
|
||||
audio_index = next(str(stream['index']) for stream in audio_streams if stream['tags'].get('language') == audio)
|
||||
|
||||
if hardcode:
|
||||
if len(sub_streams) == 1:
|
||||
if hardcode.isdigit():
|
||||
sub_stream = hardcode
|
||||
elif len(sub_streams) == 1:
|
||||
sub_stream = sub_streams[0]
|
||||
else:
|
||||
sub = next(stream['index'] for stream in sub_streams if stream['tags'].get('language') == hardcode)
|
||||
sub_stream = next(stream for stream in sub_streams if stream['tags'].get('language') == hardcode)
|
||||
|
||||
raw = ffmpeg.input(infile)
|
||||
if hardcode:
|
||||
|
@ -40,7 +47,7 @@ def main(infile, outdir, hardcode=None, audio_lang='eng'):
|
|||
else:
|
||||
video = raw.video
|
||||
|
||||
ffmpeg.output(video, raw[audio_index], outfile, acodec='aac', vcodec='libx264', crf='18', preset='slow').run()
|
||||
ffmpeg.output(video, raw[audio_index], outfile, acodec='aac', vcodec='libx264', crf='18', preset='slow').run(overwrite_output=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue