Mercurial > mplayer.hg
annotate libmpdemux/video.c @ 4294:21dbbbbd5479
a few filters (should be removed/merged when arpis videofilter stuff is finished)
-ssf cgb=<float> -> chrominance gaussian blur (nice to improve picture quality)
-ssf lgb=<float> -> luminance gaussian blur (dunno what its good for)
-ssf chs=<int> -> shift chrominance horizontally
-ssf cvs=<int> -> shift chrominance vertically
these will only work if the swscaler is used at all
author | michael |
---|---|
date | Mon, 21 Jan 2002 15:22:28 +0000 |
parents | aca490499e1f |
children | 71fa805e84d6 |
rev | line source |
---|---|
2567 | 1 // read video frame |
2 | |
2775 | 3 #include "config.h" |
4 | |
2567 | 5 #include <stdio.h> |
2775 | 6 #ifdef HAVE_MALLOC_H |
7 #include <malloc.h> | |
8 #endif | |
2567 | 9 #include <stdlib.h> |
3726 | 10 #include <string.h> |
2567 | 11 #include <unistd.h> |
12 | |
13 #include "mp_msg.h" | |
14 #include "help_mp.h" | |
15 | |
16 #include "stream.h" | |
17 #include "demuxer.h" | |
18 #include "stheader.h" | |
19 #include "parse_es.h" | |
20 #include "mpeg_hdr.h" | |
21 | |
22 static mp_mpeg_header_t picture; | |
23 | |
24 int video_read_properties(sh_video_t *sh_video){ | |
25 demux_stream_t *d_video=sh_video->ds; | |
26 | |
27 // Determine image properties: | |
28 switch(d_video->demuxer->file_format){ | |
29 case DEMUXER_TYPE_AVI: | |
30 case DEMUXER_TYPE_ASF: { | |
31 // display info: | |
32 sh_video->format=sh_video->bih->biCompression; | |
33 sh_video->disp_w=sh_video->bih->biWidth; | |
34 sh_video->disp_h=abs(sh_video->bih->biHeight); | |
3980
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
35 |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
36 #if 1 |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
37 /* hack to support decoding of mpeg1 chunks in AVI's with libmpeg2 -- 2002 alex */ |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
38 if ((sh_video->format == 0x10000001) || |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
39 (sh_video->format == 0x10000002) || |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
40 (sh_video->format == mmioFOURCC('m','p','g','1')) || |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
41 (sh_video->format == mmioFOURCC('M','P','G','1')) || |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
42 (sh_video->format == mmioFOURCC('m','p','g','2')) || |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
43 (sh_video->format == mmioFOURCC('M','P','G','2')) || |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
44 (sh_video->format == mmioFOURCC('m','p','e','g')) || |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
45 (sh_video->format == mmioFOURCC('m','p','e','g'))) |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
46 { |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
47 int saved_pos, saved_type; |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
48 |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
49 /* demuxer pos saving is required for libavcodec mpeg decoder as it's |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
50 reading the mpeg header self! */ |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
51 |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
52 saved_pos = d_video->buffer_pos; |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
53 saved_type = d_video->demuxer->file_format; |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
54 |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
55 d_video->demuxer->file_format = DEMUXER_TYPE_MPEG_ES; |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
56 video_read_properties(sh_video); |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
57 d_video->demuxer->file_format = saved_type; |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
58 d_video->buffer_pos = saved_pos; |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
59 // goto mpeg_header_parser; |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
60 } |
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
61 #endif |
2567 | 62 break; |
63 } | |
64 case DEMUXER_TYPE_MPEG_ES: | |
65 case DEMUXER_TYPE_MPEG_PS: { | |
3980
cdd55ab40363
libmpeg2 is now able to decode framecopied (with mencoder) mpeg files
alex
parents:
3726
diff
changeset
|
66 //mpeg_header_parser: |
2567 | 67 // Find sequence_header first: |
68 videobuf_len=0; videobuf_code_len=0; | |
69 mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for sequence header... ");fflush(stdout); | |
70 while(1){ | |
71 int i=sync_video_packet(d_video); | |
72 if(i==0x1B3) break; // found it! | |
73 if(!i || !skip_video_packet(d_video)){ | |
74 if(verbose) mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n"); | |
75 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MpegNoSequHdr); | |
76 return 0; | |
77 } | |
78 } | |
79 mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n"); | |
80 // sh_video=d_video->sh;sh_video->ds=d_video; | |
81 // mpeg2_init(); | |
82 // ========= Read & process sequence header & extension ============ | |
83 if(!videobuffer) videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE); | |
84 if(!videobuffer){ | |
85 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail); | |
86 return 0; | |
87 } | |
88 | |
89 if(!read_video_packet(d_video)){ | |
90 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CannotReadMpegSequHdr); | |
91 return 0; | |
92 } | |
93 if(mp_header_process_sequence_header (&picture, &videobuffer[4])) { | |
94 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_BadMpegSequHdr); | |
95 return 0; | |
96 } | |
97 if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext. | |
98 // videobuf_len=0; | |
99 int pos=videobuf_len; | |
100 if(!read_video_packet(d_video)){ | |
101 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CannotReadMpegSequHdrEx); | |
102 return 0; | |
103 } | |
104 if(mp_header_process_extension (&picture, &videobuffer[pos+4])) { | |
105 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_BadMpegSequHdrEx); | |
106 return 0; | |
107 } | |
108 } | |
109 | |
110 // printf("picture.fps=%d\n",picture.fps); | |
111 | |
112 // fill aspect info: | |
113 switch(picture.aspect_ratio_information){ | |
114 case 2: // PAL/NTSC SVCD/DVD 4:3 | |
3379
84ed0593187c
Add aspect 4 to known aspect codes, probably SECAM 4:3, at least sample file was 4:3.
atmos4
parents:
2775
diff
changeset
|
115 case 4: // SECAM 4:3? - XXX check with more files! |
2567 | 116 case 8: // PAL VCD 4:3 |
117 case 12: // NTSC VCD 4:3 | |
118 sh_video->aspect=4.0/3.0; | |
119 break; | |
120 case 3: // PAL/NTSC Widescreen SVCD/DVD 16:9 | |
3666 | 121 case 6: // (PAL?)/NTSC Widescreen SVCD 16:9 |
2567 | 122 sh_video->aspect=16.0/9.0; |
123 break; | |
124 default: | |
125 fprintf(stderr,"Detected unknown aspect_ratio_information in mpeg sequence header.\n" | |
126 "Please report the aspect value (%i) along with the movie type (VGA,PAL,NTSC," | |
127 "SECAM) and the movie resolution (720x576,352x240,480x480,...) to the MPlayer" | |
128 " developers, so that we can add support for it!\nAssuming 1:1 aspect for now.\n", | |
129 picture.aspect_ratio_information); | |
130 case 1: // VGA 1:1 - do not prescale | |
131 sh_video->aspect=0.0; | |
132 break; | |
133 } | |
134 // display info: | |
135 sh_video->format=picture.mpeg1?0x10000001:0x10000002; // mpeg video | |
136 sh_video->fps=picture.fps*0.0001f; | |
137 if(!sh_video->fps){ | |
138 // if(!force_fps){ | |
139 // fprintf(stderr,"FPS not specified (or invalid) in the header! Use the -fps option!\n"); | |
140 // return 0; | |
141 // } | |
142 sh_video->frametime=0; | |
143 } else { | |
144 sh_video->frametime=10000.0f/(float)picture.fps; | |
145 } | |
146 sh_video->disp_w=picture.display_picture_width; | |
147 sh_video->disp_h=picture.display_picture_height; | |
148 // bitrate: | |
149 if(picture.bitrate!=0x3FFFF) // unspecified/VBR ? | |
150 sh_video->i_bps=1000*picture.bitrate/16; | |
151 // info: | |
152 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"mpeg bitrate: %d (%X)\n",picture.bitrate,picture.bitrate); | |
153 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", | |
154 picture.mpeg1?"MPEG1":"MPEG2", | |
155 sh_video->disp_w,sh_video->disp_h, | |
156 picture.aspect_ratio_information, | |
157 sh_video->fps, | |
158 picture.bitrate*0.5f, | |
159 picture.bitrate/16.0f ); | |
160 break; | |
161 } | |
162 } // switch(file_format) | |
163 | |
164 return 1; | |
165 } | |
166 | |
4074 | 167 static void process_userdata(unsigned char* buf,int len){ |
168 int i; | |
169 printf( "user_data: len=%3d %02X %02X %02X %02X '", | |
170 len, buf[0], buf[1], buf[2], buf[3]); | |
171 for(i=0;i<len;i++) | |
172 if(buf[i]>=32 && buf[i]<127) putchar(buf[i]); | |
173 printf("'\n"); | |
174 } | |
175 | |
2567 | 176 int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** start,int force_fps){ |
177 demux_stream_t *d_video=sh_video->ds; | |
178 demuxer_t *demuxer=d_video->demuxer; | |
179 float frame_time=1; | |
180 float pts1=d_video->pts; | |
181 // unsigned char* start=NULL; | |
182 int in_size=0; | |
183 | |
184 *start=NULL; | |
185 | |
186 if(demuxer->file_format==DEMUXER_TYPE_MPEG_ES || demuxer->file_format==DEMUXER_TYPE_MPEG_PS){ | |
187 int in_frame=0; | |
188 //float newfps; | |
189 //videobuf_len=0; | |
190 while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){ | |
191 int i=sync_video_packet(d_video); | |
4074 | 192 //void* buffer=&videobuffer[videobuf_len+4]; |
193 int start=videobuf_len+4; | |
2567 | 194 if(in_frame){ |
195 if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame | |
196 #if 1 | |
197 // send END OF FRAME code: | |
198 videobuffer[videobuf_len+0]=0; | |
199 videobuffer[videobuf_len+1]=0; | |
200 videobuffer[videobuf_len+2]=1; | |
201 videobuffer[videobuf_len+3]=0xFF; | |
202 videobuf_len+=4; | |
203 #endif | |
204 if(!i) return -1; // EOF | |
205 break; | |
206 } | |
207 } else { | |
208 //if(i==0x100) in_frame=1; // picture startcode | |
209 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode | |
210 else if(!i) return -1; // EOF | |
211 } | |
212 //if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1; | |
213 if(!read_video_packet(d_video)) return -1; // EOF | |
214 //printf("read packet 0x%X, len=%d\n",i,videobuf_len); | |
215 // process headers: | |
216 switch(i){ | |
4074 | 217 case 0x1B3: mp_header_process_sequence_header (&picture, &videobuffer[start]);break; |
218 case 0x1B5: mp_header_process_extension (&picture, &videobuffer[start]);break; | |
219 case 0x1B2: if(verbose) process_userdata (&videobuffer[start], videobuf_len-start);break; | |
2567 | 220 } |
221 } | |
222 | |
223 // if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug | |
224 //printf("--- SEND %d bytes\n",videobuf_len); | |
225 // if(grab_frames==1){ | |
226 // FILE *f=fopen("grab.mpg","ab"); | |
227 // fwrite(videobuffer,videobuf_len-4,1,f); | |
228 // fclose(f); | |
229 // } | |
230 | |
231 *start=videobuffer; in_size=videobuf_len; | |
232 //blit_frame=decode_video(video_out,sh_video,videobuffer,videobuf_len,drop_frame); | |
233 | |
234 #if 1 | |
235 // get mpeg fps: | |
236 //newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; | |
237 if((int)(sh_video->fps*10000+0.5)!=picture.fps) if(!force_fps){ | |
238 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video->fps,picture.fps*0.0001,sh_video->fps-picture.fps*0.0001,picture.frame_rate_code); | |
239 sh_video->fps=picture.fps*0.0001; | |
240 sh_video->frametime=10000.0f/(float)picture.fps; | |
241 } | |
242 #endif | |
243 | |
244 // fix mpeg2 frametime: | |
245 frame_time=(picture.display_time)*0.01f; | |
246 picture.display_time=100; | |
247 videobuf_len=0; | |
248 | |
249 } else { | |
250 // frame-based file formats: (AVI,ASF,MOV) | |
251 in_size=ds_get_packet(d_video,start); | |
252 if(in_size<0) return -1; // EOF | |
253 // if(in_size>max_framesize) max_framesize=in_size; | |
254 // blit_frame=decode_video(video_out,sh_video,start,in_size,drop_frame); | |
255 } | |
256 | |
257 // vdecode_time=video_time_usage-vdecode_time; | |
258 | |
259 //------------------------ frame decoded. -------------------- | |
260 | |
261 // Increase video timers: | |
262 sh_video->num_frames+=frame_time; | |
263 ++sh_video->num_frames_decoded; | |
264 | |
265 frame_time*=sh_video->frametime; | |
266 if(demuxer->file_format==DEMUXER_TYPE_ASF && !force_fps){ | |
267 // .ASF files has no fixed FPS - just frame durations! | |
268 float d=d_video->pts-pts1; | |
269 if(d>=0 && d<5) frame_time=d; | |
270 if(d>0){ | |
271 if(verbose) | |
272 if((int)sh_video->fps==1000) | |
273 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"\rASF framerate: %d fps \n",(int)(1.0f/d)); | |
274 sh_video->frametime=d; // 1ms | |
275 sh_video->fps=1.0f/d; | |
276 } | |
277 } else | |
278 if(demuxer->file_format==DEMUXER_TYPE_MOV && !force_fps){ | |
279 // .MOV files has no fixed FPS - just frame durations! | |
280 frame_time=d_video->pts-pts1; | |
3526 | 281 } else |
282 if(demuxer->file_format==DEMUXER_TYPE_VIVO && !force_fps){ | |
283 // .VIVO files has no fixed FPS - just frame durations! | |
284 if(d_video->pts-pts1>0) | |
285 frame_time=d_video->pts-pts1; | |
286 mp_msg(MSGT_CPLAYER,MSGL_V,"vivo frame_time=%5.3f \n",frame_time); | |
2567 | 287 } |
288 | |
289 if(demuxer->file_format==DEMUXER_TYPE_MPEG_PS) d_video->pts+=frame_time; | |
290 | |
291 if(frame_time_ptr) *frame_time_ptr=frame_time; | |
292 return in_size; | |
293 | |
294 } | |
295 | |
296 |