[FFmpeg-devel] On obfuscated nature of public(!) API call av_dup_packet()

Anton Khirnov anton at khirnov.net
Sat Sep 15 12:01:11 CEST 2012

On Sat, 15 Sep 2012 09:33:00 +0300, Andrey Utkin <andrey.krieger.utkin at gmail.com> wrote:
> At first, this function has uncomprehendable doc comment at
> declaration, which states "something scary", but neither prohibits its
> free usage, nor explains for which cases it is usable.
> /**
>  * @warning This is a hack - the packet memory allocation stuff is broken. The
>  * packet is allocated if it was not really allocated.
>  */
> int av_dup_packet(AVPacket *pkt);
> It gets unclear if AVPacket duplication is possible at all, or it is
> very-very forbidden. Some users make up their own packet copying
> function.

The thing is, this function is horribly named. It is not 'duplicate
supplied packet'.  It is 'ensure that supplied packet is backed by
malloced storage and thus will remain valid until the caller frees it'.
It does so by duplicating the packet payload when the free callback is

Anton Khirnov

More information about the ffmpeg-devel mailing list