[Libav-user] How To Duplicate AVPacket
Xiemin Chen
chenxiemin at gmail.com
Tue Jul 1 12:37:22 CEST 2014
Dear nfxjfg:
Seems it's still not all right for the solution which you mentioned.
I write the codes like following:
1. pPacket = av_malloc(sizeof(AVPacket))
2. av_init_packet(pPacket);
3. av_read_frame(pPacket);
4. put_queue(packet);
But it seems for a little situation, the frame will contain garbage.
About 0.5s per 30 seconds I can reproduce this issue.
Is there another way I can improve my code?
Thanks very much.
Sincerely
2014-06-26 9:17 GMT-04:00 Xiemin Chen <chenxiemin at gmail.com>:
> Dear nfxjfg:
> I just do av_malloc(sizeof(AVPacket)) instead of define local variable
> AVPacket packet before av_read_frame().
> And nothing else except for putting into queue, then seems that it
> does solve my problem. Thanks for your professional answer.
> Also thanks for indicating my potential memory-leaking mistake.
> Thanks very much.
>
> Sincerely
>
>
>
> 2014-06-26 8:33 GMT-04:00 wm4 <nfxjfg at googlemail.com>:
>
> On Wed, 25 Jun 2014 20:46:59 -0400
>> Xiemin Chen <chenxiemin at gmail.com> wrote:
>>
>> > Dear all:
>> > I want to split av_read_frame() and avcodec_decode_video2() in to
>> > different thread so I need to put a queue behind them. av_read_frame()
>> read
>> > a packet then put the packet into queue, avcodec_decode_video2() read a
>> > packet from the queue then decode.
>> > But sometimes the decoded frames may contain rubbish, it's random.
>> So I
>> > think that AVPacket shares its data memory and overwrite by somebody
>> before
>> > I decode it. The following code like this:
>>
>> Why do you think that? It could be something else. Did you test with
>> valgrind?
>>
>> > 1. av_read_frame(&packet);
>> > 2. av_dup_packet(&packet);
>> > 3. AVPacket *newPakcet = av_malloc(sizeof(AVPacket));
>> > 4. *newPacket = packet;
>>
>> It depends what you do with the original packet after this. If you
>> unref it, the packet might be free'd. If you malloc the AVPacket before
>> the av_read_frame call, and then put that into the queue, you should be
>> fine.
>>
>> > 5. put_queue(packet);
>> > 6. get_queue(&packet); (Another thread)
>> > 7. avcodec_decode_video2(packet, &frame);
>> > 8. show frame;
>> > Is there any mistake I took on these codes? Thanks very much.
>> >
>> > Sincerely
>>
>> AVPackets have other data than the packet buffer - at least side data.
>> av_dup_packet() is an old API that AFAIK does nothing on packets
>> returned by libavformat. (Yes, that is very misleading - and I'm not
>> even sure if it _really_ does nothing.) Now you should use
>> av_packet_ref(), which is a relatively recently added function. But
>> it looks like you don't need it in your specific use-case.
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20140701/dc3bc6de/attachment.html>
More information about the Libav-user
mailing list