Skip to content

Commit 8a6a26d

Browse files
committed
apply suggested patch
1 parent 920a36c commit 8a6a26d

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

test/test_encoders.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,10 @@ def _get_video_metadata(self, file_path, fields):
603603
if "=" in line:
604604
key, value = line.split("=", 1)
605605
metadata[key] = value
606+
assert all(field in metadata for field in fields)
606607
return metadata
607608

608-
def _get_frames_info(self, file_path):
609+
def _get_frames_info(self, file_path, fields):
609610
"""Helper function to get frame info (pts, dts, etc.) using ffprobe."""
610611
result = subprocess.run(
611612
[
@@ -615,7 +616,7 @@ def _get_frames_info(self, file_path):
615616
"-select_streams",
616617
"v:0",
617618
"-show_entries",
618-
"frame=pts,pkt_pts,dts,pkt_duration,duration",
619+
f"frame={','.join(fields)}",
619620
"-of",
620621
"json",
621622
str(file_path),
@@ -624,7 +625,9 @@ def _get_frames_info(self, file_path):
624625
check=True,
625626
text=True,
626627
)
627-
return json.loads(result.stdout)["frames"]
628+
frames = json.loads(result.stdout)["frames"]
629+
assert all(field in frame for field in fields for frame in frames)
630+
return frames
628631

629632
@pytest.mark.parametrize("method", ("to_file", "to_tensor", "to_file_like"))
630633
def test_bad_input_parameterized(self, tmp_path, method):
@@ -1047,7 +1050,13 @@ def test_video_encoder_against_ffmpeg_cli(
10471050

10481051
# Check that video metadata is the same
10491052
if method == "to_file":
1050-
fields = ["duration", "duration_ts", "r_frame_rate", "nb_frames"]
1053+
fields = [
1054+
"duration",
1055+
"duration_ts",
1056+
"r_frame_rate",
1057+
"time_base",
1058+
"nb_frames",
1059+
]
10511060
ffmpeg_metadata = self._get_video_metadata(
10521061
ffmpeg_encoded_path,
10531062
fields=fields,
@@ -1059,16 +1068,16 @@ def test_video_encoder_against_ffmpeg_cli(
10591068
assert ffmpeg_metadata == encoder_metadata
10601069

10611070
# Check that frame timestamps and duration are the same
1062-
ffmpeg_frames_info = self._get_frames_info(ffmpeg_encoded_path)
1063-
encoder_frames_info = self._get_frames_info(encoder_output_path)
1064-
1065-
assert len(ffmpeg_frames_info) == len(encoder_frames_info)
1066-
for ffmpeg_frame, encoder_frame in zip(
1067-
ffmpeg_frames_info, encoder_frames_info
1068-
):
1069-
for key in ffmpeg_frame.keys():
1070-
assert key in encoder_frame
1071-
assert ffmpeg_frame[key] == encoder_frame[key]
1071+
fields = ("pts", "pts_time")
1072+
if format != "flv":
1073+
fields += ("duration", "duration_time")
1074+
ffmpeg_frames_info = self._get_frames_info(
1075+
ffmpeg_encoded_path, fields=fields
1076+
)
1077+
encoder_frames_info = self._get_frames_info(
1078+
encoder_output_path, fields=fields
1079+
)
1080+
assert ffmpeg_frames_info == encoder_frames_info
10721081

10731082
def test_to_file_like_custom_file_object(self):
10741083
"""Test to_file_like with a custom file-like object that implements write and seek."""

0 commit comments

Comments
 (0)