Allow setting the rotation sidedata via new FFMPEG APIs#2287
Conversation
Expose two methods on Stream: - set_display_matrix(matrix): write a raw 9-integer AV_PKT_DATA_DISPLAYMATRIX matrix (16.16 fixed point, 2.30 for the third column). - set_display_rotation(degrees, hflip=False, vflip=False): build the matrix with av_display_rotation_set() / av_display_matrix_flip(); the angle is counter-clockwise, matching VideoFrame.rotation on read. The matrix is written as coded side data on the output stream's codecpar inside _finalize_for_output() (after avcodec_parameters_from_context, which would otherwise overwrite it), so muxers record it in the container -- e.g. the MP4/MOV tkhd transformation matrix. Adds the required libav bindings (AVCodecParameters.coded_side_data, AV_PKT_DATA_DISPLAYMATRIX, av_packet_side_data_new, av_display_rotation_set, av_display_matrix_flip), .pyi stubs, a CHANGELOG entry, and tests covering all 8 EXIF orientations across several codecs. Addresses PyAV-Org#1045 and PyAV-Org#1012. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
41b6977 to
508a752
Compare
Collapse the two stream fields into a single packed-bytes field by building the rotation matrix eagerly in set_display_rotation(), and move the field and both setters from Stream to VideoStream so audio/subtitle streams no longer expose them.
|
Thanks for this! I pushed a cleanup commit (
All of |
|
thanks much cleaner, i really appreciate your quick review on this one. As a note, my findings show that only quicktime actually follows this correctly, but hopefully this can help us expose more bugs in the future! |
|
Good to know. |
|
yeah i agree, it tagged itself, i do review the code the code that it writes, i just don't have enough git skills to remove it..... |
|
any chance of a release with this feature? i've been waiting for it for a long time, and with these AI agents, i've had a new willingness to code all the hard things i thought were impossible.... |
|
You can add to |
|
Thanks. |
|
I'll release soon, once I know the new |
It would be great to be able to set this rotation side data