annotate libmpdemux/mpeg_hdr.c @ 13919:d57caeb6cf0b

added fourcc of PNG-encoded Quicktime files
author reimar
date Thu, 11 Nov 2004 13:41:35 +0000
parents 85556424c02e
children 92553e3c8f01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
1
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
2 // based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
3
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
4 // #include <inttypes.h>
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
5 #include <stdio.h>
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
6
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
7 #include "config.h"
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
8 #include "mpeg_hdr.h"
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
9
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
10 static int frameratecode2framerate[16] = {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
11 0,
5441
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
12 // Official mpeg1/2 framerates: (1-8)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
13 24000*10000/1001, 24*10000,25*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
14 30000*10000/1001, 30*10000,50*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
15 60000*10000/1001, 60*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
16 // Xing's 15fps: (9)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
17 15*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
18 // libmpeg3's "Unofficial economy rates": (10-13)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
19 5*10000,10*10000,12*10000,15*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
20 // some invalid ones: (14-15)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
21 0,0
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
22 };
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
23
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
24
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
25 int mp_header_process_sequence_header (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
26 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
27 int width, height;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
28
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
29 if ((buffer[6] & 0x20) != 0x20){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
30 printf("missing marker bit!\n");
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
31 return 1; /* missing marker_bit */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
32 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
33
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
34 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
35
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
36 picture->display_picture_width = (height >> 12);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
37 picture->display_picture_height = (height & 0xfff);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
38
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
39 width = ((height >> 12) + 15) & ~15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
40 height = ((height & 0xfff) + 15) & ~15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
41
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
42 picture->aspect_ratio_information = buffer[3] >> 4;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
43 picture->frame_rate_code = buffer[3] & 15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
44 picture->fps=frameratecode2framerate[picture->frame_rate_code];
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
45 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
46 picture->mpeg1 = 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
47 picture->picture_structure = 3; //FRAME_PICTURE;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
48 picture->display_time=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
49 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
50 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
51
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
52 static int header_process_sequence_extension (mp_mpeg_header_t * picture,
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
53 unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
54 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
55 /* check chroma format, size extensions, marker bit */
12562
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
56
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
57 if ( ((buffer[1] & 0x06) == 0x00) ||
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
58 ((buffer[1] & 0x01) != 0x00) || (buffer[2] & 0xe0) ||
83d91a7cba19 mpeg2 chroma422/444 support
iive
parents: 5441
diff changeset
59 ((buffer[3] & 0x01) != 0x01) )
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
60 return 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
61
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
62 picture->progressive_sequence = (buffer[1] >> 3) & 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
63 picture->mpeg1 = 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
64 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
65 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
66
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
67 static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
68 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
69 picture->picture_structure = buffer[2] & 3;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
70 picture->top_field_first = buffer[3] >> 7;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
71 picture->repeat_first_field = (buffer[3] >> 1) & 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
72 picture->progressive_frame = buffer[4] >> 7;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
73
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
74 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
75 picture->display_time=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
76 if(picture->repeat_first_field){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
77 if(picture->progressive_sequence){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
78 if(picture->top_field_first)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
79 picture->display_time+=200;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
80 else
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
81 picture->display_time+=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
82 } else
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
83 if(picture->progressive_frame){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
84 picture->display_time+=50;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
85 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
86 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
87 //temopral hack. We calc time on every field, so if we have 2 fields
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
88 // interlaced we'll end with double time for 1 frame
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
89 if( picture->picture_structure!=3 ) picture->display_time/=2;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
90 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
91 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
92
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
93 int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
94 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
95 switch (buffer[0] & 0xf0) {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
96 case 0x10: /* sequence extension */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
97 return header_process_sequence_extension (picture, buffer);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
98 case 0x80: /* picture coding extension */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
99 return header_process_picture_coding_extension (picture, buffer);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
100 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
101 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
102 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
103