comparison mencoder.c @ 2571:13608ff3d1e6

simplified
author arpi
date Tue, 30 Oct 2001 21:22:28 +0000
parents cf6a236b2d00
children cc926eda63cd
comparison
equal deleted inserted replaced
2570:af43a83122fc 2571:13608ff3d1e6
11 11
12 #include "codec-cfg.h" 12 #include "codec-cfg.h"
13 13
14 #include "stream.h" 14 #include "stream.h"
15 #include "demuxer.h" 15 #include "demuxer.h"
16 #include "parse_es.h"
17 #include "stheader.h" 16 #include "stheader.h"
18 17
19 #include "aviwrite.h" 18 #include "aviwrite.h"
20 19
21 #include "libvo/video_out.h" 20 #include "libvo/video_out.h"
22 21
23 #include <encore2.h> 22 #include <encore2.h>
24 23
25 char *get_path(char *filename){ 24 #include "get_path.c"
26 char *homedir;
27 char *buff;
28 static char *config_dir = "/.mplayer";
29 int len;
30
31 if ((homedir = getenv("HOME")) == NULL)
32 return NULL;
33 len = strlen(homedir) + strlen(config_dir) + 1;
34 if (filename == NULL) {
35 if ((buff = (char *) malloc(len)) == NULL)
36 return NULL;
37 sprintf(buff, "%s%s", homedir, config_dir);
38 } else {
39 len += strlen(filename) + 1;
40 if ((buff = (char *) malloc(len)) == NULL)
41 return NULL;
42 sprintf(buff, "%s%s/%s", homedir, config_dir, filename);
43 }
44 return buff;
45 }
46
47 #define ABS(x) (((x)>=0)?(x):(-(x)))
48 25
49 //-------------------------- 26 //--------------------------
50 27
51 // cache2: 28 // cache2:
52 #ifdef USE_STREAM_CACHE 29 #ifdef USE_STREAM_CACHE
56 #endif 33 #endif
57 34
58 // AVI demuxer params: 35 // AVI demuxer params:
59 static float c_total=0; 36 static float c_total=0;
60 int delay_corrected=1; 37 int delay_corrected=1;
61 extern int index_mode; // -1=untouched 0=don't use index 1=use (geneate) index
62 extern int force_ni;
63 extern int pts_from_bps;
64 38
65 char *audio_codec=NULL; // override audio codec 39 char *audio_codec=NULL; // override audio codec
66 char *video_codec=NULL; // override video codec 40 char *video_codec=NULL; // override video codec
67 int audio_family=-1; // override audio codec family 41 int audio_family=-1; // override audio codec family
68 int video_family=-1; // override video codec family 42 int video_family=-1; // override video codec family
78 double vout_time_usage=0; 52 double vout_time_usage=0;
79 static double audio_time_usage=0; 53 static double audio_time_usage=0;
80 static int total_time_usage_start=0; 54 static int total_time_usage_start=0;
81 static int benchmark=0; 55 static int benchmark=0;
82 56
83 int divx_quality=0;
84 int force_fps=0; 57 int force_fps=0;
85 58
86 #include "libmpeg2/mpeg2.h" 59 #include "libmpeg2/mpeg2.h"
87 #include "libmpeg2/mpeg2_internal.h" 60 #include "libmpeg2/mpeg2_internal.h"
88
89 extern picture_t *picture; // exported from libmpeg2/decode.c
90
91 int frameratecode2framerate[16] = {
92 0,
93 // Official mpeg1/2 framerates:
94 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 60*10000,
95 // libmpeg3's "Unofficial economy rates":
96 1*10000,5*10000,10*10000,12*10000,15*10000,0,0
97 };
98 61
99 static unsigned char* vo_image=NULL; 62 static unsigned char* vo_image=NULL;
100 static unsigned char* vo_image_ptr=NULL; 63 static unsigned char* vo_image_ptr=NULL;
101 static int vo_w,vo_h; 64 static int vo_w,vo_h;
102 65
337 signal(SIGTERM,exit_sighandler); // kill 300 signal(SIGTERM,exit_sighandler); // kill
338 301
339 302
340 while(!eof){ 303 while(!eof){
341 304
342 float frame_time=1; 305 float frame_time=0;
343 float pts1=d_video->pts;
344 int blit_frame=0; 306 int blit_frame=0;
345 float a_pts=0; 307 float a_pts=0;
346 float v_pts=0; 308 float v_pts=0;
347 309
348 // current_module="decode_video"; 310 //-------------------- Decode a frame: -----------------------
311 { unsigned char* start=NULL;
312 int in_size;
313 // get it!
314 // current_module="video_read_frame";
315 in_size=video_read_frame(sh_video,&frame_time,&start,force_fps);
316 if(in_size<0){ eof=1; break; }
317 if(in_size>max_framesize) max_framesize=in_size; // stats
318 // decode:
319 // current_module="decode_video";
320 // printf("Decode! %p %d \n",start,in_size);
321 blit_frame=decode_video(video_out,sh_video,start,in_size,drop_frame);
322 }
323 //------------------------ frame decoded. --------------------
349 324
350 //-------------------- Decode a frame: -----------------------
351
352 if(demuxer->file_format==DEMUXER_TYPE_MPEG_ES || demuxer->file_format==DEMUXER_TYPE_MPEG_PS){
353 int in_frame=0;
354 float newfps;
355 //videobuf_len=0;
356 while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
357 int i=sync_video_packet(d_video);
358 void* buffer=&videobuffer[videobuf_len+4];
359 if(in_frame){
360 if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame
361 #if 1
362 // send END OF FRAME code:
363 videobuffer[videobuf_len+0]=0;
364 videobuffer[videobuf_len+1]=0;
365 videobuffer[videobuf_len+2]=1;
366 videobuffer[videobuf_len+3]=0xFF;
367 videobuf_len+=4;
368 #endif
369 if(!i) eof=2; // EOF
370 break;
371 }
372 } else {
373 //if(i==0x100) in_frame=1; // picture startcode
374 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode
375 else if(!i){ eof=3; break;} // EOF
376 }
377 if(!read_video_packet(d_video)){ eof=4; break;} // EOF
378 //printf("read packet 0x%X, len=%d\n",i,videobuf_len);
379 if(sh_video->codec->driver!=VFM_MPEG){
380 // if not libmpeg2:
381 switch(i){
382 case 0x1B3: header_process_sequence_header (picture, buffer);break;
383 case 0x1B5: header_process_extension (picture, buffer);break;
384 }
385 }
386 }
387
388 //if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug
389 //printf("--- SEND %d bytes\n",videobuf_len);
390
391 blit_frame=decode_video(&video_out,sh_video,videobuffer,videobuf_len,0);
392
393 // get mpeg fps:
394 newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f;
395 if(ABS(sh_video->fps-newfps)>0.01f) {
396 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video->fps,newfps,sh_video->fps-newfps,picture->frame_rate_code);
397 sh_video->fps=newfps;
398 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code];
399 }
400
401 // fix mpeg2 frametime:
402 frame_time=(picture->display_time)*0.01f;
403 picture->display_time=100;
404 videobuf_len=0;
405
406 } else {
407 // frame-based file formats: (AVI,ASF,MOV)
408 unsigned char* start=NULL;
409 int in_size=ds_get_packet(d_video,&start);
410 if(in_size<0){ eof=5;break;}
411 //if(in_size>max_framesize) max_framesize=in_size;
412 if(mux_v->codec){
413 // convert
414 blit_frame=decode_video(&video_out,sh_video,start,in_size,0);
415 } else {
416 // copy
417 mux_v->buffer=start;
418 aviwrite_write_chunk(muxer,mux_v,muxer_f,in_size,(sh_video->ds->flags&1)?0x10:0);
419 }
420 }
421 if(eof) break;
422
423 //------------------------ frame decoded. --------------------
424
425 // Increase video timers:
426 sh_video->num_frames+=frame_time;
427 ++sh_video->num_frames_decoded;
428 frame_time*=sh_video->frametime;
429 if(demuxer->file_format==DEMUXER_TYPE_ASF && !force_fps){
430 // .ASF files has no fixed FPS - just frame durations!
431 float d=d_video->pts-pts1;
432 if(d>=0 && d<5) frame_time=d;
433 if(d>0){
434 if(verbose)
435 if((int)sh_video->fps==1000)
436 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"\rASF framerate: %d fps \n",(int)(1.0f/d));
437 sh_video->frametime=d; // 1ms
438 sh_video->fps=1.0f/d;
439 }
440 } else
441 if(demuxer->file_format==DEMUXER_TYPE_MOV && !force_fps){
442 // .MOV files has no fixed FPS - just frame durations!
443 float d=d_video->pts-pts1;
444 frame_time=d;
445 }
446 sh_video->timer+=frame_time; 325 sh_video->timer+=frame_time;
447
448 if(demuxer->file_format==DEMUXER_TYPE_MPEG_PS) d_video->pts+=frame_time;
449 326
450 if(pts_from_bps){ 327 if(pts_from_bps){
451 unsigned int samples=(sh_audio->audio.dwSampleSize)? 328 unsigned int samples=(sh_audio->audio.dwSampleSize)?
452 ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) : 329 ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
453 (d_audio->pack_no); // <- used for VBR audio 330 (d_audio->pack_no); // <- used for VBR audio