-
Notifications
You must be signed in to change notification settings - Fork 70
Improve VideoEncoder test against FFmpeg CLI #1058
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
Improve VideoEncoder test against FFmpeg CLI #1058
Conversation
| # There may be additional subtle differences in the encoder. | ||
| percentage = 94 if ffmpeg_version == 6 or format == "avi" else 99 | ||
| # MPEG codec used for avi format does not accept CRF | ||
| percentage = 94 if format == "avi" else 99 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had difficulty returning identical frames for avi with the default codec, mpeg4. We could consider choosing a specific codec for this test to enforce quality, but I think its ok to keep the relaxed exactness check in this case.
NicolasHug
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Dan-Flores
test/test_encoders.py
Outdated
| fields=fields, | ||
| ) | ||
| for key in ffmpeg_metadata: | ||
| assert ffmpeg_metadata[key] == encoder_metadata[key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be able to just assert ffmpeg_metadata == encoder_metadata ?
test/test_encoders.py
Outdated
| # Write tensor to file to check with ffprobe | ||
| with open(encoder_output_path, "wb") as f: | ||
| f.write(encoded_output.numpy().tobytes()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's OK to only validate to_file against ffprobe, that's what we do for the audio encoder and it makes this test a tiny bit easier to follow. No strong opinion. If you remove it from here, make sure to remove it from to_file_like as well.
torchcodec/test/test_encoders.py
Lines 353 to 354 in 22bcf4d
| if method == "to_file": | |
| validate_frames_properties(actual=encoded_by_us, expected=encoded_by_ffmpeg) |
This PR resolves the first two bullet points in #1057:
test_video_encoder_against_ffmpeg_cliover the other encoding methods (to_file_like,to_tensor)self._get_video_metadatain this test to ensure the expected metadata is the same