Merged
Conversation
mollyxu
commented
Jan 20, 2026
mollyxu
commented
Jan 21, 2026
Dan-Flores
reviewed
Jan 21, 2026
Dan-Flores
reviewed
Jan 21, 2026
Dan-Flores
reviewed
Jan 21, 2026
Dan-Flores
reviewed
Jan 21, 2026
Dan-Flores
reviewed
Jan 21, 2026
Dan-Flores
reviewed
Jan 21, 2026
Dan-Flores
reviewed
Jan 21, 2026
Dan-Flores
reviewed
Jan 21, 2026
NicolasHug
reviewed
Jan 22, 2026
Dan-Flores
reviewed
Jan 27, 2026
Dan-Flores
approved these changes
Jan 27, 2026
Contributor
Dan-Flores
left a comment
There was a problem hiding this comment.
Thanks for working on this! I left one small comment, but overall LGTM!
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1173
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 2fb9f32 with merge base 06d4538 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
NicolasHug
reviewed
Jan 28, 2026
NicolasHug
reviewed
Jan 29, 2026
mollyxu
commented
Feb 2, 2026
mollyxu
commented
Feb 4, 2026
NicolasHug
reviewed
Feb 4, 2026
NicolasHug
approved these changes
Feb 4, 2026
Contributor
NicolasHug
left a comment
There was a problem hiding this comment.
Thank you @mollyxu ! Left a bunch of comments but I'll approve now to unblock.
added 3 commits
February 4, 2026 12:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add rotation metadata support
Context: #1084
Videos recorded on mobile devices often store rotation metadata indicating how the video should be displayed. TorchCodec now extracts this metadata and applies the rotation during decoding so frames are returned in the correct orientation.
This PR adds support for extracting and applying rotation metadata from video streams. The rotation angle (in degrees counter clockwise) is extracted from the display matrix side data and:
VideoStreamMetadata.rotationWhen there are user transforms, the rotation is applied before the transforms as a part of filtergraph. In the future, we should benchmark this against alternatives and see if there should be optimizations.
The
rotationpropertyNone: The video has no rotation metadata (most videos)float: The rotation angle in degrees (counter-clockwise rounded to the nearest 90 degrees) needed for correct display. Common values are 0, 90, 180, -90, or -180.Implementation
Metadata extraction (
FFMPEGCommon.cpp):getRotationFromStream()which extracts the rotation fromAV_PKT_DATA_DISPLAYMATRIXside dataav_packet_side_data_get()withcodecpar->coded_side_dataav_stream_get_side_data()with deprecation warning suppression for FFmpeg 6av_stream_get_side_data()withint*size parameterav_display_rotation_get()to compute the angle from the display matrixMetadata propagation:
StreamMetadatastruct now includes anstd::optional<double> rotationfield (Metadata.h)SingleStreamDecoderpopulates this during stream scanningVideoStreamMetadatadataclass exposesrotation: float | None(_metadata.py)custom_ops.cpp)Test coverage
nasa_13013_rotated.mp4test resource with 90° rotation metadatatest_rotation_metadata(intest_metadata.py): Verifies rotation is correctly extracted for rotated videos and isNonefor non-rotated videostest_rotation_applied_to_frames(intest_decoders.py): Performs pixel-exact comparison with ffmpeg CLI outputtest_rotation_with_transform(intest_decoders.py): Verifies that user-specified transforms (Resize, CenterCrop, RandomCrop) work correctly with rotated videos, ensuring output dimensions match the requested (H, W) regardless of rotation metadatatest_rotation_with_transform_pipeline(intest_decoders.py): Verifies that chained transforms work correctly with rotated videos, with each transform operating in post-rotation coordinate space