Skip to content

Commit 0fbedb2

Browse files
committed
Make OutputContainer.metadata lazy
1 parent d1ca67e commit 0fbedb2

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

av/container/core.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ cdef class Container:
3434
cdef HWAccel hwaccel
3535

3636
cdef readonly StreamContainer streams
37-
cdef readonly dict metadata
37+
cdef dict _metadata
3838

3939
# Private API.
4040
cdef uint8_t _myflag # enum: writeable, input_was_opened, started, done, extradata_planned

av/container/core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,14 @@ def flags(self, value: cython.int):
414414
def input_was_opened(self):
415415
return self._myflag & 2
416416

417+
@property
418+
def metadata(self) -> dict:
419+
# Lazily created so output containers that never touch metadata don't
420+
# allocate a dict. Input containers populate ``_metadata`` eagerly.
421+
if self._metadata is None:
422+
self._metadata = {}
423+
return self._metadata
424+
417425
def chapters(self):
418426
self._assert_open()
419427
result: list = []

av/container/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __cinit__(self, *args, **kwargs):
101101
"Hardware accelerated decode requested but no stream is compatible"
102102
)
103103

104-
self.metadata = avdict_to_dict(
104+
self._metadata = avdict_to_dict(
105105
self.ptr.metadata, self.metadata_encoding, self.metadata_errors
106106
)
107107

av/container/output.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def close_output(self: OutputContainer):
6767
class OutputContainer(Container):
6868
def __cinit__(self, *args, **kwargs):
6969
self.streams = StreamContainer()
70-
self.metadata = {}
7170
self._extradata_bsfs = {}
7271
self._buffered_packets = []
7372
with cython.nogil:

0 commit comments

Comments
 (0)