Scanning a file

Bengt Richter bokr at oz.net
Mon Oct 31 17:18:19 CET 2005


On Mon, 31 Oct 2005 09:41:02 +0100, =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= <lasse at vkarlsen.no> wrote:

>David Rasmussen wrote:
><snip>
>> If you must know, the above one-liner actually counts the number of 
>> frames in an MPEG2 file. I want to know this number for a number of 
>> files for various reasons. I don't want it to take forever.
><snip>
>
>Don't you risk getting more "frames" than the file actually have? What 
>if the encoded data happens to have the magic byte values for something 
>else?
>
Good point, but perhaps the bit pattern the OP is looking for is guaranteed
(e.g. by some kind of HDLC-like bit or byte stuffing or escaping) not to occur
except as frame marker (which might make sense re the problem of re-synching
to frames in a glitched video stream).

The OP probably knows. I imagine this thread would have gone differently if the
title had been "How to count frames in an MPEG2 file?" and the OP had supplied
the info about what marks a frame and whether it is guaranteed not to occur
in the data ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list