[FFmpeg-devel] Trouble with packet duplication/queue

Deron deron at pagestream.org
Wed Mar 21 23:09:06 CET 2012


Trying to fix some odd bugs in the decklink patch I posted awhile ago. 
The last big one seems to be related to the way I am putting packets 
into the queue. I tried using the same basic code from ffplay and the 
various player demos, but they crash a violent death (double free).

here is the code in question from ffplay that does not work for me:

     if (av_dup_packet(pkt) < 0)
         return -1;

     pkt1 = (AVPacketList*)av_malloc(sizeof(AVPacketList));
     if (!pkt1)
         return -1;
     pkt1->pkt = *pkt;


if instead I do this in my code (more or less borrowed from 
avformat/utils.c as I recall):

     pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList));
     if (!pkt1)
         return -1;
     pkt1->pkt = *pkt;
     pkt->destruct = NULL;             // do not free original but only 
the copy
     /* duplicate the packet */
     if (av_dup_packet(&pkt1->pkt) < 0) {
         av_free(pkt1);
         return -1;
     }


It works 99% of the time. In fact, it was working so well I thought all 
was well. Until I ran across a set of videos which have a _bunch_ of 
frame with just 75 samples. The audio is also being resampled from 30khz 
to 48khz with -ar 48000 in the ffmpeg line. This audio comes out as 
complete garbage (lot of stuttering noise), and sounds like the audio 
when I had the queue almost right. If I first reencode the video to 48k 
then is plays fine (but it also ends up with bigger frames of audio).

So I guess the first question is what is the proper way to stuff a 
packet into a queue inside an avdevice encoder?

Deron



More information about the ffmpeg-devel mailing list