Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ffmpeg: deprecated AVStream::codec and avcodec_close
In the old method, ffmpeg automatically creates an AVCodecContext for every AVStream. The context can be opened and closed again any number of times. This is deprecated and the application code is now responsible for creating and freeing an AVCodecContext when needed. The AVCodecContext that the application creates may not be opened and closed more than once. The deprecated function avcodec_close must not be called on an AVCodecContext that you create, instead you have to free the AVCodecContext (using avcodec_free_context) and allocate a new one if you want to read the stream again. In many cases, reference fields in AVStream::codec are now available in AVStream::codecpar. Where possible the code now uses those fields, to avoid having to create an AVCodecContext. "codec" no longer shows in the online documentation for AVStream. It is only defined in ffmpeg if you define FF_API_LAVF_AVCTX when compiling ffmpeg. See external/FFmpeg/libavformat/version.h, which has a list of defines that will be set in future to disable this and others. For more information google FF_API_LAVF_AVCTX. Instead of AVStream::codec, the AVStream::codecpar structure contains the information you need to allocate your own AVStream. Old code for AVStream::codec AVCodecContext *avctx = stream->codec; new code using AVStream::codecpar AVCodec *pCodec = avcodec_find_decoder(stream->codecpar->codec_id); AVCodecContext *avctx = avcodec_alloc_context3(pCodec); avcodec_parameters_to_context(avctx, stream->codecpar); av_codec_set_pkt_timebase(avctx, stream->time_base); The avctx must saved and the same value used for subsequent calls with that stream. Existing code which uses stream->codec must instead keep track of the axctx value to use each time a packet is received. Old Code for avcodec_close: avcodec_close(st->codec); New code using avcodec_free_context: avcodec_free_context(&avctx); Note the old code must still be used for any AVCodecContext obtained from stream->codec.
- Loading branch information