Skip to content

Commit 5bbd3b1

Browse files
committed
A bit cleaner, but doesn't fix my segfault
1 parent b7818c0 commit 5bbd3b1

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

av/container/output.pyx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ cdef class OutputContainer(Container):
7979
)
8080

8181
# Create new stream in the AVFormatContext, set AVCodecContext values.
82-
lib.avformat_new_stream(self.ptr, codec)
83-
cdef lib.AVStream *stream = self.ptr.streams[self.ptr.nb_streams - 1]
82+
cdef lib.AVStream *stream = lib.avformat_new_stream(self.ptr, codec)
8483
cdef lib.AVCodecContext *codec_context = lib.avcodec_alloc_context3(codec)
8584

8685
# Copy from the template.
@@ -160,10 +159,11 @@ cdef class OutputContainer(Container):
160159
# Finalize and open all streams.
161160
cdef Stream stream
162161
for stream in self.streams:
163-
164162
ctx = stream.codec_context
165-
if not ctx.is_open:
163+
if ctx is None:
164+
raise ValueError(f"Stream {stream.index} has no codec context")
166165

166+
if not ctx.is_open:
167167
for k, v in self.options.items():
168168
ctx.options.setdefault(k, v)
169169
ctx.open()
@@ -190,10 +190,7 @@ cdef class OutputContainer(Container):
190190

191191
cdef _Dictionary all_options = Dictionary(self.options, self.container_options)
192192
cdef _Dictionary options = all_options.copy()
193-
self.err_check(lib.avformat_write_header(
194-
self.ptr,
195-
&options.ptr
196-
))
193+
self.err_check(lib.avformat_write_header(self.ptr, &options.ptr))
197194

198195
# Track option usage...
199196
for k in all_options:

0 commit comments

Comments
 (0)