Skip to content

Commit fb4c129

Browse files
committed
fix: Read format and profile from ffprobe for av1 chromium
1 parent ec60fd1 commit fb4c129

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

scripts/gen_av1_chromium.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
2626
from fluster import utils
27-
from fluster.codec import Codec, OutputFormat
27+
from fluster.codec import Codec, OutputFormat, Profile
2828
from fluster.decoders import av1_aom
2929
from fluster.test_suite import TestSuite
3030
from fluster.test_vector import TestVector
@@ -79,20 +79,14 @@
7979
class ChromiumAV1Generator:
8080
"""Generates a test suite from the conformance bitstreams used in tast tests for Chromium"""
8181

82-
def __init__(
83-
self,
84-
name: str,
85-
suite_name: str,
86-
codec: Codec,
87-
description: str,
88-
bpp: int,
89-
):
82+
def __init__(self, name: str, suite_name: str, codec: Codec, description: str, bpp: int, use_ffprobe: bool = False):
9083
self.name = name
9184
self.suite_name = suite_name
9285
self.codec = codec
9386
self.description = description
9487
self.decoder = av1_aom.AV1AOMDecoder()
9588
self.bpp = bpp
89+
self.use_ffprobe = use_ffprobe
9690

9791
def generate(self, download: bool, jobs: int) -> Any:
9892
"""Generates the test suite and saves it to a file"""
@@ -123,7 +117,6 @@ def generate(self, download: bool, jobs: int) -> Any:
123117
name = re.sub(r"_[\d]*", "", test)
124118

125119
test_vector = TestVector(name, file_url, "__skip__", test, OutputFormat.YUV420P, "")
126-
127120
test_suite.test_vectors[name] = test_vector
128121

129122
if download:
@@ -138,14 +131,44 @@ def generate(self, download: bool, jobs: int) -> Any:
138131
for test_vector in test_suite.test_vectors.values():
139132
dest_dir = os.path.join(test_suite.resources_dir, test_suite.name, test_vector.name)
140133
dest_path = os.path.join(dest_dir, os.path.basename(test_vector.source))
141-
test_vector.input_file = dest_path.replace(
142-
os.path.join(test_suite.resources_dir, test_suite.name, test_vector.name) + os.sep,
143-
"",
144-
)
134+
test_vector.input_file = os.path.basename(test_vector.source)
135+
136+
if not os.path.exists(dest_path):
137+
print(f"Warning: Bitstream file not found at {dest_path}")
138+
continue
145139

146-
if not test_vector.input_file:
147-
raise Exception(f"Bitstream file not found in {dest_dir}")
148140
test_vector.source_checksum = utils.file_checksum(dest_path)
141+
142+
if self.use_ffprobe:
143+
ffprobe = utils.normalize_binary_cmd("ffprobe")
144+
command = [
145+
ffprobe,
146+
"-v",
147+
"error",
148+
"-strict",
149+
"-2",
150+
"-select_streams",
151+
"v:0",
152+
"-show_entries",
153+
"stream=profile,pix_fmt",
154+
"-of",
155+
"default=nokey=1:noprint_wrappers=1",
156+
dest_path,
157+
]
158+
159+
result = utils.run_command_with_output(command).splitlines()
160+
if result:
161+
profile = result[0]
162+
pix_fmt = result[1]
163+
try:
164+
test_vector.output_format = OutputFormat[pix_fmt.upper()]
165+
except KeyError as key_err:
166+
raise key_err
167+
try:
168+
test_vector.profile = Profile[profile.translate(str.maketrans(" :", "__")).upper()]
169+
except KeyError as key_err:
170+
raise key_err
171+
149172
out420 = f"{dest_path}.i420"
150173
# Run the libaom av1 decoder to get the checksum as the .md5 in the JSONs are per-frame
151174
test_vector.result = self.decoder.decode(dest_path, out420, test_vector.output_format, 30, False, False)
@@ -178,6 +201,7 @@ def generate(self, download: bool, jobs: int) -> Any:
178201
Codec.AV1,
179202
"AV1 Test Vector Catalogue from https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/tast-tests/src/chromiumos/tast/local/bundles/cros/video/data/test_vectors/av1/",
180203
8,
204+
True,
181205
)
182206
generator.generate(not args.skip_download, args.jobs)
183207

@@ -187,5 +211,6 @@ def generate(self, download: bool, jobs: int) -> Any:
187211
Codec.AV1,
188212
"AV1 Test Vector Catalogue from https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/tast-tests/src/chromiumos/tast/local/bundles/cros/video/data/test_vectors/av1/",
189213
10,
214+
True,
190215
)
191216
generator.generate(not args.skip_download, args.jobs)

0 commit comments

Comments
 (0)