Skip to content

Commit

Permalink
[ffmpeg-vaapi] add b_depth test options for h264 encode
Browse files Browse the repository at this point in the history
Signed-off-by: Wang Hangjie <[email protected]>
  • Loading branch information
Hangjie22Coder committed Sep 2, 2024
1 parent a726fb1 commit 2d2da41
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/ffmpeg/encoderbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions lib/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,56 @@ def gen_avc_cqp_parameters(spec, profiles, strapi=False):
params = gen_avc_cqp_variants(spec, profiles, strapi)
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, strapi=False):
for case, params in spec.items():
if strapi:
Expand Down
42 changes: 42 additions & 0 deletions test/ffmpeg-vaapi/encode/avc.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,45 @@ 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,
minrate = bitrate,
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,
minrate = bitrate,
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()

0 comments on commit 2d2da41

Please sign in to comment.