[Libav-user] Strange memory leak and fragmentation
Strahinja Radman
dr.strashni at gmail.com
Thu Feb 21 15:45:33 EET 2019
From: Subrata Goswami
Sent: 20 February 2019 22:08
To: libav-user at ffmpeg.org
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190221/75984f6a/attachment.html>
More information about the Libav-user
mailing list