[Libav-user] Strange memory leak and fragmentation

Subrata Goswami subrata at ambient.ai
Wed Feb 20 23:00:31 EET 2019


Have couple of simple questions on the following  few lines of code.

    AVFrame *frame = av_frame_alloc();
    AVPacket packet;

    while(av_read_frame(ictx, &packet)>=0) {
        if(packet.stream_index==video_stream) {

            avcodec_send_packet(octx, &packet);
            if(avcodec_receive_frame(octx, frame)==0) {
            }
        }

    }

1.   The  above leaks memory, but  the following piece of code does not.

    AVFrame *frame = av_frame_alloc();
    AVPacket *packet=av_packet_alloc();

    while(av_read_frame(ictx, packet)>=0) {
        if(packet->stream_index==video_stream) {

            avcodec_send_packet(octx, packet);
            if(avcodec_receive_frame(octx, frame)==0) {
            }
        }
        av_packet_free(&packet);
        packet=av_packet_alloc();
    }

2.  Is there any way to reuse the packet structure, else rapid free and
alloc  probably leads to memory  fragmentation.

Would appreciate  any insight, comment, advice. Thanks .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190220/d64d0e5f/attachment.html>


More information about the Libav-user mailing list