Compare commits

..

6 commits
v2.0 ... master

Author SHA1 Message Date
Martin Sekera
681e76361d add --subtitle 2023-05-29 11:21:33 +02:00
Martin Sekera
e1beb8312d Fix normalization crash on files with complex subtitle sets. Also increases normalization speed by 20-30 %. 2021-09-04 00:51:38 +02:00
Martin Sekera
aff7ec290d H265: increase default QP a bit 2021-08-29 17:57:46 +02:00
Martin Sekera
1b5ab6416b Increase normalization speed, fix normalization scope when --cut is set. 2021-08-29 15:26:47 +02:00
Martin Sekera
fbf90f2c89 add hardware HEVC encoder support, add matching profiles 2021-08-28 18:40:08 +02:00
Martin Sekera
f9b19ebdc4 fix bitrate not detected on some videos 2021-08-27 12:19:12 +02:00
2 changed files with 46 additions and 9 deletions

View file

@ -53,7 +53,7 @@ class CodecPar:
else: else:
return [] return []
if not self.is_valid(value): if self.is_valid and not self.is_valid(value):
raise ValueError("%s is not a valid %s" %(value, self.name)) raise ValueError("%s is not a valid %s" %(value, self.name))
return [self.prefix, value] return [self.prefix, value]
@ -257,6 +257,22 @@ x265_tunes = [
"ssim" "ssim"
] ]
codec_h265 = Codec(
"h265",
"HEVC encoded using a hardware encoder via VAAPI. Very good quality and faster-than-realtime times.",
["-vaapi_device", "/dev/dri/renderD128", "-filter:v", "format=nv12,hwupload", "-profile:v", "main", "-codec:v", "hevc_vaapi", "-rc_mode", "CQP"],
[
CodecPar(
"QP",
"-qp",
True,
None,
StrIntInRange(0, 52),
"Quality factor: 0 is lossless, 22-27 generally very good, 52 worst."
)
]
)
codec_x265 = Codec( codec_x265 = Codec(
"x265", "x265",
"HEVC encoded using x265. Very good quality and decent encode times.", "HEVC encoded using x265. Very good quality and decent encode times.",
@ -443,6 +459,7 @@ codec_sdrop = Codec(
) )
video_codec_router = CodecRouter("M") video_codec_router = CodecRouter("M")
video_codec_router.add_codec(codec_h265)
video_codec_router.add_codec(codec_x265) video_codec_router.add_codec(codec_x265)
video_codec_router.add_codec(codec_x264) video_codec_router.add_codec(codec_x264)
video_codec_router.add_codec(codec_rav1e) video_codec_router.add_codec(codec_rav1e)
@ -467,7 +484,7 @@ subtitle_codec_router.add_codec(codec_sdrop)
# see doc/command_assembler.png # see doc/command_assembler.png
command = over.types.ndict() command = over.types.ndict()
command.identify = Command("ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", "INFILE") command.identify = Command("ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", "INFILE")
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.normalize_prepass = Command("ffmpeg", "CUT_FROM", "-i", "INFILE", "-threads", str(multiprocessing.cpu_count()), "CUT_TO", "MAP", "-filter:a", "loudnorm=i=-23.0:tp=-2.0:lra=7.0:print_format=json", "-vn", "-sn", "-f", "null", "/dev/null")
command.encode_generic = Command("ffmpeg", "FPS", "CUT_FROM", "-i", "INFILE", "-threads", str(multiprocessing.cpu_count()), "CUT_TO", "MAP", "VIDEO", "AUDIO", "SUBTITLE", "OUTFILE") command.encode_generic = Command("ffmpeg", "FPS", "CUT_FROM", "-i", "INFILE", "-threads", str(multiprocessing.cpu_count()), "CUT_TO", "MAP", "VIDEO", "AUDIO", "SUBTITLE", "OUTFILE")
command.sub_vfilter = Command("-filter:v", "ARGS") command.sub_vfilter = Command("-filter:v", "ARGS")
command.sub_afilter = Command("-filter:a", "ARGS", "-ar", "48k") command.sub_afilter = Command("-filter:a", "ARGS", "-ar", "48k")
@ -530,9 +547,12 @@ def get_preset(presets, preset):
factory_presets = " ".join([ factory_presets = " ".join([
"@share:video=x264:23,slow;audio=opus;container=mp4;ffmpeg-vfilter=scale=1280:trunc(ow/a/2)*2", "@share:video=x264:23,slow;audio=opus;container=mp4;ffmpeg-vfilter=scale=1280:trunc(ow/a/2)*2",
"@share-portrait:video=x264:23,slow;audio=opus;container=mp4;ffmpeg-vfilter=scale=720:trunc(ow/a/2)*2", "@share-portrait:video=x264:23,slow;audio=opus;container=mp4;ffmpeg-vfilter=scale=720:trunc(ow/a/2)*2",
"@archive-hq:video=x265:23,slow;audio=opus;container=mkv", "@archive-sw-22:video=x265:22,slow;audio=opus;container=mkv",
"@archive:video=x265:25,medium;audio=opus;container=mkv", "@archive-sw-24:video=x265:24,slow;audio=opus;container=mkv",
"@archive-animation:video=x265:27,slow;audio=opus;container=mkv" "@archive-sw-27:video=x265:27,slow;audio=opus;container=mkv",
"@archive-animation:video=x265:27,slow,animation;audio=opus;container=mkv",
"@archive-26:video=h265:26;audio=opus;container=mkv",
"@archive-28:video=h265:28;audio=opus;container=mkv"
]) ])
# -------------------------------------------------- # --------------------------------------------------
@ -598,6 +618,7 @@ if __name__ == "__main__":
files = over.types.ndict() files = over.types.ndict()
audio_words = [] audio_words = []
video_words = [] video_words = []
subtitle_words = []
files.container = "mkv" files.container = "mkv"
if not main.cfg.audio: if not main.cfg.audio:
@ -625,6 +646,14 @@ if __name__ == "__main__":
if main.cfg.ffmpeg_vfilter: if main.cfg.ffmpeg_vfilter:
video_words.append("<g>vfilter<.>=<M>%s<.>" %(main.cfg.ffmpeg_vfilter)) video_words.append("<g>vfilter<.>=<M>%s<.>" %(main.cfg.ffmpeg_vfilter))
if not main.cfg.subtitle:
main.log.fail("<W>--<G>subtitle<.> is not set")
main.exit(1)
elif main.cfg.subtitle in ("copy", "drop"):
subtitle_words.append("<c>%s<.>" %(main.cfg.subtitle))
else:
subtitle_words.append("<g>codec<.>=<M>%s<.>" %(main.cfg.subtitle))
if main.cfg.video == "drop": if main.cfg.video == "drop":
if main.cfg.audio.startswith("pcm"): if main.cfg.audio.startswith("pcm"):
files.container = "wav" files.container = "wav"
@ -667,10 +696,14 @@ if __name__ == "__main__":
else: else:
main.log.info("settings", end=":\n") main.log.info("settings", end=":\n")
main.log.info("audio: %s", ", ".join(audio_words))
main.log.info("video: %s", ", ".join(video_words)) main.log.info("video: %s", ", ".join(video_words))
main.log.info("audio: %s", ", ".join(audio_words))
main.log.info("subtitle: %s", ", ".join(subtitle_words))
main.log.info("container: <M>%s<.>", files.container) main.log.info("container: <M>%s<.>", files.container)
if main.cfg.cut:
main.log.warn("cut: start at <M>%s<.>, take <M>%s<.>", main.cfg.cut[0], main.cfg.cut[1])
if main.cfg.move: if main.cfg.move:
main.log.info("move source files to <W>%s<.>/", main.cfg.move) main.log.info("move source files to <W>%s<.>/", main.cfg.move)
@ -750,6 +783,8 @@ if __name__ == "__main__":
info.video_bitrate = over.text.Unit(video["bit_rate"], "b/s") info.video_bitrate = over.text.Unit(video["bit_rate"], "b/s")
elif "tags" in video and "BPS" in video["tags"]: elif "tags" in video and "BPS" in video["tags"]:
info.video_bitrate = over.text.Unit(int(video["tags"]["BPS"]), "b/s") info.video_bitrate = over.text.Unit(int(video["tags"]["BPS"]), "b/s")
elif "tags" in video and "BPS-eng" in video["tags"]:
info.video_bitrate = over.text.Unit(int(video["tags"]["BPS-eng"]), "b/s")
else: else:
info.video_bitrate = "<R>??<.>" info.video_bitrate = "<R>??<.>"
info.pixel_fmt = video["pix_fmt"] info.pixel_fmt = video["pix_fmt"]
@ -808,6 +843,8 @@ if __name__ == "__main__":
command.normalize_prepass.reset() command.normalize_prepass.reset()
command.normalize_prepass.INFILE = "file:" + str(files.infile) command.normalize_prepass.INFILE = "file:" + str(files.infile)
command.normalize_prepass.CUT_FROM = ["-ss", main.cfg.cut[0]] if main.cfg.cut else None
command.normalize_prepass.CUT_TO = ["-to", main.cfg.cut[1]] if main.cfg.cut else None
command.normalize_prepass.MAP = info.map_command command.normalize_prepass.MAP = info.map_command
command.normalize_prepass.run(stderr=True) command.normalize_prepass.run(stderr=True)

View file

@ -2,7 +2,7 @@
# encoding: utf-8 # encoding: utf-8
major = 2 # VERSION_MAJOR_IDENTIFIER major = 2 # VERSION_MAJOR_IDENTIFIER
minor = 0 # VERSION_MINOR_IDENTIFIER minor = 2 # VERSION_MINOR_IDENTIFIER
# VERSION_LAST_MM 2.0 # VERSION_LAST_MM 2.2
patch = 0 # VERSION_PATCH_IDENTIFIER patch = 2 # VERSION_PATCH_IDENTIFIER
str = ".".join(str(v) for v in (major, minor, patch)) str = ".".join(str(v) for v in (major, minor, patch))