From 51e854f1d3950951461476eb007097e3de484ce9 Mon Sep 17 00:00:00 2001 From: Wang Hangjie Date: Mon, 29 Jul 2024 21:57:30 -0700 Subject: [PATCH] [ffmpeg-vaapi] add b_depth test options for h264 encode Signed-off-by: Wang Hangjie --- lib/ffmpeg/encoderbase.py | 3 +- lib/parameters.py | 50 +++++++++++++++++++++++++++++++++ test/ffmpeg-vaapi/encode/avc.py | 40 ++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/lib/ffmpeg/encoderbase.py b/lib/ffmpeg/encoderbase.py index 9c58ecd8..1b6013e0 100755 --- a/lib/ffmpeg/encoderbase.py +++ b/lib/ffmpeg/encoderbase.py @@ -65,6 +65,7 @@ def hwformat(self): roi = property(lambda s: s.ifprop("roi", ",addroi=0:0:{width}/2:{height}/2:-1/3")) strict = property(lambda s: s.ifprop("strict", " -strict {strict}")) seek = property(lambda s: s.ifprop("seek", " -ss {seek}")) + bdepth = property(lambda s: s.ifprop("bdepth", " -b_depth {bdepth}")) hwupload = property(lambda s: ",hwupload") @property @@ -109,7 +110,7 @@ def encparams(self): f"{self.bframes}{self.slices}{self.minrate}{self.maxrate}{self.refs}" f"{self.extbrc}{self.loopshp}{self.looplvl}{self.tilecols}{self.tilerows}" f"{self.level}{self.ladepth}{self.forced_idr}{self.intref}{self.lowpower}" - f"{self.maxframesize}{self.pict}{self.rqp}{self.strict}{self.seek}" + f"{self.maxframesize}{self.pict}{self.rqp}{self.strict}{self.seek}{self.bdepth}" ) @property diff --git a/lib/parameters.py b/lib/parameters.py index d390c3e9..722388a9 100755 --- a/lib/parameters.py +++ b/lib/parameters.py @@ -58,6 +58,56 @@ def gen_avc_cqp_parameters(spec, profiles): params = gen_avc_cqp_variants(spec, profiles) return keys, params +def gen_avc_bdepth_variants(spec, profiles): + for case, params in spec.items(): + for variant in copy.deepcopy(params.get("variants", dict()).get("bdepth", [])): + uprofile = variant.get("profile", None) + cprofiles = [uprofile] if uprofile else profiles + gop = variant.get("gop", None) + bframes = variant.get("bframes", None) + bitrate = variant.get("bitrate", None) + qp = variant.get("qp", None) + rcmode = variant["rcmode"] + if "cbr" == rcmode: + variant.update(maxrate = bitrate) + elif "vbr" == rcmode: + variant.update(maxrate = bitrate * 2) + for profile in cprofiles: + yield [ + case, gop, bframes, bitrate, qp, variant["maxrate"], + profile, rcmode, variant.get("bdepth", 1) + ] + +def gen_avc_bdepth_parameters(spec, profiles): + keys = ("case", "gop", "bframes", "bitrate", "qp", "maxrate", "profile", "rcmode", "bdepth") + params = gen_avc_bdepth_variants(spec, profiles) + return keys, params + +def gen_avc_bdepth_lp_variants(spec, profiles): + for case, params in spec.items(): + for variant in copy.deepcopy(params.get("variants", dict()).get("bdepth_lp", [])): + uprofile = variant.get("profile", None) + cprofiles = [uprofile] if uprofile else profiles + gop = variant.get("gop", None) + bframes = variant.get("bframes", None) + bitrate = variant.get("bitrate", None) + qp = variant.get("qp", None) + rcmode = variant["rcmode"] + if "cbr" == rcmode: + variant.update(maxrate = bitrate) + elif "vbr" == rcmode: + variant.update(maxrate = bitrate * 2) + for profile in cprofiles: + yield [ + case, gop, bframes, bitrate, qp, variant["maxrate"], + profile, rcmode, variant.get("bdepth", 1) + ] + +def gen_avc_bdepth_lp_parameters(spec, profiles): + keys = ("case", "gop", "bframes", "bitrate", "qp", "maxrate", "profile", "rcmode", "bdepth") + params = gen_avc_bdepth_lp_variants(spec, profiles) + return keys, params + def gen_avc_cbr_variants(spec, profiles): for case, params in spec.items(): for variant in copy.deepcopy(params.get("variants", dict()).get("cbr", [])): diff --git a/test/ffmpeg-vaapi/encode/avc.py b/test/ffmpeg-vaapi/encode/avc.py index d3c42149..970acc0c 100755 --- a/test/ffmpeg-vaapi/encode/avc.py +++ b/test/ffmpeg-vaapi/encode/avc.py @@ -212,3 +212,43 @@ def init(self, tspec, case, gop, bframes, bitrate, maxrate, profile, rcmode): def test(self, case, gop, bframes, bitrate, maxrate, profile, rcmode): self.init(spec, case, gop, bframes, bitrate, maxrate, profile, rcmode) self.encode() + +class bdepth(AVCEncoderTest): + def init(self, tspec, case, gop, bframes, bitrate, qp, maxrate, profile, rcmode, bdepth): + vars(self).update(tspec[case].copy()) + vars(self).update( + rcmode = rcmode, + bframes = bframes, + bitrate = bitrate, + qp = qp, + case = case, + maxrate = maxrate, + gop = gop, + profile = profile, + bdepth = bdepth, + ) + + @slash.parametrize(*gen_avc_bdepth_parameters(spec, ['high', 'main'])) + def test(self, case, gop, bframes, bitrate, qp, maxrate, profile, rcmode, bdepth): + self.init(spec, case, gop, bframes, bitrate, qp, maxrate, profile, rcmode, bdepth) + self.encode() + +class bdepth_lp(AVCEncoderLPTest): + def init(self, tspec, case, gop, bframes, bitrate, qp, maxrate, profile, rcmode, bdepth): + vars(self).update(tspec[case].copy()) + vars(self).update( + rcmode = rcmode, + bframes = bframes, + bitrate = bitrate, + qp = qp, + case = case, + maxrate = maxrate, + gop = gop, + profile = profile, + bdepth = bdepth, + ) + + @slash.parametrize(*gen_avc_bdepth_lp_parameters(spec, ['high', 'main'])) + def test(self, case, gop, bframes, bitrate, qp, maxrate, profile, rcmode, bdepth): + self.init(spec, case, gop, bframes, bitrate, qp, maxrate, profile, rcmode, bdepth) + self.encode()