0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

mpeg video header parser

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2566 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
arpi 2001-10-30 18:45:54 +00:00
parent 6b0ee0f3c3
commit f395431b7d
3 changed files with 122 additions and 1 deletions

View File

@ -3,7 +3,7 @@ LIBNAME = libmpdemux.a
include ../config.mak
SRCS = cache2.c asfheader.c aviheader.c aviprint.c aviwrite.c demux_asf.c demux_avi.c demux_mov.c demux_mpg.c demuxer.c dvdauth.c open.c parse_es.c stream.c
SRCS = mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c aviwrite.c demux_asf.c demux_avi.c demux_mov.c demux_mpg.c demuxer.c dvdauth.c open.c parse_es.c stream.c
ifeq ($(STREAMING),yes)
SRCS += asf_streaming.c url.c http.c network.c
endif

100
libmpdemux/mpeg_hdr.c Normal file
View File

@ -0,0 +1,100 @@
// based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
// #include <inttypes.h>
#include <stdio.h>
#include "config.h"
#include "mpeg_hdr.h"
static int frameratecode2framerate[16] = {
0,
// Official mpeg1/2 framerates:
24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 60*10000,
// libmpeg3's "Unofficial economy rates":
1*10000,5*10000,10*10000,12*10000,15*10000,0,0
};
int mp_header_process_sequence_header (mp_mpeg_header_t * picture, unsigned char * buffer)
{
int width, height;
if ((buffer[6] & 0x20) != 0x20){
printf("missing marker bit!\n");
return 1; /* missing marker_bit */
}
height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
picture->display_picture_width = (height >> 12);
picture->display_picture_height = (height & 0xfff);
width = ((height >> 12) + 15) & ~15;
height = ((height & 0xfff) + 15) & ~15;
if ((width > 768) || (height > 576)){
printf("size restrictions for MP@ML or MPEG1 exceeded! (%dx%d)\n",width,height);
// return 1; /* size restrictions for MP@ML or MPEG1 */
}
picture->aspect_ratio_information = buffer[3] >> 4;
picture->frame_rate_code = buffer[3] & 15;
picture->fps=frameratecode2framerate[picture->frame_rate_code];
picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
picture->mpeg1 = 1;
picture->picture_structure = 3; //FRAME_PICTURE;
picture->display_time=100;
return 0;
}
static int header_process_sequence_extension (mp_mpeg_header_t * picture,
unsigned char * buffer)
{
/* check chroma format, size extensions, marker bit */
if (((buffer[1] & 0x07) != 0x02) || (buffer[2] & 0xe0) ||
((buffer[3] & 0x01) != 0x01))
return 1;
picture->progressive_sequence = (buffer[1] >> 3) & 1;
picture->mpeg1 = 0;
return 0;
}
static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
{
picture->picture_structure = buffer[2] & 3;
picture->top_field_first = buffer[3] >> 7;
picture->repeat_first_field = (buffer[3] >> 1) & 1;
picture->progressive_frame = buffer[4] >> 7;
// repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
picture->display_time=100;
if(picture->repeat_first_field){
if(picture->progressive_sequence){
if(picture->top_field_first)
picture->display_time+=200;
else
picture->display_time+=100;
} else
if(picture->progressive_frame){
picture->display_time+=50;
}
}
//temopral hack. We calc time on every field, so if we have 2 fields
// interlaced we'll end with double time for 1 frame
if( picture->picture_structure!=3 ) picture->display_time/=2;
return 0;
}
int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
{
switch (buffer[0] & 0xf0) {
case 0x10: /* sequence extension */
return header_process_sequence_extension (picture, buffer);
case 0x80: /* picture coding extension */
return header_process_picture_coding_extension (picture, buffer);
}
return 0;
}

21
libmpdemux/mpeg_hdr.h Normal file
View File

@ -0,0 +1,21 @@
typedef struct {
// video info:
int mpeg1; // 0=mpeg2 1=mpeg1
int display_picture_width;
int display_picture_height;
int aspect_ratio_information;
int frame_rate_code;
int fps; // fps*10000
int bitrate; // 0x3FFFF==VBR
// timing:
int picture_structure;
int progressive_sequence;
int repeat_first_field;
int progressive_frame;
int top_field_first;
int display_time; // secs*100
} mp_mpeg_header_t;
int mp_header_process_sequence_header (mp_mpeg_header_t * picture, unsigned char * buffer);
int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer);