Mercurial > mplayer.hg
annotate libmpdemux/video.c @ 3714:03585432814d
similar to 1.143, 'sis' bug was fixed
author | jaf |
---|---|
date | Mon, 24 Dec 2001 14:58:42 +0000 |
parents | 70c409621d92 |
children | 1acf2f1f9dc8 |
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> |
10 #include <unistd.h> | |
11 | |
12 #include "mp_msg.h" | |
13 #include "help_mp.h" | |
14 | |
15 #include "stream.h" | |
16 #include "demuxer.h" | |
17 #include "stheader.h" | |
18 #include "parse_es.h" | |
19 #include "mpeg_hdr.h" | |
20 | |
21 static mp_mpeg_header_t picture; | |
22 | |
23 int video_read_properties(sh_video_t *sh_video){ | |
24 demux_stream_t *d_video=sh_video->ds; | |
25 | |
26 // Determine image properties: | |
27 switch(d_video->demuxer->file_format){ | |
28 case DEMUXER_TYPE_AVI: | |
29 case DEMUXER_TYPE_ASF: { | |
30 // display info: | |
31 sh_video->format=sh_video->bih->biCompression; | |
32 sh_video->disp_w=sh_video->bih->biWidth; | |
33 sh_video->disp_h=abs(sh_video->bih->biHeight); | |
34 break; | |
35 } | |
36 case DEMUXER_TYPE_MPEG_ES: | |
37 case DEMUXER_TYPE_MPEG_PS: { | |
38 // Find sequence_header first: | |
39 videobuf_len=0; videobuf_code_len=0; | |
40 mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for sequence header... ");fflush(stdout); | |
41 while(1){ | |
42 int i=sync_video_packet(d_video); | |
43 if(i==0x1B3) break; // found it! | |
44 if(!i || !skip_video_packet(d_video)){ | |
45 if(verbose) mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n"); | |
46 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MpegNoSequHdr); | |
47 return 0; | |
48 } | |
49 } | |
50 mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n"); | |
51 // sh_video=d_video->sh;sh_video->ds=d_video; | |
52 // mpeg2_init(); | |
53 // ========= Read & process sequence header & extension ============ | |
54 if(!videobuffer) videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE); | |
55 if(!videobuffer){ | |
56 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail); | |
57 return 0; | |
58 } | |
59 | |
60 if(!read_video_packet(d_video)){ | |
61 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CannotReadMpegSequHdr); | |
62 return 0; | |
63 } | |
64 if(mp_header_process_sequence_header (&picture, &videobuffer[4])) { | |
65 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_BadMpegSequHdr); | |
66 return 0; | |
67 } | |
68 if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext. | |
69 // videobuf_len=0; | |
70 int pos=videobuf_len; | |
71 if(!read_video_packet(d_video)){ | |
72 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_CannotReadMpegSequHdrEx); | |
73 return 0; | |
74 } | |
75 if(mp_header_process_extension (&picture, &videobuffer[pos+4])) { | |
76 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_BadMpegSequHdrEx); | |
77 return 0; | |
78 } | |
79 } | |
80 | |
81 // printf("picture.fps=%d\n",picture.fps); | |
82 | |
83 // fill aspect info: | |
84 switch(picture.aspect_ratio_information){ | |
85 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
|
86 case 4: // SECAM 4:3? - XXX check with more files! |
2567 | 87 case 8: // PAL VCD 4:3 |
88 case 12: // NTSC VCD 4:3 | |
89 sh_video->aspect=4.0/3.0; | |
90 break; | |
91 case 3: // PAL/NTSC Widescreen SVCD/DVD 16:9 | |
3666 | 92 case 6: // (PAL?)/NTSC Widescreen SVCD 16:9 |
2567 | 93 sh_video->aspect=16.0/9.0; |
94 break; | |
95 default: | |
96 fprintf(stderr,"Detected unknown aspect_ratio_information in mpeg sequence header.\n" | |
97 "Please report the aspect value (%i) along with the movie type (VGA,PAL,NTSC," | |
98 "SECAM) and the movie resolution (720x576,352x240,480x480,...) to the MPlayer" | |
99 " developers, so that we can add support for it!\nAssuming 1:1 aspect for now.\n", | |
100 picture.aspect_ratio_information); | |
101 case 1: // VGA 1:1 - do not prescale | |
102 sh_video->aspect=0.0; | |
103 break; | |
104 } | |
105 // display info: | |
106 sh_video->format=picture.mpeg1?0x10000001:0x10000002; // mpeg video | |
107 sh_video->fps=picture.fps*0.0001f; | |
108 if(!sh_video->fps){ | |
109 // if(!force_fps){ | |
110 // fprintf(stderr,"FPS not specified (or invalid) in the header! Use the -fps option!\n"); | |
111 // return 0; | |
112 // } | |
113 sh_video->frametime=0; | |
114 } else { | |
115 sh_video->frametime=10000.0f/(float)picture.fps; | |
116 } | |
117 sh_video->disp_w=picture.display_picture_width; | |
118 sh_video->disp_h=picture.display_picture_height; | |
119 // bitrate: | |
120 if(picture.bitrate!=0x3FFFF) // unspecified/VBR ? | |
121 sh_video->i_bps=1000*picture.bitrate/16; | |
122 // info: | |
123 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"mpeg bitrate: %d (%X)\n",picture.bitrate,picture.bitrate); | |
124 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", | |
125 picture.mpeg1?"MPEG1":"MPEG2", | |
126 sh_video->disp_w,sh_video->disp_h, | |
127 picture.aspect_ratio_information, | |
128 sh_video->fps, | |
129 picture.bitrate*0.5f, | |
130 picture.bitrate/16.0f ); | |
131 break; | |
132 } | |
133 } // switch(file_format) | |
134 | |
135 return 1; | |
136 } | |
137 | |
138 int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** start,int force_fps){ | |
139 demux_stream_t *d_video=sh_video->ds; | |
140 demuxer_t *demuxer=d_video->demuxer; | |
141 float frame_time=1; | |
142 float pts1=d_video->pts; | |
143 // unsigned char* start=NULL; | |
144 int in_size=0; | |
145 | |
146 *start=NULL; | |
147 | |
148 if(demuxer->file_format==DEMUXER_TYPE_MPEG_ES || demuxer->file_format==DEMUXER_TYPE_MPEG_PS){ | |
149 int in_frame=0; | |
150 //float newfps; | |
151 //videobuf_len=0; | |
152 while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){ | |
153 int i=sync_video_packet(d_video); | |
154 void* buffer=&videobuffer[videobuf_len+4]; | |
155 if(in_frame){ | |
156 if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame | |
157 #if 1 | |
158 // send END OF FRAME code: | |
159 videobuffer[videobuf_len+0]=0; | |
160 videobuffer[videobuf_len+1]=0; | |
161 videobuffer[videobuf_len+2]=1; | |
162 videobuffer[videobuf_len+3]=0xFF; | |
163 videobuf_len+=4; | |
164 #endif | |
165 if(!i) return -1; // EOF | |
166 break; | |
167 } | |
168 } else { | |
169 //if(i==0x100) in_frame=1; // picture startcode | |
170 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode | |
171 else if(!i) return -1; // EOF | |
172 } | |
173 //if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1; | |
174 if(!read_video_packet(d_video)) return -1; // EOF | |
175 //printf("read packet 0x%X, len=%d\n",i,videobuf_len); | |
176 // process headers: | |
177 switch(i){ | |
178 case 0x1B3: mp_header_process_sequence_header (&picture, buffer);break; | |
179 case 0x1B5: mp_header_process_extension (&picture, buffer);break; | |
180 } | |
181 } | |
182 | |
183 // if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug | |
184 //printf("--- SEND %d bytes\n",videobuf_len); | |
185 // if(grab_frames==1){ | |
186 // FILE *f=fopen("grab.mpg","ab"); | |
187 // fwrite(videobuffer,videobuf_len-4,1,f); | |
188 // fclose(f); | |
189 // } | |
190 | |
191 *start=videobuffer; in_size=videobuf_len; | |
192 //blit_frame=decode_video(video_out,sh_video,videobuffer,videobuf_len,drop_frame); | |
193 | |
194 #if 1 | |
195 // get mpeg fps: | |
196 //newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; | |
197 if((int)(sh_video->fps*10000+0.5)!=picture.fps) if(!force_fps){ | |
198 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); | |
199 sh_video->fps=picture.fps*0.0001; | |
200 sh_video->frametime=10000.0f/(float)picture.fps; | |
201 } | |
202 #endif | |
203 | |
204 // fix mpeg2 frametime: | |
205 frame_time=(picture.display_time)*0.01f; | |
206 picture.display_time=100; | |
207 videobuf_len=0; | |
208 | |
209 } else { | |
210 // frame-based file formats: (AVI,ASF,MOV) | |
211 in_size=ds_get_packet(d_video,start); | |
212 if(in_size<0) return -1; // EOF | |
213 // if(in_size>max_framesize) max_framesize=in_size; | |
214 // blit_frame=decode_video(video_out,sh_video,start,in_size,drop_frame); | |
215 } | |
216 | |
217 // vdecode_time=video_time_usage-vdecode_time; | |
218 | |
219 //------------------------ frame decoded. -------------------- | |
220 | |
221 // Increase video timers: | |
222 sh_video->num_frames+=frame_time; | |
223 ++sh_video->num_frames_decoded; | |
224 | |
225 frame_time*=sh_video->frametime; | |
226 if(demuxer->file_format==DEMUXER_TYPE_ASF && !force_fps){ | |
227 // .ASF files has no fixed FPS - just frame durations! | |
228 float d=d_video->pts-pts1; | |
229 if(d>=0 && d<5) frame_time=d; | |
230 if(d>0){ | |
231 if(verbose) | |
232 if((int)sh_video->fps==1000) | |
233 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"\rASF framerate: %d fps \n",(int)(1.0f/d)); | |
234 sh_video->frametime=d; // 1ms | |
235 sh_video->fps=1.0f/d; | |
236 } | |
237 } else | |
238 if(demuxer->file_format==DEMUXER_TYPE_MOV && !force_fps){ | |
239 // .MOV files has no fixed FPS - just frame durations! | |
240 frame_time=d_video->pts-pts1; | |
3526 | 241 } else |
242 if(demuxer->file_format==DEMUXER_TYPE_VIVO && !force_fps){ | |
243 // .VIVO files has no fixed FPS - just frame durations! | |
244 if(d_video->pts-pts1>0) | |
245 frame_time=d_video->pts-pts1; | |
246 mp_msg(MSGT_CPLAYER,MSGL_V,"vivo frame_time=%5.3f \n",frame_time); | |
2567 | 247 } |
248 | |
249 if(demuxer->file_format==DEMUXER_TYPE_MPEG_PS) d_video->pts+=frame_time; | |
250 | |
251 if(frame_time_ptr) *frame_time_ptr=frame_time; | |
252 return in_size; | |
253 | |
254 } | |
255 | |
256 |