From aa907484ece5ff1d6dda6c2604af995c3b7dceb8 Mon Sep 17 00:00:00 2001 From: Martin Sekera Date: Mon, 1 Apr 2019 00:14:31 +0200 Subject: [PATCH] - add --audio aac - don't crash when channel_layout is missing - handle progressbar fault on zero filesize (WIP) --- over-video.py | 19 ++++++++++++++----- version.py | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/over-video.py b/over-video.py index ebecb76..7e2c5d6 100755 --- a/over-video.py +++ b/over-video.py @@ -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 opus<.>, vorbis<.>, pcm<.>, copy<.> or drop<.>.", str, ["opus"], abbr="a", count=1) + main.add_option("audio", "Audio codec to use, either opus<.>, vorbis<.>, aac<.>, pcm<.>, copy<.> or drop<.>.", str, ["opus"], abbr="a", count=1) main.add_option("audio-quality", "Audio encoding quality with -1<.> being the worst and 10<.> being the best. Ignored by --audio<.> opus<.>.", float, [4], abbr="q", count=1) main.add_option("video", "Video codec to use, either av1<.>, vp9<.>, x265<.>, x264<.>, copy<.> or drop<.>.", str, ["vp9"], abbr="v", count=1) main.add_option("video-preset", "Video encoding preset to use by --video<.> x264<.> and x265<.>.", str, ["slow"], abbr="P", count=1) main.add_option("video-quality", "Video encoding quality (CRF). Use 0<.>-51<.> for --video<.> x264<.> and x265<.> (0<.> being lossless, 18<.>-28<.> is reasonable) and 0<.>-63<.> for --video<.> av1<.> or vp9<.> (0<.> being highest, 15<.>-35<.> typical, and 31<.> recommended for HD video).", float, [31], abbr="Q", count=1) - main.add_option("container", "The initial container type. Either mkv<.> or webm<.> (or anything else supported by ffmpeg).", str, ["webm"], count=1) + main.add_option("container", "The initial container type. Either mkv<.> or 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. "scale=1280:trunc(ow/a/2)*2,transpose=dir=1<.>"', str, abbr="F", count=1) main.add_option("ffmpeg-map", "Raw ffmpeg -map<.> options, e.g. --map<.> 0:1<.> --map<.> 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 %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 "??<.>" @@ -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 diff --git a/version.py b/version.py index c381d45..3930969 100644 --- a/version.py +++ b/version.py @@ -4,5 +4,5 @@ major = 1 # VERSION_MAJOR_IDENTIFIER minor = 113 # VERSION_MINOR_IDENTIFIER # VERSION_LAST_MM 1.113 -patch = 0 # VERSION_PATCH_IDENTIFIER +patch = 1 # VERSION_PATCH_IDENTIFIER str = ".".join(str(v) for v in (major, minor, patch))