<div dir="ltr"><div dir="ltr"><div dir="ltr">Have couple of simple questions on the following  few lines of code. <div><br></div><div><div><font face="monospace, monospace">    AVFrame *frame = av_frame_alloc();</font></div><div><font face="monospace, monospace">    AVPacket packet;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    while(av_read_frame(ictx, &packet)>=0) {</font></div><div><font face="monospace, monospace">        if(packet.stream_index==video_stream) {</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">            avcodec_send_packet(octx, &packet);</font></div><div><font face="monospace, monospace">            if(avcodec_receive_frame(octx, frame)==0) {</font></div><div><font face="monospace, monospace">            }</font></div><div><font face="monospace, monospace">        }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    }</font></div></div><div><br></div><div>1.   The  above leaks memory, but  the following piece of code does not. </div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">    AVFrame *frame = av_frame_alloc();</font></div><div><font face="monospace, monospace">    AVPacket *packet=av_packet_alloc();</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    while(av_read_frame(ictx, packet)>=0) {</font></div><div><font face="monospace, monospace">        if(packet->stream_index==video_stream) {</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">            avcodec_send_packet(octx, packet);</font></div><div><font face="monospace, monospace">            if(avcodec_receive_frame(octx, frame)==0) {</font></div><div><font face="monospace, monospace">            }</font></div><div><font face="monospace, monospace">        }</font></div><div><font face="monospace, monospace">        av_packet_free(&packet);</font></div><div><font face="monospace, monospace">        packet=av_packet_alloc();</font></div><div><font face="monospace, monospace">    }</font></div></div><div><br></div><div>2.  Is there any way to reuse the packet structure, else rapid free and alloc  probably leads to memory  fragmentation.   </div><div><br></div><div>Would appreciate  any insight, comment, advice. Thanks . </div><div><br></div><div><br></div><div><br></div></div></div></div>