Features
- Infer the specific stream and codec context types for all FFmpeg encoder names in type-checked code by @WyattBlue.
- Add
CodecContext.supported_optionsto discover generic and codec-specific options by @WyattBlue (#2032). - Add
Packet.rescale_ts()to rescale packet PTS, DTS, and duration to a newAVRationaltime base by @WyattBlue. - Support reusing the thread's current CUDA context via a
current_ctxflag onCudaContextandVideoFrame.from_dlpack, for interop with libraries like PyTorch that initialize CUDA first by @Yozer (#2339). VideoFrame.from_dlpackno longer requires restatingprimary_ctx/current_ctxwhen passing an explicitcuda_context; the flags are only validated when explicitly given by @WyattBlue.- Support passing an explicit CUDA stream to FFmpeg CUDA operations, including NVENC input and output, via a
cuda_streamparameter onCudaContext; currently limited to logical CUDA device 0 by @Yozer (#2360). - Add
av.AVRational, an exact rational number stored as two int32s that mirrors FFmpeg'sAVRational.Codec.frame_ratesnow holds these rather thanfractions.Fraction, and every setter that accepts aFractionalso accepts anAVRational. Unset rational attributes are falsy, so test them withif not stream.time_base:rather thanis Noneby @WyattBlue. - Add
Frame.metadata, the metadata FFmpeg attaches to a frame, by @WyattBlue. - Add
CodecContext.levelby @WyattBlue. - Add
VideoCodecContext.field_orderby @WyattBlue. VideoFrame.savenow forwards keyword arguments to the encoder, letting callers trade file size for speed (e.g.pred="none"orcompression_level=1for PNG,qscale=2for JPG) by @WyattBlue.- Add
InputContainer.start_time_realtime, the stream's start time in microseconds since the Unix epoch, which RTSP derives from RTCP sender reports, by @WyattBlue (#2365).
Fixes
- Fix
VideoFrame.saveraisingAttributeErrorwhen given aPathrather than astrby @WyattBlue. - Fix a frame rate assigned to a
VideoStreamafteradd_streambeing dropped from the output; the codec context's frame rate is now copied to the stream before the header is written by @WyattBlue (#2301). - Prevent crashes and corrupted output when structural codec properties are changed after an output stream has been opened by @WyattBlue, reported by @oakaigh (#2232).
- Fix a crash when using a stream that has no
CodecContext(a demuxed stream with no available decoder, such as one from a truncated file, or a stream created byadd_mux_stream); decoding now raisesDecoderNotFoundError, encoding now raisesEncoderNotFoundError, andBitStreamFilterContextaccepts such a stream asout_streamby @WyattBlue, reported by @justinrmiller (#2344).
Misc
- Support building from source against FFmpeg 9.0 by @WyattBlue. The binary wheels still ship FFmpeg 8.1.2.
New Contributors
Full Changelog: v18.0.0...v18.1.0