comparison mencoder.c @ 3357:1fa5d7dda911

libmp3lame optional
author arpi
date Thu, 06 Dec 2001 22:27:09 +0000
parents c68f5da1c61c
children 5d70491f438c
comparison
equal deleted inserted replaced
3356:2ef511fe1f57 3357:1fa5d7dda911
39 #include "dec_video.h" 39 #include "dec_video.h"
40 40
41 #include <encore2.h> 41 #include <encore2.h>
42 #include "divx4_vbr.h" 42 #include "divx4_vbr.h"
43 43
44 #ifdef HAVE_MP3LAME
44 #include <lame/lame.h> 45 #include <lame/lame.h>
46 #endif
45 47
46 #include <inttypes.h> 48 #include <inttypes.h>
47 #include "../postproc/swscale.h" 49 #include "../postproc/swscale.h"
48 50
49 //-------------------------- 51 //--------------------------
64 char *audio_codec=NULL; // override audio codec 66 char *audio_codec=NULL; // override audio codec
65 char *video_codec=NULL; // override video codec 67 char *video_codec=NULL; // override video codec
66 int audio_family=-1; // override audio codec family 68 int audio_family=-1; // override audio codec family
67 int video_family=-1; // override video codec family 69 int video_family=-1; // override video codec family
68 70
71 #ifdef HAVE_MP3LAME
69 int out_audio_codec=ACODEC_VBRMP3; 72 int out_audio_codec=ACODEC_VBRMP3;
73 #else
74 int out_audio_codec=ACODEC_PCM;
75 #endif
76
70 int out_video_codec=VCODEC_DIVX4; 77 int out_video_codec=VCODEC_DIVX4;
71 78
72 // audio stream skip/resync functions requires only for seeking. 79 // audio stream skip/resync functions requires only for seeking.
73 // (they should be implemented in the audio codec layer) 80 // (they should be implemented in the audio codec layer)
74 //void skip_audio_frame(sh_audio_t *sh_audio){} 81 //void skip_audio_frame(sh_audio_t *sh_audio){}
109 //#include "libmpeg2/mpeg2_internal.h" 116 //#include "libmpeg2/mpeg2_internal.h"
110 117
111 ENC_PARAM divx4_param; 118 ENC_PARAM divx4_param;
112 int divx4_crispness=100; 119 int divx4_crispness=100;
113 120
121 #ifdef HAVE_MP3LAME
114 int lame_param_quality=0; // best 122 int lame_param_quality=0; // best
115 int lame_param_vbr=vbr_default; 123 int lame_param_vbr=vbr_default;
116 int lame_param_mode=-1; // unset 124 int lame_param_mode=-1; // unset
117 int lame_param_padding=-1; // unset 125 int lame_param_padding=-1; // unset
118 int lame_param_br=-1; // unset 126 int lame_param_br=-1; // unset
119 int lame_param_ratio=-1; // unset 127 int lame_param_ratio=-1; // unset
128 #endif
120 129
121 static int scale_srcW=0; 130 static int scale_srcW=0;
122 static int scale_srcH=0; 131 static int scale_srcH=0;
123 static int vo_w=0, vo_h=0; 132 static int vo_w=0, vo_h=0;
124 //-------------------------- config stuff: 133 //-------------------------- config stuff:
264 273
265 ENC_FRAME enc_frame; 274 ENC_FRAME enc_frame;
266 ENC_RESULT enc_result; 275 ENC_RESULT enc_result;
267 void* enc_handle=NULL; 276 void* enc_handle=NULL;
268 277
278 #ifdef HAVE_MP3LAME
269 lame_global_flags *lame; 279 lame_global_flags *lame;
280 #endif
270 281
271 float audio_preload=0.5; 282 float audio_preload=0.5;
272 283
273 double v_pts_corr=0; 284 double v_pts_corr=0;
274 double v_timer_corr=0; 285 double v_timer_corr=0;
600 break; 611 break;
601 } 612 }
602 break; 613 break;
603 } 614 }
604 615
605 #if 1
606 if(sh_audio) 616 if(sh_audio)
607 switch(mux_a->codec){ 617 switch(mux_a->codec){
618 #ifdef HAVE_MP3LAME
608 case ACODEC_VBRMP3: 619 case ACODEC_VBRMP3:
609 620
610 lame=lame_init(); 621 lame=lame_init();
611 lame_set_bWriteVbrTag(lame,0); 622 lame_set_bWriteVbrTag(lame,0);
612 lame_set_in_samplerate(lame,sh_audio->samplerate); 623 lame_set_in_samplerate(lame,sh_audio->samplerate);
625 lame_init_params(lame); 636 lame_init_params(lame);
626 if(verbose){ 637 if(verbose){
627 lame_print_config(lame); 638 lame_print_config(lame);
628 lame_print_internals(lame); 639 lame_print_internals(lame);
629 } 640 }
641 break;
642 #endif
630 643
631 } 644 }
632 #endif
633 645
634 signal(SIGINT,exit_sighandler); // Interrupt from keyboard 646 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
635 signal(SIGQUIT,exit_sighandler); // Quit from keyboard 647 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
636 signal(SIGTERM,exit_sighandler); // kill 648 signal(SIGTERM,exit_sighandler); // kill
637 649
672 // VBR - encode/copy an audio frame 684 // VBR - encode/copy an audio frame
673 switch(mux_a->codec){ 685 switch(mux_a->codec){
674 case 0: // copy 686 case 0: // copy
675 printf("not yet implemented!\n"); 687 printf("not yet implemented!\n");
676 break; 688 break;
689 #ifdef HAVE_MP3LAME
677 case ACODEC_VBRMP3: 690 case ACODEC_VBRMP3:
678 while(mux_a->buffer_len<4){ 691 while(mux_a->buffer_len<4){
679 unsigned char tmp[2304]; 692 unsigned char tmp[2304];
680 int len=dec_audio(sh_audio,tmp,2304); 693 int len=dec_audio(sh_audio,tmp,2304);
681 if(len<=0) break; // eof 694 if(len<=0) break; // eof
698 mux_a->buffer+mux_a->buffer_len,mux_a->buffer_size-mux_a->buffer_len); 711 mux_a->buffer+mux_a->buffer_len,mux_a->buffer_size-mux_a->buffer_len);
699 if(len<0) break; // error 712 if(len<0) break; // error
700 mux_a->buffer_len+=len; 713 mux_a->buffer_len+=len;
701 } 714 }
702 break; 715 break;
716 #endif
703 } 717 }
704 } 718 }
705 if(len<=0) break; // EOF? 719 if(len<=0) break; // EOF?
706 aviwrite_write_chunk(muxer,mux_a,muxer_f,len,0); 720 aviwrite_write_chunk(muxer,mux_a,muxer_f,len,0);
707 if(!mux_a->h.dwSampleSize && mux_a->timer>0) 721 if(!mux_a->h.dwSampleSize && mux_a->timer>0)
854 868
855 869
856 870
857 } // while(!eof) 871 } // while(!eof)
858 872
859 // fixup CBR audio header: 873 #ifdef HAVE_MP3LAME
874 // fixup CBR mp3 audio header:
860 if(sh_audio && mux_a->codec==ACODEC_VBRMP3 && !lame_param_vbr){ 875 if(sh_audio && mux_a->codec==ACODEC_VBRMP3 && !lame_param_vbr){
861 mux_a->h.dwSampleSize=1; 876 mux_a->h.dwSampleSize=1;
862 mux_a->h.dwRate=mux_a->wf->nAvgBytesPerSec; 877 mux_a->h.dwRate=mux_a->wf->nAvgBytesPerSec;
863 mux_a->h.dwScale=1; 878 mux_a->h.dwScale=1;
864 printf("\n\nCBR audio effective bitrate: %8.3f kbit/s (%d bytes/sec)\n", 879 printf("\n\nCBR audio effective bitrate: %8.3f kbit/s (%d bytes/sec)\n",
865 mux_a->h.dwRate*8.0f/1000.0f,mux_a->h.dwRate); 880 mux_a->h.dwRate*8.0f/1000.0f,mux_a->h.dwRate);
866 } 881 }
882 #endif
867 883
868 printf("\nWriting AVI index...\n"); 884 printf("\nWriting AVI index...\n");
869 aviwrite_write_index(muxer,muxer_f); 885 aviwrite_write_index(muxer,muxer_f);
870 printf("Fixup AVI header...\n"); 886 printf("Fixup AVI header...\n");
871 fseek(muxer_f,0,SEEK_SET); 887 fseek(muxer_f,0,SEEK_SET);