Mercurial > mplayer.hg
annotate libmpdemux/mpeg_hdr.c @ 19664:f6badf921e82
Add vertical clipping for subtitles that were moved because of a collision.
author | eugeni |
---|---|
date | Mon, 04 Sep 2006 17:55:57 +0000 |
parents | a1375e440e92 |
children | df1d03939216 |
rev | line source |
---|---|
2565 | 1 |
2 // based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | |
3 | |
15225 | 4 #include <inttypes.h> |
2565 | 5 #include <stdio.h> |
14886 | 6 #include <stdlib.h> |
2565 | 7 |
8 #include "config.h" | |
9 #include "mpeg_hdr.h" | |
10 | |
18398
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
11 #include "mp_msg.h" |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
12 |
16184
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
13 static float frameratecode2framerate[16] = { |
2565 | 14 0, |
5441 | 15 // Official mpeg1/2 framerates: (1-8) |
16184
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
16 24000.0/1001, 24,25, |
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
17 30000.0/1001, 30,50, |
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
18 60000.0/1001, 60, |
5441 | 19 // Xing's 15fps: (9) |
16184
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
20 15, |
5441 | 21 // libmpeg3's "Unofficial economy rates": (10-13) |
16184
04dd5945fab8
100l to whoever wrote this crap using 1/10000 units. it caused framerates to get trashed from 30000/1001 to 2997/100, etc.!
rfelker
parents:
15618
diff
changeset
|
22 5,10,12,15, |
5441 | 23 // some invalid ones: (14-15) |
24 0,0 | |
2565 | 25 }; |
26 | |
27 | |
28 int mp_header_process_sequence_header (mp_mpeg_header_t * picture, unsigned char * buffer) | |
29 { | |
30 int width, height; | |
31 | |
32 if ((buffer[6] & 0x20) != 0x20){ | |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
33 fprintf(stderr, "missing marker bit!\n"); |
2565 | 34 return 1; /* missing marker_bit */ |
35 } | |
36 | |
37 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; | |
38 | |
39 picture->display_picture_width = (height >> 12); | |
40 picture->display_picture_height = (height & 0xfff); | |
41 | |
42 width = ((height >> 12) + 15) & ~15; | |
43 height = ((height & 0xfff) + 15) & ~15; | |
44 | |
45 picture->aspect_ratio_information = buffer[3] >> 4; | |
46 picture->frame_rate_code = buffer[3] & 15; | |
47 picture->fps=frameratecode2framerate[picture->frame_rate_code]; | |
48 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6); | |
49 picture->mpeg1 = 1; | |
50 picture->picture_structure = 3; //FRAME_PICTURE; | |
51 picture->display_time=100; | |
52 return 0; | |
53 } | |
54 | |
55 static int header_process_sequence_extension (mp_mpeg_header_t * picture, | |
56 unsigned char * buffer) | |
57 { | |
58 /* check chroma format, size extensions, marker bit */ | |
12562 | 59 |
60 if ( ((buffer[1] & 0x06) == 0x00) || | |
61 ((buffer[1] & 0x01) != 0x00) || (buffer[2] & 0xe0) || | |
62 ((buffer[3] & 0x01) != 0x01) ) | |
2565 | 63 return 1; |
64 | |
65 picture->progressive_sequence = (buffer[1] >> 3) & 1; | |
66 picture->mpeg1 = 0; | |
67 return 0; | |
68 } | |
69 | |
70 static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer) | |
71 { | |
72 picture->picture_structure = buffer[2] & 3; | |
73 picture->top_field_first = buffer[3] >> 7; | |
74 picture->repeat_first_field = (buffer[3] >> 1) & 1; | |
75 picture->progressive_frame = buffer[4] >> 7; | |
76 | |
77 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3: | |
78 picture->display_time=100; | |
79 if(picture->repeat_first_field){ | |
80 if(picture->progressive_sequence){ | |
81 if(picture->top_field_first) | |
82 picture->display_time+=200; | |
83 else | |
84 picture->display_time+=100; | |
85 } else | |
86 if(picture->progressive_frame){ | |
87 picture->display_time+=50; | |
88 } | |
89 } | |
90 //temopral hack. We calc time on every field, so if we have 2 fields | |
91 // interlaced we'll end with double time for 1 frame | |
92 if( picture->picture_structure!=3 ) picture->display_time/=2; | |
93 return 0; | |
94 } | |
95 | |
96 int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer) | |
97 { | |
98 switch (buffer[0] & 0xf0) { | |
99 case 0x10: /* sequence extension */ | |
100 return header_process_sequence_extension (picture, buffer); | |
101 case 0x80: /* picture coding extension */ | |
102 return header_process_picture_coding_extension (picture, buffer); | |
103 } | |
104 return 0; | |
105 } | |
106 | |
18398
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
107 float mpeg12_aspect_info(mp_mpeg_header_t *picture) |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
108 { |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
109 float aspect = 0.0; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
110 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
111 switch(picture->aspect_ratio_information) { |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
112 case 2: // PAL/NTSC SVCD/DVD 4:3 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
113 case 8: // PAL VCD 4:3 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
114 case 12: // NTSC VCD 4:3 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
115 aspect=4.0/3.0; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
116 break; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
117 case 3: // PAL/NTSC Widescreen SVCD/DVD 16:9 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
118 case 6: // (PAL?)/NTSC Widescreen SVCD 16:9 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
119 aspect=16.0/9.0; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
120 break; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
121 case 4: // according to ISO-138182-2 Table 6.3 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
122 aspect=2.21; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
123 break; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
124 case 1: // VGA 1:1 - do not prescale |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
125 case 9: // Movie Type ??? / 640x480 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
126 aspect=0.0; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
127 break; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
128 default: |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
129 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Detected unknown aspect_ratio_information in mpeg sequence header.\n" |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
130 "Please report the aspect value (%i) along with the movie type (VGA,PAL,NTSC," |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
131 "SECAM) and the movie resolution (720x576,352x240,480x480,...) to the MPlayer" |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
132 " developers, so that we can add support for it!\nAssuming 1:1 aspect for now.\n", |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
133 picture->aspect_ratio_information); |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
134 } |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
135 |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
136 return aspect; |
a1375e440e92
COSMETICS: moved code to parse mpeg1/2 A/R to mpeg_hdr.c
nicodvb
parents:
17952
diff
changeset
|
137 } |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
138 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
139 //MPEG4 HEADERS |
14967 | 140 unsigned char mp_getbits(unsigned char *buffer, unsigned int from, unsigned char len) |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
141 { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
142 unsigned int n; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
143 unsigned char m, u, l, y; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
144 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
145 n = from / 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
146 m = from % 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
147 u = 8 - m; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
148 l = (len > u ? len - u : 0); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
149 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
150 y = (buffer[n] << m); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
151 if(8 > len) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
152 y >>= (8-len); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
153 if(l) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
154 y |= (buffer[n+1] >> (8-l)); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
155 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
156 //fprintf(stderr, "GETBITS(%d -> %d): bytes=0x%x 0x%x, n=%d, m=%d, l=%d, u=%d, Y=%d\n", |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
157 // from, (int) len, (int) buffer[n],(int) buffer[n+1], n, (int) m, (int) l, (int) u, (int) y); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
158 return y; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
159 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
160 |
14967 | 161 #define getbits mp_getbits |
162 | |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
163 static int read_timeinc(mp_mpeg_header_t * picture, unsigned char * buffer, int n) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
164 { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
165 if(picture->timeinc_bits > 8) { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
166 picture->timeinc_unit = getbits(buffer, n, picture->timeinc_bits - 8) << 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
167 n += picture->timeinc_bits - 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
168 picture->timeinc_unit |= getbits(buffer, n, 8); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
169 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
170 } else { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
171 picture->timeinc_unit = getbits(buffer, n, picture->timeinc_bits); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
172 n += picture->timeinc_bits; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
173 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
174 //fprintf(stderr, "TIMEINC2: %d, bits: %d\n", picture->timeinc_unit, picture->timeinc_bits); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
175 return n; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
176 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
177 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
178 int mp4_header_process_vol(mp_mpeg_header_t * picture, unsigned char * buffer) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
179 { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
180 unsigned int n, aspect=0, aspectw=0, aspecth=0, x=1, v; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
181 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
182 //begins with 0x0000012x |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
183 picture->fps = 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
184 picture->timeinc_bits = picture->timeinc_resolution = picture->timeinc_unit = 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
185 n = 9; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
186 if(getbits(buffer, n, 1)) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
187 n += 7; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
188 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
189 aspect=getbits(buffer, n, 4); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
190 n += 4; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
191 if(aspect == 0x0f) { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
192 aspectw = getbits(buffer, n, 8); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
193 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
194 aspecth = getbits(buffer, n, 8); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
195 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
196 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
197 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
198 if(getbits(buffer, n, 1)) { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
199 n += 4; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
200 if(getbits(buffer, n, 1)) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
201 n += 79; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
202 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
203 } else n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
204 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
205 n+=3; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
206 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
207 picture->timeinc_resolution = getbits(buffer, n, 8) << 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
208 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
209 picture->timeinc_resolution |= getbits(buffer, n, 8); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
210 n += 8; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
211 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
212 picture->timeinc_bits = 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
213 v = picture->timeinc_resolution - 1; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
214 while(v && (x<16)) { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
215 v>>=1; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
216 picture->timeinc_bits++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
217 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
218 picture->timeinc_bits = (picture->timeinc_bits > 1 ? picture->timeinc_bits : 1); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
219 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
220 n++; //marker bit |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
221 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
222 if(getbits(buffer, n, 1)) { //fixed_vop_timeinc |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
223 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
224 n = read_timeinc(picture, buffer, n); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
225 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
226 if(picture->timeinc_unit) |
16319
798d9be2337f
multiplying fps by 10000 is no more necessary (when determining mp4v and h264 framerate)
nicodvb
parents:
16184
diff
changeset
|
227 picture->fps = (float) picture->timeinc_resolution / (float) picture->timeinc_unit; |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
228 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
229 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
230 //fprintf(stderr, "ASPECT: %d, PARW=%d, PARH=%d, TIMEINCRESOLUTION: %d, FIXED_TIMEINC: %d (number of bits: %d), FPS: %u\n", |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
231 // aspect, aspectw, aspecth, picture->timeinc_resolution, picture->timeinc_unit, picture->timeinc_bits, picture->fps); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
232 |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
233 return 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
234 } |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
235 |
14887 | 236 void mp4_header_process_vop(mp_mpeg_header_t * picture, unsigned char * buffer) |
14477
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
237 { |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
238 int n; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
239 n = 0; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
240 picture->picture_type = getbits(buffer, n, 2); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
241 n += 2; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
242 while(getbits(buffer, n, 1)) |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
243 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
244 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
245 getbits(buffer, n, 1); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
246 n++; |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
247 n = read_timeinc(picture, buffer, n); |
92553e3c8f01
automatic fps calculation for mpeg4 in raw stream/mpeg-ts
nicodvb
parents:
12755
diff
changeset
|
248 } |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
249 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
250 #define min(a, b) ((a) <= (b) ? (a) : (b)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
251 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
252 static unsigned int read_golomb(unsigned char *buffer, unsigned int *init) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
253 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
254 unsigned int x, v = 0, v2 = 0, m, len = 0, n = *init; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
255 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
256 while(getbits(buffer, n++, 1) == 0) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
257 len++; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
258 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
259 x = len + n; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
260 while(n < x) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
261 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
262 m = min(x - n, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
263 v |= getbits(buffer, n, m); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
264 n += m; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
265 if(x - n > 8) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
266 v <<= 8; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
267 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
268 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
269 v2 = 1; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
270 for(n = 0; n < len; n++) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
271 v2 <<= 1; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
272 v2 = (v2 - 1) + v; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
273 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
274 //fprintf(stderr, "READ_GOLOMB(%u), V=2^%u + %u-1 = %u\n", *init, len, v, v2); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
275 *init = x; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
276 return v2; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
277 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
278 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
279 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
280 static int h264_parse_vui(mp_mpeg_header_t * picture, unsigned char * buf, unsigned int n) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
281 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
282 unsigned int overscan, vsp_color, chroma, timing, fixed_fps; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
283 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
284 if(getbits(buf, n++, 1)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
285 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
286 picture->aspect_ratio_information = getbits(buf, n, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
287 n += 8; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
288 if(picture->aspect_ratio_information == 255) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
289 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
290 picture->display_picture_width = (getbits(buf, n, 8) << 8) | getbits(buf, n + 8, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
291 n += 16; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
292 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
293 picture->display_picture_height = (getbits(buf, n, 8) << 8) | getbits(buf, n + 8, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
294 n += 16; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
295 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
296 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
297 |
14887 | 298 if((overscan=getbits(buf, n++, 1))) |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
299 n++; |
14887 | 300 if((vsp_color=getbits(buf, n++, 1))) |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
301 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
302 n += 4; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
303 if(getbits(buf, n++, 1)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
304 n += 24; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
305 } |
14887 | 306 if((chroma=getbits(buf, n++, 1))) |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
307 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
308 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
309 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
310 } |
14887 | 311 if((timing=getbits(buf, n++, 1))) |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
312 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
313 picture->timeinc_unit = (getbits(buf, n, 8) << 24) | (getbits(buf, n+8, 8) << 16) | (getbits(buf, n+16, 8) << 8) | getbits(buf, n+24, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
314 n += 32; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
315 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
316 picture->timeinc_resolution = (getbits(buf, n, 8) << 24) | (getbits(buf, n+8, 8) << 16) | (getbits(buf, n+16, 8) << 8) | getbits(buf, n+24, 8); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
317 n += 32; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
318 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
319 fixed_fps = getbits(buf, n, 1); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
320 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
321 if(picture->timeinc_unit > 0 && picture->timeinc_resolution > 0) |
16319
798d9be2337f
multiplying fps by 10000 is no more necessary (when determining mp4v and h264 framerate)
nicodvb
parents:
16184
diff
changeset
|
322 picture->fps = (float) picture->timeinc_resolution / (float) picture->timeinc_unit; |
17952
7ad7d20cfadc
H264: when fixed_fps is set the framerate is expressed in fields per second, so it must be halved
nicodvb
parents:
16319
diff
changeset
|
323 if(fixed_fps) |
7ad7d20cfadc
H264: when fixed_fps is set the framerate is expressed in fields per second, so it must be halved
nicodvb
parents:
16319
diff
changeset
|
324 picture->fps /= 2; |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
325 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
326 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
327 //fprintf(stderr, "H264_PARSE_VUI, OVESCAN=%u, VSP_COLOR=%u, CHROMA=%u, TIMING=%u, DISPW=%u, DISPH=%u, TIMERES=%u, TIMEINC=%u, FIXED_FPS=%u\n", overscan, vsp_color, chroma, timing, picture->display_picture_width, picture->display_picture_height, |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
328 // picture->timeinc_resolution, picture->timeinc_unit, picture->timeinc_unit, fixed_fps); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
329 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
330 return n; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
331 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
332 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
333 int h264_parse_sps(mp_mpeg_header_t * picture, unsigned char * buf, int len) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
334 { |
15073 | 335 unsigned int n = 0, v, i, j, mbh; |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
336 unsigned char *dest; |
15073 | 337 int frame_mbs_only; |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
338 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
339 dest = (unsigned char*) malloc(len); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
340 if(! dest) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
341 return 0; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
342 j = i = 0; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
343 while(i <= len-3) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
344 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
345 if(buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 3) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
346 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
347 dest[j] = dest[j+1] = 0; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
348 j += 2; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
349 i += 3; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
350 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
351 else |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
352 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
353 dest[j] = buf[i]; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
354 j++; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
355 i++; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
356 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
357 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
358 dest[j] = buf[len-2]; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
359 dest[j+1] = buf[len-1]; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
360 j += 2; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
361 len = j+1; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
362 buf = dest; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
363 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
364 picture->fps = picture->timeinc_unit = picture->timeinc_resolution = 0; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
365 n = 24; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
366 read_golomb(buf, &n); |
15618 | 367 if(buf[0] >= 100){ |
368 if(read_golomb(buf, &n) == 3) | |
369 n++; | |
370 read_golomb(buf, &n); | |
371 read_golomb(buf, &n); | |
372 n++; | |
373 if(getbits(buf, n++, 1)){ | |
374 //FIXME scaling matrix | |
375 } | |
376 } | |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
377 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
378 v = read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
379 if(v == 0) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
380 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
381 else if(v == 1) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
382 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
383 getbits(buf, n++, 1); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
384 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
385 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
386 v = read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
387 for(i = 0; i < v; i++) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
388 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
389 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
390 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
391 getbits(buf, n++, 1); |
15073 | 392 picture->display_picture_width = 16 *(read_golomb(buf, &n)+1); |
393 mbh = read_golomb(buf, &n)+1; | |
394 frame_mbs_only = getbits(buf, n++, 1); | |
395 picture->display_picture_height = 16 * (2 - frame_mbs_only) * mbh; | |
396 if(!frame_mbs_only) | |
14798
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
397 getbits(buf, n++, 1); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
398 getbits(buf, n++, 1); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
399 if(getbits(buf, n++, 1)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
400 { |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
401 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
402 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
403 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
404 read_golomb(buf, &n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
405 } |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
406 if(getbits(buf, n++, 1)) |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
407 n = h264_parse_vui(picture, buf, n); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
408 |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
409 free(dest); |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
410 return n; |
0bd50330e688
framerate autodetection for H264 in raw/ts streams
nicodvb
parents:
14477
diff
changeset
|
411 } |