From: Subrata Goswami
Sent: 20 February 2019 22:08
To: [email protected]
Subject: [Libav-user] Strange memory leak and fragmentation

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 . 



You need to use av_packet_unref(&packet); so that the library can free the 
packet struct after you are done with it. 
https://ffmpeg.org/doxygen/4.0/group__lavc__packet.html#ga63d5a489b419bd5d45cfd09091cbcbc2


_______________________________________________
Libav-user mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to