<div dir="ltr">So I can write something like this and it would be ok?<div><br></div><div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif">AVCodecContext *codecContext;</div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif">AVPacket *packet;</div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif">AVFrame *frame;</div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif">// allocating codec context, getting packet</div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif">.................................</div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif">//</div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif"><div>avcodec_send_packet(codecContext, packet);</div><div>while(avcodec_receive_frame(codecContext, frame) == 0)</div></div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif">{</div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif"> av_frame_unref(frame);</div><div style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif">}</div></div></div><br><div class="gmail_quote"><div dir="ltr">пт, 16 сент. 2016 г. в 2:26, Steve <<a href="mailto:musicspeedchanger@gmail.com">musicspeedchanger@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Timur Guseynov wrote<br>
> I'm a bit confused with decoding/encoding api. I've read this<br>
> <<a href="https://ffmpeg.org/doxygen/3.1/group__lavc__encdec.html>" rel="noreferrer" target="_blank">https://ffmpeg.org/doxygen/3.1/group__lavc__encdec.html></a>;<br>
> documentation and<br>
> it says "Receive output in a loop. Periodically call one of the<br>
> avcodec_receive_*()...".<br>
><br>
> avcodec_receive_frame() docs say "the function will always call<br>
> av_frame_unref(frame) before doing anything else." The same goes for<br>
> avcodec_receive_packet().<br>
><br>
> So, for example, I will write such code:<br>
><br>
> AVCodecContext *codecContext;<br>
> AVPacket *packet;<br>
> AVFrame *frame;<br>
> // allocating codec context, getting packet<br>
> .................................<br>
> //<br>
> avcodec_send_packet(codecContext, packet);<br>
> while(avcodec_receive_frame(codecContext, frame) == 0)<br>
> {<br>
> }<br>
><br>
> Will this code be functioning right?<br>
><br>
> _______________________________________________<br>
> Libav-user mailing list<br>
<br>
> Libav-user@<br>
<br>
> <a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
The doc for avcodec_receive_packet has you need to check a typo, it calls<br>
av_packet_unref. This is just convenience, you would have to call<br>
av_packet_unref or av_frame_unref yourself otherwise on each turn.<br>
<br>
Your code would be ok but you need to call av_packet_unref at the end<br>
because you retain ownership of the packet.<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://libav-users.943685.n4.nabble.com/Libav-user-Decoding-encoding-api-tp4662664p4662672.html" rel="noreferrer" target="_blank">http://libav-users.943685.n4.nabble.com/Libav-user-Decoding-encoding-api-tp4662664p4662672.html</a><br>
Sent from the libav-users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
</blockquote></div>