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