11import warnings
22
3+ from libc.stdint cimport int32_t
34cimport libav as lib
45
6+ from av.enum cimport define_enum
57from av.error cimport err_check
68from av.packet cimport Packet
79from av.utils cimport (
@@ -17,6 +19,12 @@ from av.deprecation import AVDeprecationWarning
1719cdef object _cinit_bypass_sentinel = object ()
1820
1921
22+ # If necessary more can be added from
23+ # https://ffmpeg.org/doxygen/trunk/group__lavc__packet.html#ga9a80bfcacc586b483a973272800edb97
24+ SideData = define_enum(" SideData" , __name__ , (
25+ (" DISPLAYMATRIX" , lib.AV_PKT_DATA_DISPLAYMATRIX, " Display Matrix" ),
26+ ))
27+
2028cdef Stream wrap_stream(Container container, lib.AVStream * c_stream, CodecContext codec_context):
2129 """ Build an av.Stream for an existing AVStream.
2230
@@ -79,6 +87,8 @@ cdef class Stream:
7987 if self .codec_context:
8088 self .codec_context.stream_index = stream.index
8189
90+ self .nb_side_data, self .side_data = self ._get_side_data(stream)
91+
8292 self .metadata = avdict_to_dict(
8393 stream.metadata,
8494 encoding = self .container.metadata_encoding,
@@ -103,6 +113,11 @@ cdef class Stream:
103113 AVDeprecationWarning
104114 )
105115
116+ if name == " side_data" :
117+ return self .side_data
118+ elif name == " nb_side_data" :
119+ return self .nb_side_data
120+
106121 # Convenience getter for codec context properties.
107122 if self .codec_context is not None :
108123 return getattr (self .codec_context, name)
@@ -167,6 +182,20 @@ cdef class Stream:
167182
168183 return self .codec_context.decode(packet)
169184
185+ cdef _get_side_data(self , lib.AVStream * stream):
186+ # Get DISPLAYMATRIX SideDate from a lib.AVStream object.
187+ # Returns: tuple[int, dict[str, Any]]
188+
189+ nb_side_data = stream.nb_side_data
190+ side_data = {}
191+
192+ for i in range (nb_side_data):
193+ # Based on: https://www.ffmpeg.org/doxygen/trunk/dump_8c_source.html#l00430
194+ if stream.side_data[i].type == lib.AV_PKT_DATA_DISPLAYMATRIX:
195+ side_data[" DISPLAYMATRIX" ] = lib.av_display_rotation_get(< const int32_t * > stream.side_data[i].data)
196+
197+ return nb_side_data, side_data
198+
170199 property id :
171200 """
172201 The format-specific ID of this stream.
0 commit comments