Hi Anand,

For most real-world streams, that will give you something very close to 
the exact answer, sure. So yes, I think that should work fine.

I hesitate for two reasons:

(1) A picture can have more than one slice, I think, even in the Main
     Profile. I don't think I've ever seen this in a real stream, though.

(2) Technically, you're calling mpeg2_getpos() AFTER libmpeg2 has parsed
     the header. So when you're in STATE_PICTURE, your position will be at
     the end of the picture header, not the beginning of it. This only
     makes a tiny difference but if you need the "exact" frame size,
     you might care about this.

If you want to do this absolutely perfectly correct, don't use libmpeg2 at 
all. Just search the MPEG-2 elemental stream for the four-byte string 
{0x0, 0x0, 0x1, 0x0}. That's the start of a picture header. Then search 
for the next picture start code (0x0 0x0 0x1 0x0). That's the start of the 
next picture. Done -- the difference in absolute position between these 
two start codes is the number of bytes required to code the picture.

If you want to have a more refined definition of what the "exact frame 
size" means, you might want to also stop counting when you get to a new 
sequence header (0x0 0x0 0x1 0xB3) or an end-of-sequence header (0x0 0x0 
0x1 0xB7), and then don't start up the count for the next frame until you 
hit a picture start (0x0 0x0 0x1 0x0).

But unless you care about being absolutely precise down to the last few 
tens of bytes, your method will work fine.

Hope this helps,
Keith

On Thu, 5 Apr 2007, anand meher wrote:

> Hi,
>   i am trying to find the frame sizes (in bytes ) using decode_mpeg2.
>
>                                   Can i take the difference of
> mpeg2_getpos() return values when it hits the STATE_PICTURE(when the picture
> header is found) and STATE_SLICE(when the last slice of a picture has been
> found)  to get the exact frame size.
>                                                   Thanks in advance
>
> regards
>
> anand
>
>
>
> On 4/5/07, Keith Winstein <[EMAIL PROTECTED]> wrote:
>> 
>> Hi Anand,
>> 
>> Please reply to the list in case somebody else wants to chime in.
>> 
>> mpeg2_getpos() returns the total number of bytes (octets) since the start
>> of the stream. So yes, you will have to take the difference between
>> hitting one PICTURE header and the next header (probably PICTURE or
>> SEQUENCE) in order to find the coded length of the picture (in bytes).
>> 
>> There's basically no way to determine the coded length of the picture
>> until you hit the next header.
>> 
>> Best,
>> Keith
>> 
>> On Wed, 4 Apr 2007, anand meher wrote:
>> 
>> > Hi kieth,
>> >               As i mentioned earlier i am looking for the frame
>> > sizes(i.ethe exact no of bytes ) required for coding,
>> >             I am calling mpeg2_getpos() in STATE_PICTURE. of
>> decode_mpeg2
>> > function .I am getting an integer number in return.Can u please explain
>> > further to get the exact frame sizes . do we need to take the
>> > diference(i.ethe difference of the return value pf mpeg2_getpos()when
>> > 1st picture header
>> > was hit and the second return value from mpeg2_getpos() when the next
>> > picture header is hit....                    OR
>> >
>> > will the reurn value of mpeg2_getpos() directly gives the frame size...?
>> >                                                                  looking
>> > for ur reply  and thanks in advance
>> >
>> > regards
>> >
>> > anand.
>> >
>> >
>> >
>> > i hope i am making sense..please correct me if i am wrong ) .
>> >
>> >
>> > On 4/4/07, anand meher < [EMAIL PROTECTED]> wrote:
>> >>
>> >> Hi keith,
>> >>              i am glad to recieve a mail from you.I am working on a
>> >> project which requires the exact frame sizes(i.e the no of bytes)
>> >> required to code. I am using mpeg2dec.c program in libmpeg2 . There is
>> a
>> >> function called as decode_mpeg2 which is a kind of event handler.
>> >>
>> >>        The point 1 in ur reply is the exact one i was asking about. I
>> >> think in the decode_mpeg2
>> >> function and in the case STATE_PICTURE ,we need to call
>> mpeg2_getpos().I
>> >> will try for that.
>> >> anyways i am really glad for ur quick reply.
>> >>                                  If i get any more doubts..i will try
>> to
>> >> mail you.
>> >>
>> >> Thanks & regards
>> >>
>> >> Anand.
>> >>
>> >>
>> >>
>> >>
>> >> On 4/4/07, Keith Winstein < [EMAIL PROTECTED]> wrote:
>> >> >
>> >> > Hi Anand,
>> >> >
>> >> > Not sure exactly what you mean. Are you asking about:
>> >> >
>> >> > (1) The number of bits required to code each picture ( e.g., "911376
>> bits
>> >> > for the I frame, 115936 for the B frame after it, etc.")? For this,
>> >> > you'll
>> >> > have to call mpeg2_getpos() to get the position in the stream as you
>> hit
>> >> > PICTURE headers.
>> >> >
>> >> > (2) The horizontal and vertical sizes of the luma and chroma
>> matrices.
>> >> > These are in the sequence header -- see the code to dump_state.c for
>> an
>> >> > example. E.g., "1920x1088 for luma, 960x544 for chroma".
>> >> >
>> >> > (3) The intended displayed area of the frame (e.g., "1920x1080").
>> This
>> >> > is
>> >> > in the sequence display extension header, also printed out by
>> >> > dump_state.c
>> >> > ("seq->display_width", etc.).
>> >> >
>> >> > Sizes #2 and #3 are not allowed to vary on a picture-by-picture
>> basis.
>> >> > Only by ending the sequence and then starting a new sequence can you
>> >> > change the size of the image. (A picture display extension header can
>> >> > vary
>> >> > the location of the "display rectangle" within the full luma and
>> chroma
>> >> > matrices, but it can't change the dimensions of the "display
>> >> > rectangle.")
>> >> >
>> >> > Hope that helps. If you can be more specific I'd be happy to help
>> >> > further.
>> >> >
>> >> > Best,
>> >> > Keith
>> >> >
>> >> > On Wed, 4 Apr 2007, anand meher wrote:
>> >> >
>> >> > > Hi,
>> >> > >      i am trying to find the frame sizes of the individual i,b,p
>> frame
>> >> > > sizes using libmpeg2.the current picture data structure does not
>> >> > provide
>> >> > > with the frame size.so is there any other way  to find the frame
>> sizes
>> >> > > usiiiing libmpeg2. i am using the decode function in
>> mpeg2dec.cprogram
>> >> of
>> >> > > libmpeg2.
>> >> > >
>> >> > > thanks in advance
>> >> > >
>> >> >
>> >>
>> >>
>> >
>> 
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Libmpeg2-devel mailing list
Libmpeg2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libmpeg2-devel

Reply via email to