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 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
Asked
Active
Viewed 1,855 times
1 Answers
3
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. (:

Cipi
- 11,055
- 9
- 47
- 60
-
2Is this correct? I'm trying to decode frames of a stream I know is 1280x1024. With this logic, the width can't be above 1020, and height can't be above 511. – Ninjammer Sep 22 '13 at 23:14
-
WIDTH should multiply by 8 instead of 4, and HEIGHT should multiply by 2 also for that integer read from last 5 bytes instead of 4 bytes. – Nima May 02 '17 at 12:56