Mercurial > mplayer.hg
annotate libmpdemux/video.c @ 3410:3eb15016e454
still fiddling with surround levels
author | steve |
---|---|
date | Sun, 09 Dec 2001 18:54:54 +0000 |
parents | 84ed0593187c |
children | cf787373f0aa |
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 | |
92 sh_video->aspect=16.0/9.0; | |
93 break; | |
94 default: | |
95 fprintf(stderr,"Detected unknown aspect_ratio_information in mpeg sequence header.\n" | |
96 "Please report the aspect value (%i) along with the movie type (VGA,PAL,NTSC," | |
97 "SECAM) and the movie resolution (720x576,352x240,480x480,...) to the MPlayer" | |
98 " developers, so that we can add support for it!\nAssuming 1:1 aspect for now.\n", | |
99 picture.aspect_ratio_information); | |
100 case 1: // VGA 1:1 - do not prescale | |
101 sh_video->aspect=0.0; | |
102 break; | |
103 } | |
104 // display info: | |
105 sh_video->format=picture.mpeg1?0x10000001:0x10000002; // mpeg video | |
106 sh_video->fps=picture.fps*0.0001f; | |
107 if(!sh_video->fps){ | |
108 // if(!force_fps){ | |
109 // fprintf(stderr,"FPS not specified (or invalid) in the header! Use the -fps option!\n"); | |
110 // return 0; | |
111 // } | |
112 sh_video->frametime=0; | |
113 } else { | |
114 sh_video->frametime=10000.0f/(float)picture.fps; | |
115 } | |
116 sh_video->disp_w=picture.display_picture_width; | |
117 sh_video->disp_h=picture.display_picture_height; | |
118 // bitrate: | |
119 if(picture.bitrate!=0x3FFFF) // unspecified/VBR ? | |
120 sh_video->i_bps=1000*picture.bitrate/16; | |
121 // info: | |
122 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"mpeg bitrate: %d (%X)\n",picture.bitrate,picture.bitrate); | |
123 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", | |
124 picture.mpeg1?"MPEG1":"MPEG2", | |
125 sh_video->disp_w,sh_video->disp_h, | |
126 picture.aspect_ratio_information, | |
127 sh_video->fps, | |
128 picture.bitrate*0.5f, | |
129 picture.bitrate/16.0f ); | |
130 break; | |
131 } | |
132 } // switch(file_format) | |
133 | |
134 return 1; | |
135 } | |
136 | |
137 int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** start,int force_fps){ | |
138 demux_stream_t *d_video=sh_video->ds; | |
139 demuxer_t *demuxer=d_video->demuxer; | |
140 float frame_time=1; | |
141 float pts1=d_video->pts; | |
142 // unsigned char* start=NULL; | |
143 int in_size=0; | |
144 | |
145 *start=NULL; | |
146 | |
147 if(demuxer->file_format==DEMUXER_TYPE_MPEG_ES || demuxer->file_format==DEMUXER_TYPE_MPEG_PS){ | |
148 int in_frame=0; | |
149 //float newfps; | |
150 //videobuf_len=0; | |
151 while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){ | |
152 int i=sync_video_packet(d_video); | |
153 void* buffer=&videobuffer[videobuf_len+4]; | |
154 if(in_frame){ | |
155 if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame | |
156 #if 1 | |
157 // send END OF FRAME code: | |
158 videobuffer[videobuf_len+0]=0; | |
159 videobuffer[videobuf_len+1]=0; | |
160 videobuffer[videobuf_len+2]=1; | |
161 videobuffer[videobuf_len+3]=0xFF; | |
162 videobuf_len+=4; | |
163 #endif | |
164 if(!i) return -1; // EOF | |
165 break; | |
166 } | |
167 } else { | |
168 //if(i==0x100) in_frame=1; // picture startcode | |
169 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode | |
170 else if(!i) return -1; // EOF | |
171 } | |
172 //if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1; | |
173 if(!read_video_packet(d_video)) return -1; // EOF | |
174 //printf("read packet 0x%X, len=%d\n",i,videobuf_len); | |
175 // process headers: | |
176 switch(i){ | |
177 case 0x1B3: mp_header_process_sequence_header (&picture, buffer);break; | |
178 case 0x1B5: mp_header_process_extension (&picture, buffer);break; | |
179 } | |
180 } | |
181 | |
182 // if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug | |
183 //printf("--- SEND %d bytes\n",videobuf_len); | |
184 // if(grab_frames==1){ | |
185 // FILE *f=fopen("grab.mpg","ab"); | |
186 // fwrite(videobuffer,videobuf_len-4,1,f); | |
187 // fclose(f); | |
188 // } | |
189 | |
190 *start=videobuffer; in_size=videobuf_len; | |
191 //blit_frame=decode_video(video_out,sh_video,videobuffer,videobuf_len,drop_frame); | |
192 | |
193 #if 1 | |
194 // get mpeg fps: | |
195 //newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; | |
196 if((int)(sh_video->fps*10000+0.5)!=picture.fps) if(!force_fps){ | |
197 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); | |
198 sh_video->fps=picture.fps*0.0001; | |
199 sh_video->frametime=10000.0f/(float)picture.fps; | |
200 } | |
201 #endif | |
202 | |
203 // fix mpeg2 frametime: | |
204 frame_time=(picture.display_time)*0.01f; | |
205 picture.display_time=100; | |
206 videobuf_len=0; | |
207 | |
208 } else { | |
209 // frame-based file formats: (AVI,ASF,MOV) | |
210 in_size=ds_get_packet(d_video,start); | |
211 if(in_size<0) return -1; // EOF | |
212 // if(in_size>max_framesize) max_framesize=in_size; | |
213 // blit_frame=decode_video(video_out,sh_video,start,in_size,drop_frame); | |
214 } | |
215 | |
216 // vdecode_time=video_time_usage-vdecode_time; | |
217 | |
218 //------------------------ frame decoded. -------------------- | |
219 | |
220 // Increase video timers: | |
221 sh_video->num_frames+=frame_time; | |
222 ++sh_video->num_frames_decoded; | |
223 | |
224 frame_time*=sh_video->frametime; | |
225 if(demuxer->file_format==DEMUXER_TYPE_ASF && !force_fps){ | |
226 // .ASF files has no fixed FPS - just frame durations! | |
227 float d=d_video->pts-pts1; | |
228 if(d>=0 && d<5) frame_time=d; | |
229 if(d>0){ | |
230 if(verbose) | |
231 if((int)sh_video->fps==1000) | |
232 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"\rASF framerate: %d fps \n",(int)(1.0f/d)); | |
233 sh_video->frametime=d; // 1ms | |
234 sh_video->fps=1.0f/d; | |
235 } | |
236 } else | |
237 if(demuxer->file_format==DEMUXER_TYPE_MOV && !force_fps){ | |
238 // .MOV files has no fixed FPS - just frame durations! | |
239 frame_time=d_video->pts-pts1; | |
240 } | |
241 | |
242 if(demuxer->file_format==DEMUXER_TYPE_MPEG_PS) d_video->pts+=frame_time; | |
243 | |
244 if(frame_time_ptr) *frame_time_ptr=frame_time; | |
245 return in_size; | |
246 | |
247 } | |
248 | |
249 |