Fix/dg 18 rotation metadata for videos is not applied serverside #1911
+113
−5
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.
What does this PR do?
Resolves DG-18
Videos recorded on mobile devices in portrait mode were displaying incorrectly. The video dimensions showed as landscape (1920×1080) even though the video should appear as portrait (1080×1920). This happened because aiortc's MediaPlayer and PyAV don't automatically apply rotation metadata stored in the video's displaymatrix.
Solution
Detect rotation metadata using ffprobe (PyAV doesn't reliably expose displaymatrix side_data)
Apply rotation correction usin cv2.rotate() (which is fast for 90 deg rotations)
Type of Change
Testing
I tested it with the same video provided by the user in DG-18.
Checklist
Additional Context
Note
Corrects orientation of videos by reading rotation metadata and rotating frames during processing.
get_video_rotation,get_cv2_rotation_code, androtate_video_frameinwebrtc_worker/utils.py(usesffmpeg-pythonand OpenCV)VideoFrameProcessor.set_track(track, rotation_code=None)and applies rotation in_process_frame_asyncrotation_codetoMediaPlayer/OnDemandVideoTracksetup inwebrtc.pyrequirements/_requirements.txtto includeffmpeg-pythonWritten by Cursor Bugbot for commit d2e8607. This will update automatically on new commits. Configure here.