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.
30 #include "stream/stream.h"
33 #include "demux_ty_osd.h"
39 /* sub_cc (closed captions)*/
40 #include "sub/sub_cc.h"
42 /* biCompression constant */
45 static mp_mpeg_header_t picture
;
47 static int telecine
=0;
48 static float telecine_cnt
=-2.5;
58 static video_codec_t
find_video_codec(sh_video_t
*sh_video
)
60 demux_stream_t
*d_video
=sh_video
->ds
;
61 int fmt
= d_video
->demuxer
->file_format
;
64 (fmt
== DEMUXER_TYPE_PVA
) ||
65 (fmt
== DEMUXER_TYPE_MPEG_ES
) ||
66 (fmt
== DEMUXER_TYPE_MPEG_GXF
) ||
67 (fmt
== DEMUXER_TYPE_MPEG_PES
) ||
69 (fmt
== DEMUXER_TYPE_MPEG_PS
|| fmt
== DEMUXER_TYPE_MPEG_TS
) &&
70 ((! sh_video
->format
) || (sh_video
->format
==0x10000001) || (sh_video
->format
==0x10000002))
72 (fmt
== DEMUXER_TYPE_MPEG_TY
)
75 else if((fmt
== DEMUXER_TYPE_MPEG4_ES
) ||
76 ((fmt
== DEMUXER_TYPE_MPEG_TS
) && (sh_video
->format
==0x10000004)) ||
77 ((fmt
== DEMUXER_TYPE_MPEG_PS
) && (sh_video
->format
==0x10000004))
80 else if((fmt
== DEMUXER_TYPE_H264_ES
) ||
81 ((fmt
== DEMUXER_TYPE_MPEG_TS
) && (sh_video
->format
==0x10000005)) ||
82 ((fmt
== DEMUXER_TYPE_MPEG_PS
) && (sh_video
->format
==0x10000005))
85 else if((fmt
== DEMUXER_TYPE_MPEG_PS
|| fmt
== DEMUXER_TYPE_MPEG_TS
) &&
86 (sh_video
->format
==mmioFOURCC('W', 'V', 'C', '1')))
88 else if (fmt
== DEMUXER_TYPE_ASF
&& sh_video
->bih
&& sh_video
->bih
->biCompression
== mmioFOURCC('D', 'V', 'R', ' '))
94 int video_read_properties(sh_video_t
*sh_video
){
95 demux_stream_t
*d_video
=sh_video
->ds
;
96 video_codec_t video_codec
= find_video_codec(sh_video
);
97 // Determine image properties:
100 if((d_video
->demuxer
->file_format
== DEMUXER_TYPE_ASF
) || (d_video
->demuxer
->file_format
== DEMUXER_TYPE_AVI
)) {
102 // in case no strf chunk has been seen in avi, we have no bitmap header
103 if(!sh_video
->bih
) return 0;
104 sh_video
->format
=sh_video
->bih
->biCompression
;
105 sh_video
->disp_w
=sh_video
->bih
->biWidth
;
106 sh_video
->disp_h
=abs(sh_video
->bih
->biHeight
);
111 int pos
= 0, vop_cnt
=0, units
[3];
112 videobuf_len
=0; videobuf_code_len
=0;
113 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for Video Object Start code... ");
115 int i
=sync_video_packet(d_video
);
116 if(i
<=0x11F) break; // found it!
117 if(!i
|| !skip_video_packet(d_video
)){
118 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
122 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
124 videobuffer
= av_malloc(VIDEOBUFFER_SIZE
+ MP_INPUT_BUFFER_PADDING_SIZE
);
125 if (videobuffer
) memset(videobuffer
+VIDEOBUFFER_SIZE
, 0, MP_INPUT_BUFFER_PADDING_SIZE
);
127 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot allocate shared memory.\n");
131 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for Video Object Layer Start code... ");
133 int i
=sync_video_packet(d_video
);
134 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"M4V: 0x%X\n",i
);
135 if(i
>=0x120 && i
<=0x12F) break; // found it!
136 if(!i
|| !read_video_packet(d_video
)){
137 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
141 pos
= videobuf_len
+4;
142 if(!read_video_packet(d_video
)){
143 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Can't read Video Object Layer Header\n");
146 mp4_header_process_vol(&picture
, &(videobuffer
[pos
]));
147 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK! FPS SEEMS TO BE %.3f\nSearching for Video Object Plane Start code... ", sh_video
->fps
);
150 int i
=sync_video_packet(d_video
);
151 if(i
==0x1B6) break; // found it!
152 if(!i
|| !read_video_packet(d_video
)){
153 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
157 pos
= videobuf_len
+4;
158 if(!read_video_packet(d_video
)){
159 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Can't read Video Object Plane Header\n");
162 mp4_header_process_vop(&picture
, &(videobuffer
[pos
]));
163 sh_video
->disp_w
= picture
.display_picture_width
;
164 sh_video
->disp_h
= picture
.display_picture_height
;
165 units
[vop_cnt
] = picture
.timeinc_unit
;
167 //mp_msg(MSGT_DECVIDEO,MSGL_V, "TYPE: %d, unit: %d\n", picture.picture_type, picture.timeinc_unit);
169 int i
, mn
, md
, mx
, diff
;
183 if((units
[i
] > mn
) && (units
[i
] < mx
))
186 mp_msg(MSGT_DECVIDEO
,MSGL_V
, "MIN: %d, mid: %d, max: %d\n", mn
, md
, mx
);
187 if(mx
- md
> md
- mn
)
192 picture
.fps
= ((float)picture
.timeinc_resolution
) / diff
;
193 mp_msg(MSGT_DECVIDEO
,MSGL_V
, "FPS seems to be: %f, resolution: %d, delta_units: %d\n", picture
.fps
, picture
.timeinc_resolution
, diff
);
197 sh_video
->fps
=picture
.fps
;
198 sh_video
->frametime
=1.0/picture
.fps
;
199 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
, "FPS seems to be: %f\n", picture
.fps
);
201 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
202 sh_video
->format
=0x10000004;
207 videobuf_len
=0; videobuf_code_len
=0;
208 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for sequence parameter set... ");
210 int i
=sync_video_packet(d_video
);
211 if((i
&~0x60) == 0x107 && i
!= 0x107) break; // found it!
212 if(!i
|| !skip_video_packet(d_video
)){
213 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
217 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
219 videobuffer
= av_malloc(VIDEOBUFFER_SIZE
+ MP_INPUT_BUFFER_PADDING_SIZE
);
220 if (videobuffer
) memset(videobuffer
+VIDEOBUFFER_SIZE
, 0, MP_INPUT_BUFFER_PADDING_SIZE
);
222 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot allocate shared memory.\n");
226 pos
= videobuf_len
+4;
227 if(!read_video_packet(d_video
)){
228 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Can't read sequence parameter set\n");
231 h264_parse_sps(&picture
, &(videobuffer
[pos
]), videobuf_len
- pos
);
232 sh_video
->disp_w
=picture
.display_picture_width
;
233 sh_video
->disp_h
=picture
.display_picture_height
;
234 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for picture parameter set... ");
236 int i
=sync_video_packet(d_video
);
237 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"H264: 0x%X\n",i
);
238 if((i
&~0x60) == 0x108 && i
!= 0x108) break; // found it!
239 if(!i
|| !read_video_packet(d_video
)){
240 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
244 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\nSearching for Slice... ");
246 int i
=sync_video_packet(d_video
);
247 if((i
&~0x60) == 0x101 || (i
&~0x60) == 0x102 || (i
&~0x60) == 0x105) break; // found it!
248 if(!i
|| !read_video_packet(d_video
)){
249 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
253 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
254 sh_video
->format
=0x10000005;
256 sh_video
->fps
=picture
.fps
;
257 sh_video
->frametime
=1.0/picture
.fps
;
258 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
, "FPS seems to be: %f\n", picture
.fps
);
263 if (d_video
->demuxer
->file_format
== DEMUXER_TYPE_ASF
) { // DVR-MS
264 if(!sh_video
->bih
) return 0;
265 sh_video
->format
=sh_video
->bih
->biCompression
;
268 // Find sequence_header first:
269 videobuf_len
=0; videobuf_code_len
=0;
270 telecine
=0; telecine_cnt
=-2.5;
271 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Searching for sequence header... ");
273 int i
=sync_video_packet(d_video
);
274 if(i
==0x1B3) break; // found it!
275 if(!i
|| !skip_video_packet(d_video
)){
276 if( mp_msg_test(MSGT_DECVIDEO
,MSGL_V
) ) mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
277 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"MPEG: FATAL: EOF while searching for sequence header.\n");
281 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"OK!\n");
282 // ========= Read & process sequence header & extension ============
284 videobuffer
= av_malloc(VIDEOBUFFER_SIZE
+ MP_INPUT_BUFFER_PADDING_SIZE
);
285 if (videobuffer
) memset(videobuffer
+VIDEOBUFFER_SIZE
, 0, MP_INPUT_BUFFER_PADDING_SIZE
);
287 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot allocate shared memory.\n");
292 if(!read_video_packet(d_video
)){
293 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"FATAL: Cannot read sequence header.\n");
296 if(mp_header_process_sequence_header (&picture
, &videobuffer
[4])) {
297 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"MPEG: bad sequence header\n");
298 goto mpeg_header_parser
;
300 if(sync_video_packet(d_video
)==0x1B5){ // next packet is seq. ext.
301 int pos
=videobuf_len
;
302 if(!read_video_packet(d_video
)){
303 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"FATAL: Cannot read sequence header extension.\n");
306 if(mp_header_process_extension (&picture
, &videobuffer
[pos
+4])) {
307 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"MPEG: bad sequence header extension\n");
313 sh_video
->format
=picture
.mpeg1
?0x10000001:0x10000002; // mpeg video
314 sh_video
->fps
=picture
.fps
* picture
.frame_rate_extension_n
/ picture
.frame_rate_extension_d
;
316 sh_video
->frametime
=0;
318 sh_video
->frametime
=1.0/sh_video
->fps
;
320 sh_video
->disp_w
=picture
.display_picture_width
;
321 sh_video
->disp_h
=picture
.display_picture_height
;
323 if(picture
.bitrate
!=0x3FFFF) // unspecified/VBR ?
324 sh_video
->i_bps
=picture
.bitrate
* 400 / 8;
326 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
,"mpeg bitrate: %d (%X)\n",picture
.bitrate
,picture
.bitrate
);
327 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,"VIDEO: %s %dx%d (aspect %d) %5.3f fps %5.1f kbps (%4.1f kbyte/s)\n",
328 picture
.mpeg1
?"MPEG1":"MPEG2",
329 sh_video
->disp_w
,sh_video
->disp_h
,
330 picture
.aspect_ratio_information
,
332 sh_video
->i_bps
* 8 / 1000.0,
333 sh_video
->i_bps
/ 1000.0 );
337 // Find sequence_header:
340 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,"Searching for VC1 sequence header... ");
342 int i
=sync_video_packet(d_video
);
343 if(i
==0x10F) break; // found it!
344 if(!i
|| !skip_video_packet(d_video
)){
345 if( mp_msg_test(MSGT_DECVIDEO
,MSGL_V
) ) mp_msg(MSGT_DECVIDEO
,MSGL_V
,"NONE :(\n");
346 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
, "Couldn't find VC-1 sequence header\n");
350 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,"found\n");
352 videobuffer
= av_malloc(VIDEOBUFFER_SIZE
+ MP_INPUT_BUFFER_PADDING_SIZE
);
353 if (videobuffer
) memset(videobuffer
+VIDEOBUFFER_SIZE
, 0, MP_INPUT_BUFFER_PADDING_SIZE
);
355 mp_tmsg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot allocate shared memory.\n");
359 if(!read_video_packet(d_video
)){
360 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
, "Couldn't read VC-1 sequence header!\n");
365 int i
=sync_video_packet(d_video
);
366 if(i
==0x10E) break; // found it!
367 if(!i
|| !skip_video_packet(d_video
)){
368 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Couldn't find VC-1 entry point sync-code:(\n");
372 if(!read_video_packet(d_video
)){
373 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Couldn't read VC-1 entry point sync-code:(\n");
377 if(mp_vc1_decode_sequence_header(&picture
, &videobuffer
[4], videobuf_len
-4)) {
378 sh_video
->bih
= calloc(1, sizeof(*sh_video
->bih
) + videobuf_len
);
379 if(sh_video
->bih
== NULL
) {
380 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Couldn't alloc %zu bytes for VC-1 extradata!\n", sizeof(*sh_video
->bih
) + videobuf_len
);
383 sh_video
->bih
->biSize
= sizeof(*sh_video
->bih
) + videobuf_len
;
384 memcpy(sh_video
->bih
+ 1, videobuffer
, videobuf_len
);
385 sh_video
->bih
->biCompression
= sh_video
->format
;
386 sh_video
->bih
->biWidth
= sh_video
->disp_w
= picture
.display_picture_width
;
387 sh_video
->bih
->biHeight
= sh_video
->disp_h
= picture
.display_picture_height
;
388 if(picture
.fps
> 0) {
389 sh_video
->frametime
=1.0/picture
.fps
;
390 sh_video
->fps
= picture
.fps
;
392 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,"VIDEO: VC-1 %dx%d, %5.3f fps, header len: %d\n",
393 sh_video
->disp_w
, sh_video
->disp_h
, sh_video
->fps
, videobuf_len
);
397 } // switch(file_format)
402 static void process_userdata(const unsigned char* buf
,int len
){
404 /* if the user data starts with "CC", assume it is a CC info packet */
405 if(len
>2 && buf
[0]=='C' && buf
[1]=='C'){
406 // mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"video.c: process_userdata() detected Closed Captions!\n");
407 subcc_process_data(buf
+2,len
-2);
410 if( len
> 2 && buf
[ 0 ] == 'T' && buf
[ 1 ] == 'Y' )
412 ty_processuserdata( buf
+ 2, len
- 2 );
416 if(verbose
<2) return;
417 fprintf(stderr
, "user_data: len=%3d %02X %02X %02X %02X '",
418 len
, buf
[0], buf
[1], buf
[2], buf
[3]);
420 // if(buf[i]>=32 && buf[i]<127) fputc(buf[i], stderr);
421 if(buf
[i
]&0x60) fputc(buf
[i
]&0x7F, stderr
);
422 fprintf(stderr
, "'\n");
425 int video_read_frame(sh_video_t
* sh_video
,float* frame_time_ptr
,unsigned char** start
,int force_fps
){
426 demux_stream_t
*d_video
=sh_video
->ds
;
427 demuxer_t
*demuxer
=d_video
->demuxer
;
429 float pts1
=d_video
->pts
;
432 int picture_coding_type
=0;
434 video_codec_t video_codec
= find_video_codec(sh_video
);
438 if(video_codec
== VIDEO_MPEG12
){
442 while(videobuf_len
<VIDEOBUFFER_SIZE
-MAX_VIDEO_PACKET_SIZE
){
443 int i
=sync_video_packet(d_video
);
444 //void* buffer=&videobuffer[videobuf_len+4];
445 int start
=videobuf_len
+4;
447 if(i
<0x101 || i
>=0x1B0){ // not slice code -> end of frame
448 if(!i
) return -1; // EOF
456 if(i
>=0x101 && i
<0x1B0) in_frame
=1; // picture startcode
457 else if(!i
) return -1; // EOF
459 if(!read_video_packet(d_video
)) return -1; // EOF
462 case 0x1B3: mp_header_process_sequence_header (&picture
, &videobuffer
[start
]);break;
463 case 0x1B5: mp_header_process_extension (&picture
, &videobuffer
[start
]);break;
464 case 0x1B2: process_userdata (&videobuffer
[start
], videobuf_len
-start
);break;
465 case 0x100: picture_coding_type
=(videobuffer
[start
+1] >> 3) & 7;break;
468 fps
= picture
.fps
* picture
.frame_rate_extension_n
/ picture
.frame_rate_extension_d
;
470 *start
=videobuffer
; in_size
=videobuf_len
;
473 if(sh_video
->fps
!=fps
) if(!force_fps
&& !telecine
){
474 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,"Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video
->fps
,fps
,sh_video
->fps
-fps
,picture
.frame_rate_code
);
476 sh_video
->frametime
=1.0/fps
;
479 // fix mpeg2 frametime:
480 frame_time
=(picture
.display_time
)*0.01f
;
481 picture
.display_time
=100;
484 telecine_cnt
*=0.9; // drift out error
485 telecine_cnt
+=frame_time
-5.0/4.0;
486 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"\r telecine = %3.1f %5.3f \n",frame_time
,telecine_cnt
);
490 if(telecine_cnt
<-1.5 || telecine_cnt
>1.5){
491 mp_tmsg(MSGT_DECVIDEO
,MSGL_INFO
,"\ndemux_mpg: 30000/1001fps NTSC content detected, switching framerate.\n");
495 if(telecine_cnt
>-0.5 && telecine_cnt
<0.5 && !force_fps
){
496 sh_video
->fps
=sh_video
->fps
*4/5;
497 sh_video
->frametime
=sh_video
->frametime
*5/4;
498 mp_tmsg(MSGT_DECVIDEO
,MSGL_INFO
,"\ndemux_mpg: 24000/1001fps progressive NTSC content detected, switching framerate.\n");
501 } else if(video_codec
== VIDEO_MPEG4
){
502 while(videobuf_len
<VIDEOBUFFER_SIZE
-MAX_VIDEO_PACKET_SIZE
){
503 int i
=sync_video_packet(d_video
);
505 if(!read_video_packet(d_video
)) return -1; // EOF
508 *start
=videobuffer
; in_size
=videobuf_len
;
510 } else if(video_codec
== VIDEO_H264
){
512 while(videobuf_len
<VIDEOBUFFER_SIZE
-MAX_VIDEO_PACKET_SIZE
){
513 int i
=sync_video_packet(d_video
);
514 int pos
= videobuf_len
+4;
516 if(!read_video_packet(d_video
)) return -1; // EOF
517 if((i
&~0x60) == 0x107 && i
!= 0x107) {
518 h264_parse_sps(&picture
, &(videobuffer
[pos
]), videobuf_len
- pos
);
519 if(picture
.fps
> 0) {
520 sh_video
->fps
=picture
.fps
;
521 sh_video
->frametime
=1.0/picture
.fps
;
523 i
=sync_video_packet(d_video
);
525 if(!read_video_packet(d_video
)) return -1; // EOF
528 // here starts the access unit end detection code
529 // see the mail on MPlayer-dev-eng for details:
530 // Date: Sat, 17 Sep 2005 11:24:06 +0200
531 // Subject: Re: [MPlayer-dev-eng] [RFC] h264 ES parser problems
532 // Message-ID: <20050917092406.GA7699@rz.uni-karlsruhe.de>
533 if((i
&~0x60) == 0x101 || (i
&~0x60) == 0x102 || (i
&~0x60) == 0x105)
534 // found VCL NAL with slice header i.e. start of current primary coded
535 // picture, so start scanning for the end now
538 i
= sync_video_packet(d_video
) & ~0x60; // code of next packet
539 if(i
== 0x106 || i
== 0x109) break; // SEI or access unit delim.
540 if(i
== 0x101 || i
== 0x102 || i
== 0x105) {
541 // assuming arbitrary slice ordering is not allowed, the
542 // first_mb_in_slice (golomb encoded) value should be 0 then
543 // for the first VCL NAL in a picture
544 if (demux_peekc(d_video
) & 0x80)
549 *start
=videobuffer
; in_size
=videobuf_len
;
551 } else if(video_codec
== VIDEO_VC1
) {
552 while(videobuf_len
<VIDEOBUFFER_SIZE
-MAX_VIDEO_PACKET_SIZE
) {
553 int i
=sync_video_packet(d_video
);
555 if(!read_video_packet(d_video
)) return -1; // EOF
559 in_size
=videobuf_len
;
562 // frame-based file formats: (AVI,ASF,MOV)
563 in_size
=ds_get_packet(d_video
,start
);
564 if(in_size
<0) return -1; // EOF
568 //------------------------ frame decoded. --------------------
570 // Increase video timers:
571 sh_video
->num_frames
+=frame_time
;
572 ++sh_video
->num_frames_decoded
;
574 frame_time
*=sh_video
->frametime
;
576 // override frame_time for variable/unknown FPS formats:
577 if(!force_fps
) switch(demuxer
->file_format
){
578 case DEMUXER_TYPE_GIF
:
579 case DEMUXER_TYPE_MATROSKA
:
580 case DEMUXER_TYPE_MNG
:
581 if(d_video
->pts
>0 && pts1
>0 && d_video
->pts
>pts1
)
582 frame_time
=d_video
->pts
-pts1
;
584 case DEMUXER_TYPE_TV
:
585 case DEMUXER_TYPE_MOV
:
586 case DEMUXER_TYPE_FILM
:
587 case DEMUXER_TYPE_VIVO
:
588 case DEMUXER_TYPE_OGG
:
589 case DEMUXER_TYPE_ASF
: {
590 double next_pts
= ds_get_next_pts(d_video
);
591 double d
= (next_pts
!= MP_NOPTS_VALUE
) ? next_pts
- d_video
->pts
: d_video
->pts
-pts1
;
594 if((int)sh_video
->fps
==1000)
595 mp_msg(MSGT_CPLAYER
,MSGL_V
,"\navg. framerate: %d fps \n",(int)(1.0f
/d
));
596 sh_video
->frametime
=d
; // 1ms
597 sh_video
->fps
=1.0f
/d
;
601 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
);
602 // frame_time = 1/25.0;
606 case DEMUXER_TYPE_LAVF
:
607 case DEMUXER_TYPE_LAVF_PREFERRED
:
608 if((int)sh_video
->fps
==1000 || (int)sh_video
->fps
<=1){
609 double next_pts
= ds_get_next_pts(d_video
);
610 double d
= (next_pts
!= MP_NOPTS_VALUE
) ? next_pts
- d_video
->pts
: d_video
->pts
-pts1
;
616 case DEMUXER_TYPE_REAL
:
618 double next_pts
= ds_get_next_pts(d_video
);
619 double d
= (next_pts
!= MP_NOPTS_VALUE
) ? next_pts
- d_video
->pts
: d_video
->pts
- pts1
;
621 frame_time
= (d
>= 0 && pts1
> 0) ? d
: 0.001;
626 if(video_codec
== VIDEO_MPEG12
){
627 sh_video
->pts
+=frame_time
;
628 if(picture_coding_type
==1)
629 d_video
->keyframe
= true;
630 if(picture_coding_type
<=2 && sh_video
->i_pts
){
631 sh_video
->pts
=sh_video
->i_pts
;
635 if(picture_coding_type
<=2) sh_video
->i_pts
=pts
;
636 else sh_video
->pts
=pts
;
640 sh_video
->pts
=d_video
->pts
;
642 if(frame_time_ptr
) *frame_time_ptr
=frame_time
;