AliReza Khoshgoftar schrieb:
> Hi,
> I am trying to count the number of packets in an mpeg2 elementary stream.
> Doing it in two different ways, I get different results.
>
> *Method 1:*
> I use "packet_buffer" data member of my AVForamtContext media handle(let's
> name if "pFormatCtx"), and simly count the number of the nodes in the linked
> list like this:
>
> AVPacketList *packetBuffer;
>
>> int packet_count;
>> packetBuffer = pFormatCtx -> packet_buffer;
>> while(packetBuffer->next != NULL){
>> packet_count++;
>> packetBuffer = packetBuffer->next;
>> }
>>
>>
>
>
As I understood, the packet_buffer only holds packets that have already
been read but no decoded yet. When you call av_find_stream_info libav
will read some packets to get stream information. Those packets will be
put in the packet_buffer so that they don't have to be extracted again.
The other packets will be added to this buffer later by av_read_frame.
> *Method 2:*
> I increment a counter whenever I read a packet using "av_read_frame()":
>
> int packet_count;
>
>> while(av_read_frame(pFormatCtx, &packet)>=0) {
>> packet_count++;
>> /*some code*/
>> }
>>
>>
>
>
That way is right.
> The first method results in "packet_count = 76", the second results in
> "packet_count=375", while I know that "av_read_frame" in my case is simply
> reading the "pkt" of the linked list "packet_buffer"(which is in
> AVFormatContext object)
> So, why is the result for the two case so different?
>
av_read_frame is not only reading packets from the packet_buffer, it
also reads new packets (with av_read_frame_internal) and adds them to
it. The 76 packets in the packet_buffer from method 1 are only those
packets that were needed to find stream informations. If you would have
called av_read_frame in you loop from method 1 the other packets would
have been added one by one to the packet_buffer and it would also result
in packet_count=375.
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user