4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #include "stream/stream.h"
40 /* sub_cc (closed captions)*/
43 /* biCompression constant */
47 #include "demux_rtp.h"
50 static mp_mpeg_header_t picture
;
52 static int telecine
=0;
53 static float telecine_cnt
=-2.5;
63 static video_codec_t
find_video_codec(sh_video_t
*sh_video
)
65 demux_stream_t
*d_video
=sh_video
->ds
;
66 int fmt
= d_video
->demuxer
->file_format
;
69 (fmt
== DEMUXER_TYPE_PVA
) ||
70 (fmt
== DEMUXER_TYPE_MPEG_ES
) ||
71 (fmt
== DEMUXER_TYPE_MPEG_GXF
) ||
72 (fmt
== DEMUXER_TYPE_MPEG_PES
) ||
74 (fmt
== DEMUXER_TYPE_MPEG_PS
|| fmt
== DEMUXER_TYPE_MPEG_TS
) &&
75 ((! sh_video
->format
) || (sh_video
->format
==0x10000001) || (sh_video
->format
==0x10000002))
77 (fmt
== DEMUXER_TYPE_MPEG_TY
)
79 || ((fmt
== DEMUXER_TYPE_RTP
) && demux_is_mpeg_rtp_stream(d_video
->demuxer
))
83 else if((fmt
== DEMUXER_TYPE_MPEG4_ES
) ||
84 ((fmt
== DEMUXER_TYPE_MPEG_TS
) && (sh_video
->format
==0x10000004)) ||
85 ((fmt
== DEMUXER_TYPE_MPEG_PS
) && (sh_video
->format
==0x10000004))
88 else if((fmt
== DEMUXER_TYPE_H264_ES
) ||
89 ((fmt
== DEMUXER_TYPE_MPEG_TS
) && (sh_video
->format
==0x10000005)) ||
90 ((fmt
== DEMUXER_TYPE_MPEG_PS
) && (sh_video
->format
==0x10000005))
93 else if((fmt
== DEMUXER_TYPE_MPEG_PS
|| fmt
== DEMUXER_TYPE_MPEG_TS
) &&
94 (sh_video
->format
==mmioFOURCC('W', 'V', 'C', '1')))
96 else if (fmt
== DEMUXER_TYPE_ASF
&& sh_video
->bih
&& sh_video
->bih
->biCompression
== mmioFOURCC('D', 'V', 'R', ' '))
102 int video_read_properties(sh_video_t
*sh_video
){
103 demux_stream_t
*d_video
=sh_video
->ds
;
104 video_codec_t video_codec
= find_video_codec(sh_video
);
105 // Determine image properties:
108 if((d_video
->demuxer
->file_format
== DEMUXER_TYPE_ASF
) || (d_video
->demuxer
->file_format
== DEMUXER_TYPE_AVI
)) {
110 // in case no strf chunk has been seen in avi, we have no bitmap header
111 if(!sh_video
->bih
) return 0;
112 sh_video
->format
=sh_video
->bih
->biCompression
;
113 sh_video
->disp_w
=sh_video
->bih
->biWidth
;
114 sh_video
->disp_h
=abs(sh_video
->bih
->biHeight
);
119 int pos
= 0, vop_cnt
=0, units
[3];
120 videobuf_len
=0; videobuf_code_len
=0;
121 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for Video Object Start code... ");
123 int i
=sync_video_packet(d_video
);
124 if(i
<=0x11F) break; // found it!
125 if(!i
|| !skip_video_packet(d_video
)){
126 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
130 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
132 videobuffer
=(char*)memalign(8,VIDEOBUFFER_SIZE
+ MP_INPUT_BUFFER_PADDING_SIZE
);
133 if (videobuffer
) memset(videobuffer
+VIDEOBUFFER_SIZE
, 0, MP_INPUT_BUFFER_PADDING_SIZE
);
135 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot allocate shared memory.\n");
139 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for Video Object Layer Start code... ");
141 int i
=sync_video_packet(d_video
);
142 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"M4V: 0x%X\n",i
);
143 if(i
>=0x120 && i
<=0x12F) break; // found it!
144 if(!i
|| !read_video_packet(d_video
)){
145 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
149 pos
= videobuf_len
+4;
150 if(!read_video_packet(d_video
)){
151 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Can't read Video Object Layer Header\n");
154 mp4_header_process_vol(&picture
, &(videobuffer
[pos
]));
155 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK! FPS SEEMS TO BE %.3f\nSearching for Video Object Plane Start code... ", sh_video
->fps
);
158 int i
=sync_video_packet(d_video
);
159 if(i
==0x1B6) break; // found it!
160 if(!i
|| !read_video_packet(d_video
)){
161 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
165 pos
= videobuf_len
+4;
166 if(!read_video_packet(d_video
)){
167 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Can't read Video Object Plane Header\n");
170 mp4_header_process_vop(&picture
, &(videobuffer
[pos
]));
171 units
[vop_cnt
] = picture
.timeinc_unit
;
173 //mp_msg(MSGT_DECVIDEO,MSGL_V, "TYPE: %d, unit: %d\n", picture.picture_type, picture.timeinc_unit);
175 int i
, mn
, md
, mx
, diff
;
189 if((units
[i
] > mn
) && (units
[i
] < mx
))
192 mp_msg(MSGT_DECVIDEO
,MSGL_V
, "MIN: %d, mid: %d, max: %d\n", mn
, md
, mx
);
193 if(mx
- md
> md
- mn
)
198 picture
.fps
= ((float)picture
.timeinc_resolution
) / diff
;
199 mp_msg(MSGT_DECVIDEO
,MSGL_V
, "FPS seems to be: %f, resolution: %d, delta_units: %d\n", picture
.fps
, picture
.timeinc_resolution
, diff
);
203 sh_video
->fps
=picture
.fps
;
204 sh_video
->frametime
=1.0/picture
.fps
;
205 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
, "FPS seems to be: %f\n", picture
.fps
);
207 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
208 sh_video
->format
=0x10000004;
213 videobuf_len
=0; videobuf_code_len
=0;
214 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for sequence parameter set... ");
216 int i
=sync_video_packet(d_video
);
217 if((i
&~0x60) == 0x107 && i
!= 0x107) break; // found it!
218 if(!i
|| !skip_video_packet(d_video
)){
219 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
223 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
225 videobuffer
=(char*)memalign(8,VIDEOBUFFER_SIZE
+ MP_INPUT_BUFFER_PADDING_SIZE
);
226 if (videobuffer
) memset(videobuffer
+VIDEOBUFFER_SIZE
, 0, MP_INPUT_BUFFER_PADDING_SIZE
);
228 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot allocate shared memory.\n");
232 pos
= videobuf_len
+4;
233 if(!read_video_packet(d_video
)){
234 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Can't read sequence parameter set\n");
237 h264_parse_sps(&picture
, &(videobuffer
[pos
]), videobuf_len
- pos
);
238 sh_video
->disp_w
=picture
.display_picture_width
;
239 sh_video
->disp_h
=picture
.display_picture_height
;
240 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for picture parameter set... ");
242 int i
=sync_video_packet(d_video
);
243 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"H264: 0x%X\n",i
);
244 if((i
&~0x60) == 0x108 && i
!= 0x108) break; // found it!
245 if(!i
|| !read_video_packet(d_video
)){
246 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
250 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\nSearching for Slice... ");
252 int i
=sync_video_packet(d_video
);
253 if((i
&~0x60) == 0x101 || (i
&~0x60) == 0x102 || (i
&~0x60) == 0x105) break; // found it!
254 if(!i
|| !read_video_packet(d_video
)){
255 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
259 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
260 sh_video
->format
=0x10000005;
262 sh_video
->fps
=picture
.fps
;
263 sh_video
->frametime
=1.0/picture
.fps
;
264 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
, "FPS seems to be: %f\n", picture
.fps
);
269 if (d_video
->demuxer
->file_format
== DEMUXER_TYPE_ASF
) { // DVR-MS
270 if(!sh_video
->bih
) return 0;
271 sh_video
->format
=sh_video
->bih
->biCompression
;
274 // Find sequence_header first:
275 videobuf_len
=0; videobuf_code_len
=0;
276 telecine
=0; telecine_cnt
=-2.5;
277 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for sequence header... ");
279 int i
=sync_video_packet(d_video
);
280 if(i
==0x1B3) break; // found it!
281 if(!i
|| !skip_video_packet(d_video
)){
282 if( mp_msg_test(MSGT_DECVIDEO
,MSGL_V
) ) mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
283 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"MPEG: FATAL: EOF while searching for sequence header.\n");
287 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
288 // ========= Read & process sequence header & extension ============
290 videobuffer
=(char*)memalign(8,VIDEOBUFFER_SIZE
+ MP_INPUT_BUFFER_PADDING_SIZE
);
291 if (videobuffer
) memset(videobuffer
+VIDEOBUFFER_SIZE
, 0, MP_INPUT_BUFFER_PADDING_SIZE
);
293 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot allocate shared memory.\n");
298 if(!read_video_packet(d_video
)){
299 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"FATAL: Cannot read sequence header.\n");
302 if(mp_header_process_sequence_header (&picture
, &videobuffer
[4])) {
303 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"MPEG: bad sequence header\n");
304 goto mpeg_header_parser
;
306 if(sync_video_packet(d_video
)==0x1B5){ // next packet is seq. ext.
307 int pos
=videobuf_len
;
308 if(!read_video_packet(d_video
)){
309 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"FATAL: Cannot read sequence header extension.\n");
312 if(mp_header_process_extension (&picture
, &videobuffer
[pos
+4])) {
313 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"MPEG: bad sequence header extension\n");
319 sh_video
->format
=picture
.mpeg1
?0x10000001:0x10000002; // mpeg video
320 sh_video
->fps
=picture
.fps
;
322 sh_video
->frametime
=0;
324 sh_video
->frametime
=1.0/picture
.fps
;
326 sh_video
->disp_w
=picture
.display_picture_width
;
327 sh_video
->disp_h
=picture
.display_picture_height
;
329 if(picture
.bitrate
!=0x3FFFF) // unspecified/VBR ?
330 sh_video
->i_bps
=picture
.bitrate
* 400 / 8;
332 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
,"mpeg bitrate: %d (%X)\n",picture
.bitrate
,picture
.bitrate
);
333 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,"VIDEO: %s %dx%d (aspect %d) %5.3f fps %5.1f kbps (%4.1f kbyte/s)\n",
334 picture
.mpeg1
?"MPEG1":"MPEG2",
335 sh_video
->disp_w
,sh_video
->disp_h
,
336 picture
.aspect_ratio_information
,
338 sh_video
->i_bps
* 8 / 1000.0,
339 sh_video
->i_bps
/ 1000.0 );
343 // Find sequence_header:
346 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,"Searching for VC1 sequence header... ");
348 int i
=sync_video_packet(d_video
);
349 if(i
==0x10F) break; // found it!
350 if(!i
|| !skip_video_packet(d_video
)){
351 if( mp_msg_test(MSGT_DECVIDEO
,MSGL_V
) ) mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
352 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
, "Couldn't find VC-1 sequence header\n");
356 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,"found\n");
358 videobuffer
=(char*)memalign(8,VIDEOBUFFER_SIZE
+ MP_INPUT_BUFFER_PADDING_SIZE
);
359 if (videobuffer
) memset(videobuffer
+VIDEOBUFFER_SIZE
, 0, MP_INPUT_BUFFER_PADDING_SIZE
);
361 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot allocate shared memory.\n");
365 if(!read_video_packet(d_video
)){
366 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
, "Couldn't read VC-1 sequence header!\n");
371 int i
=sync_video_packet(d_video
);
372 if(i
==0x10E) break; // found it!
373 if(!i
|| !skip_video_packet(d_video
)){
374 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Couldn't find VC-1 entry point sync-code:(\n");
378 if(!read_video_packet(d_video
)){
379 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Couldn't read VC-1 entry point sync-code:(\n");
383 if(mp_vc1_decode_sequence_header(&picture
, &videobuffer
[4], videobuf_len
-4)) {
384 sh_video
->bih
= (BITMAPINFOHEADER
*) calloc(1, sizeof(BITMAPINFOHEADER
) + videobuf_len
);
385 if(sh_video
->bih
== NULL
) {
386 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Couldn't alloc %d bytes for VC-1 extradata!\n", sizeof(BITMAPINFOHEADER
) + videobuf_len
);
389 sh_video
->bih
->biSize
= sizeof(BITMAPINFOHEADER
) + videobuf_len
;
390 memcpy(sh_video
->bih
+ 1, videobuffer
, videobuf_len
);
391 sh_video
->bih
->biCompression
= sh_video
->format
;
392 sh_video
->bih
->biWidth
= sh_video
->disp_w
= picture
.display_picture_width
;
393 sh_video
->bih
->biHeight
= sh_video
->disp_h
= picture
.display_picture_height
;
394 if(picture
.fps
> 0) {
395 sh_video
->frametime
=1.0/picture
.fps
;
396 sh_video
->fps
= picture
.fps
;
398 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,"VIDEO: VC-1 %dx%d, %5.3f fps, header len: %d\n",
399 sh_video
->disp_w
, sh_video
->disp_h
, sh_video
->fps
, videobuf_len
);
403 } // switch(file_format)
408 void ty_processuserdata( unsigned char* buf
, int len
);
410 static void process_userdata(unsigned char* buf
,int len
){
412 /* if the user data starts with "CC", assume it is a CC info packet */
413 if(len
>2 && buf
[0]=='C' && buf
[1]=='C'){
414 // mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"video.c: process_userdata() detected Closed Captions!\n");
415 subcc_process_data(buf
+2,len
-2);
417 if( len
> 2 && buf
[ 0 ] == 'T' && buf
[ 1 ] == 'Y' )
419 ty_processuserdata( buf
+ 2, len
- 2 );
422 if(verbose
<2) return;
423 fprintf(stderr
, "user_data: len=%3d %02X %02X %02X %02X '",
424 len
, buf
[0], buf
[1], buf
[2], buf
[3]);
426 // if(buf[i]>=32 && buf[i]<127) fputc(buf[i], stderr);
427 if(buf
[i
]&0x60) fputc(buf
[i
]&0x7F, stderr
);
428 fprintf(stderr
, "'\n");
431 int video_read_frame(sh_video_t
* sh_video
,float* frame_time_ptr
,unsigned char** start
,int force_fps
){
432 demux_stream_t
*d_video
=sh_video
->ds
;
433 demuxer_t
*demuxer
=d_video
->demuxer
;
435 float pts1
=d_video
->pts
;
437 int picture_coding_type
=0;
439 video_codec_t video_codec
= find_video_codec(sh_video
);
443 if(video_codec
== VIDEO_MPEG12
){
447 while(videobuf_len
<VIDEOBUFFER_SIZE
-MAX_VIDEO_PACKET_SIZE
){
448 int i
=sync_video_packet(d_video
);
449 //void* buffer=&videobuffer[videobuf_len+4];
450 int start
=videobuf_len
+4;
452 if(i
<0x101 || i
>=0x1B0){ // not slice code -> end of frame
453 if(!i
) return -1; // EOF
461 if(i
>=0x101 && i
<0x1B0) in_frame
=1; // picture startcode
462 else if(!i
) return -1; // EOF
464 if(!read_video_packet(d_video
)) return -1; // EOF
467 case 0x1B3: mp_header_process_sequence_header (&picture
, &videobuffer
[start
]);break;
468 case 0x1B5: mp_header_process_extension (&picture
, &videobuffer
[start
]);break;
469 case 0x1B2: process_userdata (&videobuffer
[start
], videobuf_len
-start
);break;
470 case 0x100: picture_coding_type
=(videobuffer
[start
+1] >> 3) & 7;break;
474 *start
=videobuffer
; in_size
=videobuf_len
;
477 if(sh_video
->fps
!=picture
.fps
) if(!force_fps
&& !telecine
){
478 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video
->fps
,picture
.fps
,sh_video
->fps
-picture
.fps
,picture
.frame_rate_code
);
479 sh_video
->fps
=picture
.fps
;
480 sh_video
->frametime
=1.0/picture
.fps
;
483 // fix mpeg2 frametime:
484 frame_time
=(picture
.display_time
)*0.01f
;
485 picture
.display_time
=100;
488 telecine_cnt
*=0.9; // drift out error
489 telecine_cnt
+=frame_time
-5.0/4.0;
490 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"\r telecine = %3.1f %5.3f \n",frame_time
,telecine_cnt
);
494 if(telecine_cnt
<-1.5 || telecine_cnt
>1.5){
495 mp_tmsg(MSGT_DECVIDEO
,MSGL_INFO
,"\ndemux_mpg: 30000/1001fps NTSC content detected, switching framerate.\n");
499 if(telecine_cnt
>-0.5 && telecine_cnt
<0.5 && !force_fps
){
500 sh_video
->fps
=sh_video
->fps
*4/5;
501 sh_video
->frametime
=sh_video
->frametime
*5/4;
502 mp_tmsg(MSGT_DECVIDEO
,MSGL_INFO
,"\ndemux_mpg: 24000/1001fps progressive NTSC content detected, switching framerate.\n");
505 } else if(video_codec
== VIDEO_MPEG4
){
506 while(videobuf_len
<VIDEOBUFFER_SIZE
-MAX_VIDEO_PACKET_SIZE
){
507 int i
=sync_video_packet(d_video
);
509 if(!read_video_packet(d_video
)) return -1; // EOF
512 *start
=videobuffer
; in_size
=videobuf_len
;
514 } else if(video_codec
== VIDEO_H264
){
516 while(videobuf_len
<VIDEOBUFFER_SIZE
-MAX_VIDEO_PACKET_SIZE
){
517 int i
=sync_video_packet(d_video
);
518 int pos
= videobuf_len
+4;
520 if(!read_video_packet(d_video
)) return -1; // EOF
521 if((i
&~0x60) == 0x107 && i
!= 0x107) {
522 h264_parse_sps(&picture
, &(videobuffer
[pos
]), videobuf_len
- pos
);
523 if(picture
.fps
> 0) {
524 sh_video
->fps
=picture
.fps
;
525 sh_video
->frametime
=1.0/picture
.fps
;
527 i
=sync_video_packet(d_video
);
529 if(!read_video_packet(d_video
)) return -1; // EOF
532 // here starts the access unit end detection code
533 // see the mail on MPlayer-dev-eng for details:
534 // Date: Sat, 17 Sep 2005 11:24:06 +0200
535 // Subject: Re: [MPlayer-dev-eng] [RFC] h264 ES parser problems
536 // Message-ID: <20050917092406.GA7699@rz.uni-karlsruhe.de>
537 if((i
&~0x60) == 0x101 || (i
&~0x60) == 0x102 || (i
&~0x60) == 0x105)
538 // found VCL NAL with slice header i.e. start of current primary coded
539 // picture, so start scanning for the end now
542 i
= sync_video_packet(d_video
) & ~0x60; // code of next packet
543 if(i
== 0x106 || i
== 0x109) break; // SEI or access unit delim.
544 if(i
== 0x101 || i
== 0x102 || i
== 0x105) {
545 // assuming arbitrary slice ordering is not allowed, the
546 // first_mb_in_slice (golomb encoded) value should be 0 then
547 // for the first VCL NAL in a picture
548 if (demux_peekc(d_video
) & 0x80)
553 *start
=videobuffer
; in_size
=videobuf_len
;
555 } else if(video_codec
== VIDEO_VC1
) {
556 while(videobuf_len
<VIDEOBUFFER_SIZE
-MAX_VIDEO_PACKET_SIZE
) {
557 int i
=sync_video_packet(d_video
);
559 if(!read_video_packet(d_video
)) return -1; // EOF
563 in_size
=videobuf_len
;
566 // frame-based file formats: (AVI,ASF,MOV)
567 in_size
=ds_get_packet(d_video
,start
);
568 if(in_size
<0) return -1; // EOF
572 //------------------------ frame decoded. --------------------
574 // Increase video timers:
575 sh_video
->num_frames
+=frame_time
;
576 ++sh_video
->num_frames_decoded
;
578 frame_time
*=sh_video
->frametime
;
580 // override frame_time for variable/unknown FPS formats:
581 if(!force_fps
) switch(demuxer
->file_format
){
582 case DEMUXER_TYPE_GIF
:
583 case DEMUXER_TYPE_MATROSKA
:
584 case DEMUXER_TYPE_MNG
:
585 if(d_video
->pts
>0 && pts1
>0 && d_video
->pts
>pts1
)
586 frame_time
=d_video
->pts
-pts1
;
588 case DEMUXER_TYPE_TV
:
589 case DEMUXER_TYPE_MOV
:
590 case DEMUXER_TYPE_FILM
:
591 case DEMUXER_TYPE_VIVO
:
592 case DEMUXER_TYPE_OGG
:
593 case DEMUXER_TYPE_ASF
: {
594 double next_pts
= ds_get_next_pts(d_video
);
595 double d
= (next_pts
!= MP_NOPTS_VALUE
) ? next_pts
- d_video
->pts
: d_video
->pts
-pts1
;
598 if((int)sh_video
->fps
==1000)
599 mp_msg(MSGT_CPLAYER
,MSGL_V
,"\navg. framerate: %d fps \n",(int)(1.0f
/d
));
600 sh_video
->frametime
=d
; // 1ms
601 sh_video
->fps
=1.0f
/d
;
605 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"\nInvalid frame duration value (%5.3f/%5.3f => %5.3f). Defaulting to %5.3f sec.\n",d_video
->pts
,next_pts
,d
,frame_time
);
606 // frame_time = 1/25.0;
610 case DEMUXER_TYPE_LAVF
:
611 case DEMUXER_TYPE_LAVF_PREFERRED
:
612 if((int)sh_video
->fps
==1000 || (int)sh_video
->fps
<=1){
613 double next_pts
= ds_get_next_pts(d_video
);
614 double d
= (next_pts
!= MP_NOPTS_VALUE
) ? next_pts
- d_video
->pts
: d_video
->pts
-pts1
;
620 case DEMUXER_TYPE_REAL
:
622 double next_pts
= ds_get_next_pts(d_video
);
623 double d
= (next_pts
!= MP_NOPTS_VALUE
) ? next_pts
- d_video
->pts
: d_video
->pts
- pts1
;
625 frame_time
= (d
>= 0 && pts1
> 0) ? d
: 0.001;
630 if(video_codec
== VIDEO_MPEG12
){
631 sh_video
->pts
+=frame_time
;
632 if(picture_coding_type
==1)
634 if(picture_coding_type
<=2 && sh_video
->i_pts
){
635 sh_video
->pts
=sh_video
->i_pts
;
639 if(picture_coding_type
<=2) sh_video
->i_pts
=pts
;
640 else sh_video
->pts
=pts
;
644 sh_video
->pts
=d_video
->pts
;
646 if(frame_time_ptr
) *frame_time_ptr
=frame_time
;