Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ffmpeg-vaapi] add b_depth test options for h264 encode #673

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Hangjie22Coder marked this conversation as resolved.
Show resolved Hide resolved
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,
Hangjie22Coder marked this conversation as resolved.
Show resolved Hide resolved
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()