Mercurial > mplayer.hg
comparison mencoder.c @ 2643:9d0a638e211a
divx4 2-pass support, -frames option
author | arpi |
---|---|
date | Sat, 03 Nov 2001 00:44:02 +0000 |
parents | 511f1983e0f0 |
children | a863a97f3a1c |
comparison
equal
deleted
inserted
replaced
2642:0e6e13261d79 | 2643:9d0a638e211a |
---|---|
24 | 24 |
25 #include "dec_audio.h" | 25 #include "dec_audio.h" |
26 #include "dec_video.h" | 26 #include "dec_video.h" |
27 | 27 |
28 #include <encore2.h> | 28 #include <encore2.h> |
29 #include "divx4_vbr.h" | |
29 | 30 |
30 #include <lame/lame.h> | 31 #include <lame/lame.h> |
31 | 32 |
32 //-------------------------- | 33 //-------------------------- |
33 | 34 |
75 | 76 |
76 char* out_filename="test.avi"; | 77 char* out_filename="test.avi"; |
77 char* mp3_filename=NULL; | 78 char* mp3_filename=NULL; |
78 char* ac3_filename=NULL; | 79 char* ac3_filename=NULL; |
79 | 80 |
81 static int pass=0; | |
82 static char* passtmpfile="divx2pass.log"; | |
83 | |
84 static int play_n_frames=-1; | |
85 | |
80 char *out_audio_codec=NULL; // override audio codec | 86 char *out_audio_codec=NULL; // override audio codec |
81 char *out_video_codec=NULL; // override video codec | 87 char *out_video_codec=NULL; // override video codec |
82 | 88 |
83 //#include "libmpeg2/mpeg2.h" | 89 //#include "libmpeg2/mpeg2.h" |
84 //#include "libmpeg2/mpeg2_internal.h" | 90 //#include "libmpeg2/mpeg2_internal.h" |
85 | 91 |
86 ENC_PARAM divx4_param; | 92 ENC_PARAM divx4_param; |
93 int divx4_crispness=100; | |
87 | 94 |
88 int lame_param_quality=0; // best | 95 int lame_param_quality=0; // best |
89 int lame_param_vbr=vbr_default; | 96 int lame_param_vbr=vbr_default; |
90 int lame_param_mode=-1; // unset | 97 int lame_param_mode=-1; // unset |
91 int lame_param_padding=-1; // unset | 98 int lame_param_padding=-1; // unset |
249 mp_msg(MSGT_MENCODER,MSGL_HINT,MSGTR_CopyCodecsConf); | 256 mp_msg(MSGT_MENCODER,MSGL_HINT,MSGTR_CopyCodecsConf); |
250 exit(0); | 257 exit(0); |
251 } | 258 } |
252 } | 259 } |
253 | 260 |
261 // set some defaults, before parsing configfile/commandline: | |
262 divx4_param.min_quantizer = 2; | |
263 divx4_param.max_quantizer = 31; | |
264 divx4_param.rc_period = 2000; | |
265 divx4_param.rc_reaction_period = 10; | |
266 divx4_param.rc_reaction_ratio = 20; | |
267 | |
268 | |
254 num_filenames=parse_command_line(conf, argc, argv, envp, &filenames); | 269 num_filenames=parse_command_line(conf, argc, argv, envp, &filenames); |
255 if(num_filenames<0) exit(1); // error parsing cmdline | 270 if(num_filenames<0) exit(1); // error parsing cmdline |
256 if(!num_filenames && !vcd_track && !dvd_title){ | 271 if(!num_filenames && !vcd_track && !dvd_title){ |
257 printf("\nMissing filename!\n\n"); | 272 printf("\nMissing filename!\n\n"); |
258 exit(1); | 273 exit(1); |
494 else if(divx4_param.bitrate<=16000) divx4_param.bitrate*=1000; | 509 else if(divx4_param.bitrate<=16000) divx4_param.bitrate*=1000; |
495 if(!divx4_param.quality) divx4_param.quality=5; // the quality of compression ( 1 - fastest, 5 - best ) | 510 if(!divx4_param.quality) divx4_param.quality=5; // the quality of compression ( 1 - fastest, 5 - best ) |
496 divx4_param.handle=NULL; | 511 divx4_param.handle=NULL; |
497 encore(NULL,ENC_OPT_INIT,&divx4_param,NULL); | 512 encore(NULL,ENC_OPT_INIT,&divx4_param,NULL); |
498 enc_handle=divx4_param.handle; | 513 enc_handle=divx4_param.handle; |
514 switch(out_fmt){ | |
515 case IMGFMT_YV12: enc_frame.colorspace=ENC_CSP_YV12; break; | |
516 case IMGFMT_IYUV: | |
517 case IMGFMT_I420: enc_frame.colorspace=ENC_CSP_I420; break; | |
518 case IMGFMT_YUY2: enc_frame.colorspace=ENC_CSP_YUY2; break; | |
519 case IMGFMT_UYVY: enc_frame.colorspace=ENC_CSP_UYVY; break; | |
520 case IMGFMT_RGB24: | |
521 case IMGFMT_BGR24: | |
522 enc_frame.colorspace=ENC_CSP_RGB24; break; | |
523 default: | |
524 mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported out_fmt!\n"); | |
525 } | |
526 switch(pass){ | |
527 case 1: | |
528 VbrControl_init_2pass_vbr_analysis(passtmpfile, divx4_param.quality); | |
529 break; | |
530 case 2: | |
531 VbrControl_init_2pass_vbr_encoding(passtmpfile, | |
532 divx4_param.bitrate, | |
533 divx4_param.framerate, | |
534 divx4_crispness, | |
535 divx4_param.quality); | |
536 break; | |
537 } | |
499 break; | 538 break; |
500 } | 539 } |
501 | 540 |
502 #if 1 | 541 #if 1 |
503 if(sh_audio) | 542 if(sh_audio) |
539 float a_pts=0; | 578 float a_pts=0; |
540 float v_pts=0; | 579 float v_pts=0; |
541 unsigned char* start=NULL; | 580 unsigned char* start=NULL; |
542 int in_size; | 581 int in_size; |
543 int skip_flag=0; // 1=skip -1=duplicate | 582 int skip_flag=0; // 1=skip -1=duplicate |
583 | |
584 if(play_n_frames>=0){ | |
585 --play_n_frames; | |
586 if(play_n_frames<0) break; | |
587 } | |
544 | 588 |
545 if(sh_audio){ | 589 if(sh_audio){ |
546 // get audio: | 590 // get audio: |
547 while(mux_a->timer-audio_preload<mux_v->timer){ | 591 while(mux_a->timer-audio_preload<mux_v->timer){ |
548 int len; | 592 int len; |
648 break; | 692 break; |
649 } | 693 } |
650 enc_frame.image=vo_image_ptr; | 694 enc_frame.image=vo_image_ptr; |
651 enc_frame.bitstream=mux_v->buffer; | 695 enc_frame.bitstream=mux_v->buffer; |
652 enc_frame.length=mux_v->buffer_size; | 696 enc_frame.length=mux_v->buffer_size; |
653 switch(out_fmt){ | 697 enc_frame.mvs=NULL; |
654 case IMGFMT_YV12: enc_frame.colorspace=ENC_CSP_YV12; break; | |
655 case IMGFMT_IYUV: | |
656 case IMGFMT_I420: enc_frame.colorspace=ENC_CSP_I420; break; | |
657 case IMGFMT_YUY2: enc_frame.colorspace=ENC_CSP_YUY2; break; | |
658 case IMGFMT_UYVY: enc_frame.colorspace=ENC_CSP_UYVY; break; | |
659 case IMGFMT_RGB24: | |
660 case IMGFMT_BGR24: | |
661 enc_frame.colorspace=ENC_CSP_RGB24; break; | |
662 } | |
663 enc_frame.quant=0; | 698 enc_frame.quant=0; |
664 enc_frame.intra=0; | 699 enc_frame.intra=0; |
665 enc_frame.mvs=NULL; | 700 if(pass==2){ // handle 2-pass: |
701 enc_frame.quant = VbrControl_get_quant(); | |
702 enc_frame.intra = VbrControl_get_intra(); | |
703 encore(enc_handle,ENC_OPT_ENCODE_VBR,&enc_frame,&enc_result); | |
704 VbrControl_update_2pass_vbr_encoding(enc_result.motion_bits, | |
705 enc_result.texture_bits, | |
706 enc_result.total_bits); | |
707 } else { | |
708 encore(enc_handle,ENC_OPT_ENCODE,&enc_frame,&enc_result); | |
709 if(pass==1){ | |
710 VbrControl_update_2pass_vbr_analysis(enc_result.is_key_frame, | |
711 enc_result.motion_bits, | |
712 enc_result.texture_bits, | |
713 enc_result.total_bits, | |
714 enc_result.quantizer); | |
715 } | |
716 } | |
717 | |
666 // printf("encoding...\n"); | 718 // printf("encoding...\n"); |
667 encore(enc_handle,ENC_OPT_ENCODE,&enc_frame,&enc_result); | |
668 // printf(" len=%d key:%d qualt:%d \n",enc_frame.length,enc_result.is_key_frame,enc_result.quantizer); | 719 // printf(" len=%d key:%d qualt:%d \n",enc_frame.length,enc_result.is_key_frame,enc_result.quantizer); |
669 aviwrite_write_chunk(muxer,mux_v,muxer_f,enc_frame.length,enc_result.is_key_frame?0x10:0); | 720 aviwrite_write_chunk(muxer,mux_v,muxer_f,enc_frame.length,enc_result.is_key_frame?0x10:0); |
670 break; | 721 break; |
671 } | 722 } |
672 | 723 |