Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions av/codec/context.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ cdef class CodecContext:
# Whether AVCodecContext.extradata should be de-allocated upon destruction.
cdef bint extradata_set

# True when created via add_stream_from_template(); start_encoding() skips
# avcodec_open2() and lets encode()/decode() open the codec lazily if needed.
cdef readonly bint _template_initialized

# Used as a signal that this is within a stream, and also for us to access that
# stream. This is set "manually" by the stream after constructing this object.
cdef int stream_index
Expand Down
13 changes: 8 additions & 5 deletions av/container/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def add_stream_from_template(

# Construct the user-land stream
py_codec_context: CodecContext = wrap_codec_context(ctx, codec, None)
py_codec_context._template_initialized = True
py_stream: Stream = wrap_stream(self, stream, py_codec_context)
self.streams.add_stream(py_stream)

Expand Down Expand Up @@ -368,12 +369,14 @@ def start_encoding(self):
if not ctx.is_open:
for k, v in self.options.items():
ctx.options.setdefault(k, v)
ctx.open()

# Track option consumption.
for k in self.options:
if k not in ctx.options:
used_options.add(k)
if not ctx._template_initialized:
ctx.open()

# Track option consumption.
for k in self.options:
if k not in ctx.options:
used_options.add(k)

stream._finalize_for_output()

Expand Down
Loading