[Libav-user] AVPacket av_malloc av_packet_unref question

Charles linux2 at orion15.org
Fri Aug 19 23:31:51 EEST 2016

I have a piece of code that appears to work, that is to say it does stream packets..
It goes like this:
av_packet = (AVPacket *) av_malloc( sizeof( AVPacket ) );
while ( 1 ) /// reading in from file out to mpegts
    av_read_frame( av_in_fmt_ctx, m_avpacket );
    ret = av_interleaved_write_frame( av_out_fmt_ctx, av_packet );
    av_packet_unref( av_packet );

In the include headers I find this type of verbage ::
  * The side data is always allocated with av_malloc(), copied by
  * av_packet_ref() and freed by av_packet_unref().

 From reading the av_read_frame I know the packed is a reference to another packet (at least the buf).

Question :
What is av_malloc doing if the packet is getting unref and passed back into av_read_frame without another malloc?

Follow Up :
Is this thread safe?


More information about the Libav-user mailing list