Getting frame dimension from raw mpeg4 stream?
does anyone know how i can retrieve the frame dimension of a mpeg4 video (non h264, i.e. Mpeg4 Part 2) from the raw video开发者_StackOverflow社区 bitstream? i´m currently writing a custom media source for windows media foundation, i have to provide a mediatype which needs the frame size. it doesn´t work without it. any ideas? thanks
I am not getting you. Are you trying to know the width and the height of the video being streamed? If so (and I guess that it is the "dimension" you are looking for) heres how:
- Parse the stream for this integer
000001B0
(hex) its always the first thing you get streamed. If not, see the SDP of the stream (if you have any, and search forconfig=
field, and there it is... only now it is a Base16 string! - Read all the bytes until you get to the integer
000001B6
(hex) - You should get something like this (hex):
000001B0F5000001B5891300000100000001200086C40FA28 A021E0A2
- This is the "stream configuration header" or frame or whatever, exact name is Video Object Sequence. It holds all the info a decoder would need to decode the video stream.
- Read the last 4 bytes (in my example they are separated by one space --
A021E0A2
) - Now observe these bytes as one 32-bit unsigned integer...
- To get width read the first 8 bits, and then multiply what you get with 4
- Skip next 7 bits
- To get height read next 9 bits
In pseudo code:
WIDTH = readBitsUnsigned(array, 8) * 4; readBitsUnsigned(array, 7); HEIGHT = readBitsUnsigned(array, 9);
There you go... width and height. (:
精彩评论