<div dir="ltr"><div><div>Yes. I have found you can also check if pkt->packet.size == 0 instead of pkt->buf == NULL.<br><br><br></div>Regards,<br></div>Gabriel.<br><br><div><div><br></div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><br><a href="http://lives-video.com" target="_blank">http://lives-video.com</a><br><a href="https://www.openhub.net/accounts/salsaman" target="_blank">https://www.openhub.net/accounts/salsaman</a><br></div></div></div></div></div>
<br><div class="gmail_quote">On Sun, Aug 21, 2016 at 9:36 PM, Charles <span dir="ltr"><<a href="mailto:linux2@orion15.org" target="_blank">linux2@orion15.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 08/21/2016 07:23 PM, Brian Brice wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You should probably use av_packet_alloc instead of av_malloc on the<br>
AVPacket. This will ensure that each field is initialized properly.<br>
<br>
The demuxer could set the data pointer to its own internal storage<br>
(when buf is NULL) which can be reused when you call av_read_frame<br>
another time. The call to av_packet_unref is mostly to decrement the<br>
reference count on the buf pointer. It does other things, like<br>
releasing the side data and resetting the fields to some default.<br>
<br>
On Fri, Aug 19, 2016 at 3:31 PM, Charles <<a href="mailto:linux2@orion15.org" target="_blank">linux2@orion15.org</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a piece of code that appears to work, that is to say it does stream<br>
packets..<br>
It goes like this:<br>
av_packet = (AVPacket *) av_malloc( sizeof( AVPacket ) );<br>
while ( 1 ) /// reading in from file out to mpegts<br>
{<br>
av_read_frame( av_in_fmt_ctx, m_avpacket );<br>
[...]<br>
ret = av_interleaved_write_frame( av_out_fmt_ctx, av_packet );<br>
av_packet_unref( av_packet );<br>
}<br>
<br>
In the include headers I find this type of verbage ::<br>
* The side data is always allocated with av_malloc(), copied by<br>
* av_packet_ref() and freed by av_packet_unref().<br>
<br>
>From reading the av_read_frame I know the packed is a reference to another<br>
packet (at least the buf).<br>
<br>
Question :<br>
What is av_malloc doing if the packet is getting unref and passed back into<br>
av_read_frame without another malloc?<br>
<br>
Follow Up :<br>
Is this thread safe?<br>
<br>
</blockquote></blockquote>
<br></div></div>
This may be poor form but I just declared an AVPacket<br>
<br>
/// \note setup stuff used in ReadFrame<br>
av_init_packet( &av_pkt );<br>
av_pkt.data = NULL; /// demux will allocate<br>
av_pkt.size = 0;<br>
[...]<br>
<br>
Comments from av_read_frame<br>
<br>
* If pkt->buf is NULL, then the packet is valid until the next<br>
* av_read_frame() or until avformat_close_input(). Otherwise the packet<br>
* is valid indefinitely. In both cases the packet must be freed with<br>
* av_packet_unref when it is no longer needed.<br>
<br>
I am using the new ABI avcodec_send_packet / avcodec_receive_frame<br>
Since it is a spinning thread, the packet stays in scope and I just never delete it...<br>
Seems to work ok<div class="HOEnZb"><div class="h5"><br>
<br>
Thanks<br>
cco<br>
<br>
______________________________<wbr>_________________<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/list<wbr>info/libav-user</a><br>
</div></div></blockquote></div><br></div>