Repository navigation
v18.1.1
Fixes
-
Expose
Frame.best_effort_timestamp, FFmpeg's estimate of a frame's presentation time, which falls back to the DTS when the PTS is unreliable (#2477). -
Fix several crashes from reading freed or out-of-range memory:
- Reading a
Streamor itsindex_entriesafter the container is closed now raises instead of reading freed memory. AnIndexEntryis a copy, so it stays readable after the close. - Resuming
demux()ordecode()after the container is closed now raises instead of reading the freed format context. add_stream_from_template()checks that the template's container is still open.- Indexes are range checked before being turned into pointer arithmetic:
MotionVectors[i]accepts negative indexes, andVideoFormatComponent,AudioPlane,BitmapSubtitlePlane, andVideoBlockParamsreject out-of-range ones.VideoBlockParamsalso keeps itsVideoEncParamsalive. - A Python file whose
read(n)returns more thannbytes raisesValueErrorinstead of overflowing FFmpeg's I/O buffer. Packet(bytearray)copies the data, so resizing the bytearray afterwards no longer leaves the packet reading freed memory.- Inserting into a
Dictionarywhile iterating it no longer reads an invalidated entry. HWConfigand the side data wrappers can no longer be left holding a NULL pointer when created through__new__.
- Reading a
-
Fix crashes in filter graphs:
- A
FilterContextorFilterLinkthat outlives itsGraphkeeps the graph alive instead of using freed memory. push()to a buffer source configures the graph first, aspull()does.- Filters added or linked after
Graph.configure()are configured on the next push or pull instead of segfaulting. FilterContext.link_toraisesValueErrorwhen linking filters from different graphs instead of aborting the process.
- A
-
FilterLink.inputandFilterLink.outputnow follow the filters the graph auto-inserts while configuring, instead of the pad they first resolved. -
repr()of a filter pad no longer raisesAttributeError. -
Fix memory corruption when decoding audio with custom channel layouts (e.g.
"FR+FL"), which were shallow-copied and double freed (#2444). -
Fix a deadlock when freeing a frame-threaded decoder while a worker thread logs an error. The codec context is now freed with the GIL released (#2440).
-
Release the GIL around hardware frame transfers.
-
Fix corrupted rows in threaded high bit depth
VideoFrame.reformat()on x86 (#2431). -
VideoFrame.reformat()(and soto_ndarray(format=...),to_rgb(), andto_image()) shares oneSwsContextper thread instead of allocating one per frame, which used megabytes per frame with FFmpeg 8 (#2320). -
Fix reference cycles that kept frames, streams, and filters alive until gc ran: reading
Frame.side_data,MotionVectorsmemoizing its vectors,Stream.index_entries(#2425), and filter pads. -
Frame.side_datanow satisfies theMappingprotocol it advertises: iteration yieldsTypekeys, soitems(),keys(), andvalues()work instead of raisingKeyError. -
Frame.side_dataandPacketSideData.data_typeno longer raise on side data types FFmpeg has added since PyAV last listed them, such as theAV_PKT_DATA_HEVC_CONFan HEVC stream in MP4 or Matroska carries. -
Attaching one object to the
opaqueof more than one frame or packet no longer loses it when the first holder is freed. -
Frames returned by flushing a codec context directly (
CodecContext.decode()with no packet) now carry the stream'stime_baseinstead ofNone. -
A failed
CodecContext.open()no longer clears the selected codec, sois_encoderandis_decoderkeep working and the context can be reopened after fixing the offending parameters. -
A rejected
add_stream()oradd_mux_stream()no longer breaks the container, and a failed stream or output allocation no longer leaks. -
Output containers pass their options to
avio_open2(), so protocol options are used by the protocol. By @ANDYwyLEE. -
InputContainer.sizereturnsNonewhen the size cannot be determined instead of a negative error code. -
Audio encoding passes the codec's
thread_countto its internalAudioResampler, which no longer starts an idle thread per CPU for codecs without threading. By @tonyay163. -
AudioFrame.planesno longer counts one plane too many for 8-channel planar audio, and no longer reads pastextended_datafor more channels. By @ChandraChaan in (#2502). -
AudioFifo.write()raisesValueErrorfor a frame whose channel layout differs from the first frame's, instead of scrambling or over-reading the samples. By @ChandraChaan in (#2505). -
SubtitleCodecContext.decode(None)flushes the decoder instead of raisingRuntimeError, so delayed decoders such as EIA-608 closed captions return their final subtitle. -
AssSubtitle.dialoguestrips override tags such as{\b1}, turns\nand\hinto spaces, treats\{and\}as literal braces, and keeps a{with no closing}instead of dropping the rest of the line. -
HWAccel.createpassesflagson to the context it creates instead of dropping them. -
Packet(str)and settingCodecContext.extradatato astrno longer drop the last bytes of non-ASCII text. -
AVRationalvalues with a zero denominator compare and hash consistently withfloatandDecimalinfinities, and its operators returnNotImplementedfor unsupported operands. -
av.video.frame.supported_np_pix_fmtsnow listsyuv422p. -
BitStreamFilterContextnow passesin_stream's time base to the filter, so filters that read it, such assettswithTBandpcm_rechunk, no longer returnNonetimestamps. By @NotAFlightRisk. -
CodecContext.openreleases the GIL while the codec opens, as do creating a hardware device and its encoder frame pool, so other Python threads keep running while a hardware encoder takes seconds to start (#2517). -
Release the GIL while initializing filters, configuring filter graphs, listing devices, and creating the CUDA device and frame pool used by
VideoFrame.from_dlpack(), so slow setup such as loading awhispermodel or probing capture devices no longer stops other Python threads. -
FilterContext.push(None)on a filter that isn't a buffer source now flushes through its input instead of segfaulting. -
VideoFrame.from_numpy_buffer()raisesValueErrorwhenwidthis wider than the array's rows, instead of reading past the end of the buffer. -
VideoFrame.from_numpy_buffer()with agbrporgbrapformat no longer garbles input whose rows are padded, or reads past the end of its copy. -
Memory borrowed from read-only Python objects is no longer exported as writable: a
Packetmade frombytesorstr, a frame fromVideoFrame.from_numpy_buffer()on a read-only array, and side data now give read-onlymemoryviewobjects and refuseupdate(). -
Writing to a Python file object whose
write()accepts only part of each buffer, such as a socket or pipe, no longer silently drops the rest. -
Closing an input container opened with
io_opennow closes the fileio_openreturned for the main input, instead of leaving it open. -
Container.set_chapters()no longer leaks memory or drops the existing chapters when given an invalid entry. -
AVRational(x)now converts a float,DecimalorFractionexactly instead of truncating it to an integer, andAVRational(num, den)raisesTypeErrorunless both are integers. -
VideoFrame.reformat()no longer changes abt470bgframe's colorspace tosmpte170mwhendst_colorspaceisn't given. -
HWAccelnow raisesValueErrorfor an unknown device type name instead of falling back to the codec's first hardware config. -
frame.side_data.get()andinno longer raiseIndexErrorfor an out-of-range integer key. -
CodecContext.codec_tagno longer raisesUnicodeDecodeErrorfor a tag that isn't ASCII, such as AAC in WAV; it now reads and sets each byte as one Latin-1 character. -
A failed
VideoFrame.reformat()no longer leaves the source frame'scolor_trcandcolor_primarieschanged to unspecified. -
Setting
CodecContext.extradataorSubtitleCodecContext.subtitle_headernow zeroes the padding FFmpeg reads past the data, so an ASS header no longer reads past the end of its buffer. -
VideoFrame.from_numpy_buffer()withyuv420p,yuvj420p, ornv12now gets the right height when it isn't a multiple of 4. -
container.streams.best()raises an error on a closed container instead of segfaulting. -
OutputContainer.add_attachment()now pads its data with the zeroed bytes FFmpeg requires after it.
Full Changelog: v18.1.0...v18.1.1