[Libav-user] Calculate total streamed in bytes

wm4 nfxjfg at googlemail.com
Fri Apr 11 14:29:41 CEST 2014


On Fri, 11 Apr 2014 14:30:54 +0300
Mert Gedik <gedikmert89 at gmail.com> wrote:

> On Fri, Apr 11, 2014 at 1:11 PM, Lucas Soltic <lucas.soltic at orange.fr>wrote:
> 
> > Le 11 avr. 2014 à 11:20, Mert Gedik <gedikmert89 at gmail.com> a écrit :
> >
> >
> > Hello everyone,
> >
> > I want to show how much data is downloaded in my player, and I did as
> > below,
> >
> >             if (packet.data) {
> >                 totalBytes += packet.size;
> >                 av_free_packet(&packet);
> >             }
> >
> > in a loop that uses av_read_frame
> >
> > How ever, when I tested a video file that I know the size of the video
> > file, I see that totalBytes is always lower than the file size. How can I
> > calculate the exact value ?
> >
> >
> > Thanks,
> >
> >
> > -MG
> >
> >
> > You are computing the size of the data for the video stream only. The
> > video file also contains data for the container format required by the
> > demuxer. Except if you use raw streams, which is usually not the case.
> >
> > Lucas
> >
> > _______________________________________________
> > Libav-user mailing list
> > Libav-user at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/libav-user
> >
> >
> 
> Thanks lucas for the information but
> how can I get the size of data for the container format required by the
> demuxer ?
> 
> Also, I realized that the difference between video file size and my
> calculation gets higher when the video file size is bigger.
> 
> any help is appreciated,

To do this properly, you could implement a custom AVIOContext, which
counts the number of bytes read. But this is probably a bit too
involved just for that. Another, much less reliable possibility is
looking at the packet file positions, and assuming the whole file was
read up until this position. (But it's guaranteed to be off by a small
amount of data.)


More information about the Libav-user mailing list