PDA

View Full Version : MPEG 1/2 : Specifications ?


Kyle_Katarn
29th January 2004, 12:57
I'm working on a "Video Toolbox" ( http://www.katarncorp.com/?vtb ) and i would like to get resolution, bitrate... from a MPEG 1/2 video file.

Do you know where i could find info about this ?

RB
29th January 2004, 14:22
This is better asked in Development.

Kyle_Katarn
29th January 2004, 16:03
Ok i'll do !

RB
29th January 2004, 16:47
Uh, thread is already moved to Development forum.

Kyle_Katarn
29th January 2004, 16:53
I've seen.... thank you !

mpucoder
29th January 2004, 16:57
MPEG-1 (http://www.iso.ch/iso/en/CombinedQueryResult.CombinedQueryResult?queryString=11172) MPEG-2 (http://www.iso.ch/iso/en/CombinedQueryResult.CombinedQueryResult?queryString=13818)
DVD uses the 1998 version of 13818.

Kyle_Katarn
29th January 2004, 17:03
Thank you !

All that i need is resolution, bitrate.... not encoding/decoding specs... isn't there some free (opensource ?) documentation about that anywhere ?

Nic
29th January 2004, 18:38
Resolution you'll get from the sequence header. bitrate will be far more difficult to get. Look at code in projects like DVD2AVI and libmpeg2 to help you....MPEG-2 isn't as straightforward as it might be...

-Nic

Kyle_Katarn
29th January 2004, 18:41
Thank you !
I'll give this a look...

diehardii
30th January 2004, 20:10
Try bbtools. If that doesn't work, PM me and I'll send you something that should work for mpeg2.

~Steve

Kyle_Katarn
31st January 2004, 19:27
Thank you !

Marcel
4th March 2004, 13:21
On wotsit.org I found this:
From: Wilson Woo <wilson00@HK.Super.NET>
To: submit@wotsit.demon.co.uk
Subject: MPEG Video
THIS TEXT CONTAINS ONLY MPEG VIDEO HEADER INFO - BY WILSON WOO
It's only what I know. Please feel free to update it.

Below is information got from someone.
/*****************************************************************/
Sequence Header
This contains information related to one or more "group-of-pictures"
Byte# Data Details
===================================================================
1-4 Sequenceheader code In Hex 000001B3
12 bits Horizontal size In pixels
12 bits Vertical size In pixels
4 bits Pel aspect ratio See below
18 bits Picture rate See below
1 bit Marker bit Always 1
10 bits VBV buffer size Minimum buffer needed to decode this
sequence of pictures; in 16KB units
1 bit Constrained
parameter flag
1 bit Load intra 0: false; 1: true (matrix follows)
quantizer matrix
64 bytes Intra quantizer Optional
matrix
1 bit Load nonintra 0: false; 1: true (matrix follows)
quantizer matrix
64 bytes Nonintra quantizer Optional
matrix
- Squence extension Optional
Data
- User data Optional application-dependent data
===================================================================
Aspect raios are defined by a code which represents the height and
width of the Video image.
Picture rates are also defined by a code that represents the number
of pictures that may be displayed each second.

Each group of pictures has a header that contains one "I picture"
and zero or more B and P pictures. The header is concerned with
the time synchronisation for the first picture in this group, and
the closeness of the previous group to this one.

/*****************************************************************/
For picture rate:
1 = 23.976 frames/sec
2 = 24
3 = 25
4 = 29.97
5 = 30
6 = 50
7 = 59.94
8 = 60

Here gives an example. Below is Hex dump of first 256 bytes of
the first Video frame of TEST.MPG from XingMPEG.
00 00 01 B3 16 00 F0 C4 02 A3 20 A5 10 12 12 14
14 14 16 16 16 16 18 18 19 18 18 1A 1B 1B 1B 1B
1A 1C 1D 1E 1E 1E 1D 1C 1E 1F 20 21 21 20 1F 1E
21 23 23 24 23 23 21 25 26 27 27 26 25 29 2A 2A
2A 29 2D 2D 2D 2D 30 31 30 34 34 38 16 00 F0 C4
00 00 01 B8 00 08 00 00 00 00 01 00 00 0A 72 00
00 00 01 01 13 F9 50 02 BC B2 B8 BE 68 8B A4 9F
C5 B5 CA 00 56 76 39 65 F2 30 8B A6 9D 50 69 E7
DA FE 13 CF B7 FF 8F F4 CE 7B FA 0E F0 66 AE 1C
5D E7 00 C8 0A 92 B9 29 3C 21 23 F1 D6 40 13 06
F0 10 10 C6 27 80 A0 34 E1 C8 E4 0F 74 91 DA C4
03 A0 DC 03 12 60 18 49 27 1D D4 BC 67 0E 54 8C
96 FC 5D C0 06 E0 1A 72 11 7C 9A 8D C9 45 89 6D
CD C4 0B 63 DC 90 18 24 00 EC 84 90 18 10 C9 3B
1E A7 60 3C 9D 74 80 76 05 0B 02 81 A9 29 39 68
53 8F 59 F1 BF 93 FB A0 04 01 BC B0 CE 18 E1 25

Sequence header = (Hex) 00 00 01 B3
Horizontal size = 0x160 = 352
Vertical size = 0x0F0 = 240
Pel aspect ratio = [I don't know]
Picture rate = 4 = 29.97 frames/sec
Marker bit = 1

This helped me a lot; I managed easily to write a simple (and very dirty) delphi unit to get FPS from the clips (adding resolution should be easy):


unit VidInfo;

interface

function getFPS(sFileName: String): Single;

implementation

uses SysUtils;

function getFPS(sFileName: String): Single;
var f: file of byte;
i: integer;
liMsPerFrame: LongInt;
bByte: Byte;
hex: Array [0..15] of Char;
buf: String;
FPS: Single;
begin
for i := 0 to 9 do hex[i] := IntToStr(i)[1];
hex[10]:='A'; hex[11]:='B'; hex[12]:='C'; hex[13]:='D'; hex[14]:='E'; hex[15]:='F';

FPS := 0;

AssignFile(f, sFileName);
Reset(f);
if UpperCase(copy(sFileName, length(sFileName)-2,3)) = 'AVI'
then begin
for i := 1 to 32 do if not EOF(f) then Read(f,bByte);
if not EOF(f) then Read(f,bByte); liMsPerFrame := bByte;
if not EOF(f) then Read(f,bByte); liMsPerFrame := liMsPerFrame + bByte * 256;
if not EOF(f) then Read(f,bByte); liMsPerFrame := liMsPerFrame + bByte * 256 * 256;
if not EOF(f) then Read(f,bByte); liMsPerFrame := liMsPerFrame + bByte * 256 * 256 * 256;
FPS := 1000000 / liMsPerFrame;
end;

if (UpperCase(copy(sFileName, length(sFileName)-3,4)) = 'MPEG')
or (UpperCase(copy(sFileName, length(sFileName)-2,3)) = 'MPG')
or (UpperCase(copy(sFileName, length(sFileName)-2,3)) = 'MPE')
then begin
if length(buf) >= 8 then delete(buf,1,2);
while (EOF(f)=false) and (buf<>'000001B3') do begin
if length(buf) >= 8 then delete(buf,1,2);
Read(f,bByte);
buf := buf + hex[bByte DIV 16] + hex[bByte MOD 16];
end;
for i := 1 to 4 do if not EOF(f) then Read(f,bByte) else bByte := 0;
bByte := bByte MOD 16;
Case bByte of
1: FPS := 23.976;
2: FPS := 24;
3: FPS := 25;
4: FPS := 29.97;
5: FPS := 30;
6: FPS := 50;
7: FPS := 59.94;
8: FPS := 60;
end;
end;
CloseFile(f);
getFPS := round(FPS*100)/100; //or getFPS := FPS if you want the exact value
end;


For usage in worldwide spreaded apps, this sure needs a lot of work (check if file exists etc), but it gives me the framerate of MPEG and AVI files.

Kyle_Katarn
4th March 2004, 13:25
Thanks !

Gabrielgoc
4th March 2004, 17:51
Please refer to this thread, MPEG Validator obtain all info you need. Sources are included.

http://forum.doom9.org/showthread.php?s=&threadid=71696

Gabriel

Kyle_Katarn
4th March 2004, 18:03
Great ! Thank you !