- add --audio aac

- don't crash when channel_layout is missing
- handle progressbar fault on zero filesize (WIP)
This commit is contained in:
Martin Sekera 2019-04-01 00:14:31 +02:00
parent 59d61e5f3e
commit aa907484ec
2 changed files with 15 additions and 6 deletions

View file

@ -25,6 +25,7 @@ command.identify = Command("ffprobe", "-v", "quiet", "-print_format", "json", "-
command.normalize_prepass = Command("ffmpeg", "-i", "INFILE", "MAP", "-filter:a", "loudnorm=i=-23.0:tp=-2.0:lra=7.0:print_format=json", "-f", "null", "/dev/null")
command.encode_generic = Command("ffmpeg", "FPS", "CUT_FROM", "-i", "INFILE", "-threads", str(multiprocessing.cpu_count()), "CUT_TO", "MAP", "VIDEO", "AUDIO", "-sn", "OUTFILE")
command.sub_mp3 = Command("-codec:a", "libmp3lame", "NORMALIZE")
command.sub_aac = Command("-codec:a", "aac", "NORMALIZE")
command.sub_opus = Command("-codec:a", "libopus", "NORMALIZE")
command.sub_vorbis = Command("-codec:a", "libvorbis", "-qscale:a", "QUALITY", "NORMALIZE")
command.sub_pcm = Command("-codec:a", "pcm_s16le", "NORMALIZE")
@ -42,12 +43,12 @@ command.sub_copy_video = Command("-codec:v", "copy")
if __name__ == "__main__":
main = over.app.Main("over-video", version.str, "AO-JSL", features={"config_file": True})
main.add_option("audio", "Audio codec to use, either <M>opus<.>, <M>vorbis<.>, <M>pcm<.>, <M>copy<.> or <M>drop<.>.", str, ["opus"], abbr="a", count=1)
main.add_option("audio", "Audio codec to use, either <M>opus<.>, <M>vorbis<.>, <M>aac<.>, <M>pcm<.>, <M>copy<.> or <M>drop<.>.", str, ["opus"], abbr="a", count=1)
main.add_option("audio-quality", "Audio encoding quality with <M>-1<.> being the worst and <M>10<.> being the best. Ignored by <W>--<g>audio<.> <m>opus<.>.", float, [4], abbr="q", count=1)
main.add_option("video", "Video codec to use, either <M>av1<.>, <M>vp9<.>, <M>x265<.>, <M>x264<.>, <M>copy<.> or <M>drop<.>.", str, ["vp9"], abbr="v", count=1)
main.add_option("video-preset", "Video encoding preset to use by <W>--<g>video<.> <m>x264<.> and <m>x265<.>.", str, ["slow"], abbr="P", count=1)
main.add_option("video-quality", "Video encoding quality (CRF). Use <M>0<.>-<M>51<.> for <W>--<g>video<.> <m>x264<.> and <m>x265<.> (<M>0<.> being lossless, <M>18<.>-<M>28<.> is reasonable) and <M>0<.>-<M>63<.> for <W>--<g>video<.> <m>av1<.> or <m>vp9<.> (<M>0<.> being highest, <M>15<.>-<M>35<.> typical, and <M>31<.> recommended for HD video).", float, [31], abbr="Q", count=1)
main.add_option("container", "The initial container type. Either <M>mkv<.> or <M>webm<.> (or anything else supported by ffmpeg).", str, ["webm"], count=1)
main.add_option("container", "The initial container type. Either <M>mkv<.> or <M>webm<.> (or anything else supported by ffmpeg).", str, ["mkv"], count=1)
main.add_option("normalize", "Normalize the audio track without clipping. May use dynamic range compression.", bool, [True], abbr="n")
main.add_option("ffmpeg-vfilter", 'Raw ffmpeg -filter:v options, e.g. "<M>scale=1280:trunc(ow/a/2)*2,transpose=dir=1<.>"', str, abbr="F", count=1)
main.add_option("ffmpeg-map", "Raw ffmpeg <c>-map<.> options, e.g. <W>--<g>map<.> <M>0:1<.> <W>--<g>map<.> <M>0:2<.>. This is a drop-in fix until we get proper stream selection.", str, abbr="M", overwrite=False, count=1)
@ -113,7 +114,7 @@ if __name__ == "__main__":
if main.cfg.move_source:
main.print("move source files to <W>%s<.>/" %(main.cfg.move_source))
if main.cfg.audio not in ("drop", "copy", "pcm", "vorbis", "opus", "mp3"):
if main.cfg.audio not in ("drop", "copy", "pcm", "vorbis", "opus", "aac", "mp3"):
raise ValueError("unknown audio codec: %s" %(main.cfg.audio))
if main.cfg.video not in ("drop", "copy", "x264", "x265", "vp9", "av1"):
@ -195,7 +196,7 @@ if __name__ == "__main__":
audio = audio_streams[0]
info.audio_codec = audio["codec_name"]
info.audio_channels = audio["channels"]
info.audio_channel_layout = audio["channel_layout"]
info.audio_channel_layout = audio["channel_layout"] if "channel_layout" in audio else "don't care"
info.audio_samplerate = over.text.Unit(audio["sample_rate"], "Hz")
info.audio_language = audio["tags"]["language"] if "tags" in audio and "language" in audio["tags"] else "und"
info.audio_bitrate = over.text.Unit(audio["bit_rate"], "b/s") if "bit_rate" in audio else "<R>??<.>"
@ -327,6 +328,11 @@ if __name__ == "__main__":
command.sub_vorbis.NORMALIZE = info.normalize_command
encode_cmd.AUDIO = command.sub_vorbis
elif main.cfg.audio == "aac":
command.sub_aac.reset()
command.sub_aac.NORMALIZE = info.normalize_command
encode_cmd.AUDIO = command.sub_aac
elif main.cfg.audio == "opus":
command.sub_opus.reset()
command.sub_opus.NORMALIZE = info.normalize_command
@ -433,7 +439,10 @@ if __name__ == "__main__":
if out:
if b"time=" in out:
t = aux.parse_time(out)
pb.set("a", int(t))
try:
pb.set("a", int(t))
except ZeroDivisionError:
print(out)
elif out is None:
break