[FFmpeg-devel] [PATCH 1/2] lavf: add AVFMT_AVFRAME flag
ramiro.polla at gmail.com
Thu Dec 26 02:42:16 CET 2013
Attached patch adds another AVFMT flag that provides the muxer with a
referenced frame. The way it works is that the muxer is passed an
AVFrame structure with its reference count incremented (with
av_frame_clone()). The muxer can then keep the frame for as long as it
sees fit and is responsible for unreferencing it. This will be used by
the decklink output device (my next patch).
The problem with using plain AVFMT_RAWPICTURE is that the frame is
unreferenced in FFmpeg while the muxer might still be using it. By not
using AVFMT_RAWPICTURE, the frame is encoded to rawvideo, which causes
an extra data copy. In 1080p for decklink this extra copy would take
about 10% of the total time.
This approach still has some issues which I'd like to discuss here.
When an AVFrame is copied directly to another location in memory
(which happens in the packet queue in lavf), extended_data is no
longer equal to data, which is a check used by some av_frame
functions. It is therefore necessary to set extended_data to data
before using the frame in the muxer.
Also, I haven't figured out why, but there are some random errors when
using the referenced frame in the muxer, so it is best to clone it
again and unreference the original frame. For example:
static int write_packet(AVFormatContext *avctx, AVPacket *pkt)
AVFrame *avframe = (AVFrame *) pkt->data;
avframe->extended_data = avframe->data;
avframe2 = av_frame_clone(avframe);
<avframe2 is now correctly referenced>
More information about the ffmpeg-devel