comparison mencoder.c @ 3663:9092546e7765

made divx4 optional (also configure checking needed) and added avcodec_close
author alex
date Sat, 22 Dec 2001 16:59:10 +0000
parents af1f8e2d693a
children ec943f8ec439
comparison
equal deleted inserted replaced
3662:1e0052d8c532 3663:9092546e7765
1 #define HAVE_DIVX4ENCORE /* FIXME!! add it to configure */
2
1 #define VCODEC_COPY 0 3 #define VCODEC_COPY 0
2 #define VCODEC_FRAMENO 1 4 #define VCODEC_FRAMENO 1
3 #define VCODEC_DIVX4 2 5 #define VCODEC_DIVX4 2
4 #define VCODEC_RAW 3 6 #define VCODEC_RAW 3
5 #define VCODEC_LIBAVCODEC 4 7 #define VCODEC_LIBAVCODEC 4
23 "MEncoder " VERSION "(C) 2000-2001 Arpad Gereoffy (see DOCS!)\n" 25 "MEncoder " VERSION "(C) 2000-2001 Arpad Gereoffy (see DOCS!)\n"
24 "\n"; 26 "\n";
25 27
26 #include "cpudetect.h" 28 #include "cpudetect.h"
27 29
28
29 #include "codec-cfg.h" 30 #include "codec-cfg.h"
30 31
31 #include "stream.h" 32 #include "stream.h"
32 #include "demuxer.h" 33 #include "demuxer.h"
33 #include "stheader.h" 34 #include "stheader.h"
41 #endif 42 #endif
42 43
43 #include "dec_audio.h" 44 #include "dec_audio.h"
44 #include "dec_video.h" 45 #include "dec_video.h"
45 46
47 #ifdef HAVE_DIVX4ENCORE
46 #include <encore2.h> 48 #include <encore2.h>
47 #include "divx4_vbr.h" 49 #include "divx4_vbr.h"
50 #endif
48 51
49 #ifdef HAVE_MP3LAME 52 #ifdef HAVE_MP3LAME
50 #include <lame/lame.h> 53 #include <lame/lame.h>
51 #endif 54 #endif
52 55
132 char* mp3_filename=NULL; 135 char* mp3_filename=NULL;
133 char* ac3_filename=NULL; 136 char* ac3_filename=NULL;
134 137
135 char *force_fourcc=NULL; 138 char *force_fourcc=NULL;
136 139
140 #ifdef HAVE_DIVX4ENCORE
137 static int pass=0; 141 static int pass=0;
138 static char* passtmpfile="divx2pass.log"; 142 static char* passtmpfile="divx2pass.log";
139 int pass_working=0; 143 int pass_working=0;
144 #endif
140 145
141 static int play_n_frames=-1; 146 static int play_n_frames=-1;
142 147
143 //char *out_audio_codec=NULL; // override audio codec 148 //char *out_audio_codec=NULL; // override audio codec
144 //char *out_video_codec=NULL; // override video codec 149 //char *out_video_codec=NULL; // override video codec
145 150
146 //#include "libmpeg2/mpeg2.h" 151 //#include "libmpeg2/mpeg2.h"
147 //#include "libmpeg2/mpeg2_internal.h" 152 //#include "libmpeg2/mpeg2_internal.h"
148 153
154 #ifdef HAVE_DIVX4ENCORE
149 ENC_PARAM divx4_param; 155 ENC_PARAM divx4_param;
150 int divx4_crispness=100; 156 int divx4_crispness=100;
157 #endif
151 158
152 #ifdef HAVE_MP3LAME 159 #ifdef HAVE_MP3LAME
153 int lame_param_quality=0; // best 160 int lame_param_quality=0; // best
154 int lame_param_vbr=vbr_default; 161 int lame_param_vbr=vbr_default;
155 int lame_param_mode=-1; // unset 162 int lame_param_mode=-1; // unset
300 aviwrite_t* muxer=NULL; 307 aviwrite_t* muxer=NULL;
301 aviwrite_stream_t* mux_a=NULL; 308 aviwrite_stream_t* mux_a=NULL;
302 aviwrite_stream_t* mux_v=NULL; 309 aviwrite_stream_t* mux_v=NULL;
303 FILE* muxer_f=NULL; 310 FILE* muxer_f=NULL;
304 311
312 #ifdef HAVE_DIVX4ENCORE
305 ENC_FRAME enc_frame; 313 ENC_FRAME enc_frame;
306 ENC_RESULT enc_result; 314 ENC_RESULT enc_result;
307 void* enc_handle=NULL; 315 void* enc_handle=NULL;
316 #endif
308 317
309 #ifdef HAVE_MP3LAME 318 #ifdef HAVE_MP3LAME
310 lame_global_flags *lame; 319 lame_global_flags *lame;
311 #endif 320 #endif
312 321
342 gCpuCaps.cpuType,gCpuCaps.hasMMX,gCpuCaps.hasMMX2, 351 gCpuCaps.cpuType,gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
343 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt, 352 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
344 gCpuCaps.hasSSE, gCpuCaps.hasSSE2); 353 gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
345 #endif 354 #endif
346 355
347 356 #ifdef HAVE_DIVX4ENCORE
348 // set some defaults, before parsing configfile/commandline: 357 // set some defaults, before parsing configfile/commandline:
349 divx4_param.min_quantizer = 2; 358 divx4_param.min_quantizer = 2;
350 divx4_param.max_quantizer = 31; 359 divx4_param.max_quantizer = 31;
351 divx4_param.rc_period = 2000; 360 divx4_param.rc_period = 2000;
352 divx4_param.rc_reaction_period = 10; 361 divx4_param.rc_reaction_period = 10;
353 divx4_param.rc_reaction_ratio = 20; 362 divx4_param.rc_reaction_ratio = 20;
354 363 #endif
355 364
356 num_filenames=parse_command_line(conf, argc, argv, envp, &filenames); 365 num_filenames=parse_command_line(conf, argc, argv, envp, &filenames);
357 if(num_filenames<0) exit(1); // error parsing cmdline 366 if(num_filenames<0) exit(1); // error parsing cmdline
358 if(!num_filenames && !vcd_track && !dvd_title && !tv_param_on){ 367 if(!num_filenames && !vcd_track && !dvd_title && !tv_param_on){
359 printf("\nMissing filename!\n\n"); 368 printf("\nMissing filename!\n\n");
586 mux_v->bih->biBitCount=24; 595 mux_v->bih->biBitCount=24;
587 mux_v->bih->biCompression=mmioFOURCC('F','r','N','o'); 596 mux_v->bih->biCompression=mmioFOURCC('F','r','N','o');
588 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); 597 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
589 break; 598 break;
590 case VCODEC_DIVX4: 599 case VCODEC_DIVX4:
600 #ifndef HAVE_DIVX4ENCORE
601 printf("No support for Divx4 encore compiled in\n");
602 return 0; /* FIXME */
603 #else
591 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); 604 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER));
592 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); 605 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
593 mux_v->bih->biWidth=vo_w; 606 mux_v->bih->biWidth=vo_w;
594 mux_v->bih->biHeight=vo_h; 607 mux_v->bih->biHeight=vo_h;
595 mux_v->bih->biPlanes=1; 608 mux_v->bih->biPlanes=1;
598 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); 611 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
599 612
600 if (pass) 613 if (pass)
601 printf("Divx: 2-pass logfile: %s\n", passtmpfile); 614 printf("Divx: 2-pass logfile: %s\n", passtmpfile);
602 break; 615 break;
616 #endif
603 case VCODEC_LIBAVCODEC: 617 case VCODEC_LIBAVCODEC:
604 #ifndef USE_LIBAVCODEC 618 #ifndef USE_LIBAVCODEC
605 printf("No support for FFmpeg's libavcodec compiled in\n"); 619 printf("No support for FFmpeg's libavcodec compiled in\n");
620 return 0; /* FIXME */
606 #else 621 #else
607 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); 622 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER));
608 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); 623 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
609 mux_v->bih->biWidth=vo_w; 624 mux_v->bih->biWidth=vo_w;
610 mux_v->bih->biHeight=vo_h; 625 mux_v->bih->biHeight=vo_h;
711 break; 726 break;
712 case VCODEC_FRAMENO: 727 case VCODEC_FRAMENO:
713 decoded_frameno=0; 728 decoded_frameno=0;
714 break; 729 break;
715 case VCODEC_DIVX4: 730 case VCODEC_DIVX4:
731 #ifndef HAVE_DIVX4ENCORE
732 printf("No support for Divx4 encore compiled in\n");
733 return 0; /* FIXME */
734 #else
716 // init divx4linux: 735 // init divx4linux:
717 divx4_param.x_dim=vo_w; 736 divx4_param.x_dim=vo_w;
718 divx4_param.y_dim=vo_h; 737 divx4_param.y_dim=vo_h;
719 divx4_param.framerate=(float)mux_v->h.dwRate/mux_v->h.dwScale; 738 divx4_param.framerate=(float)mux_v->h.dwRate/mux_v->h.dwScale;
720 if(!divx4_param.bitrate) divx4_param.bitrate=800000; 739 if(!divx4_param.bitrate) divx4_param.bitrate=800000;
759 else 778 else
760 pass_working = 1; 779 pass_working = 1;
761 break; 780 break;
762 } 781 }
763 break; 782 break;
783 #endif
764 case VCODEC_LIBAVCODEC: 784 case VCODEC_LIBAVCODEC:
765 #ifndef USE_LIBAVCODEC 785 #ifndef USE_LIBAVCODEC
766 printf("No support for FFmpeg's libavcodec compiled in\n"); 786 printf("No support for FFmpeg's libavcodec compiled in\n");
767 #else 787 #else
768 if (!avcodec_inited) 788 if (!avcodec_inited)
838 lavc_venc_context.pix_fmt = PIX_FMT_YUV420P; 858 lavc_venc_context.pix_fmt = PIX_FMT_YUV420P;
839 break; 859 break;
840 case IMGFMT_UYVY: 860 case IMGFMT_UYVY:
841 lavc_venc_context.pix_fmt = PIX_FMT_YUV422; 861 lavc_venc_context.pix_fmt = PIX_FMT_YUV422;
842 break; 862 break;
843 #if 0 /* it's faulting :( */ 863 #if 0 /* it's faulting :( -- libavcodec's bug! -- alex */
844 case IMGFMT_BGR24: 864 case IMGFMT_BGR24:
845 lavc_venc_context.pix_fmt = PIX_FMT_BGR24; 865 lavc_venc_context.pix_fmt = PIX_FMT_BGR24;
846 break; 866 break;
847 #endif
848 case IMGFMT_RGB24: 867 case IMGFMT_RGB24:
849 lavc_venc_context.pix_fmt = PIX_FMT_RGB24; 868 lavc_venc_context.pix_fmt = PIX_FMT_RGB24;
850 break; 869 break;
870 #endif
851 default: 871 default:
852 printf("Not supported image format! (%s)\n", 872 printf("Not supported image format! (%s)\n",
853 vo_format_name(out_fmt)); 873 vo_format_name(out_fmt));
854 return 0; /* FIXME */ 874 return 0; /* FIXME */
855 } 875 }
863 883
864 { 884 {
865 char buf[1024]; 885 char buf[1024];
866 886
867 avcodec_string((char *)&buf[0], 1023, &lavc_venc_context, 1); 887 avcodec_string((char *)&buf[0], 1023, &lavc_venc_context, 1);
868 printf(buf); 888 printf("%s\n", buf);
869 } 889 }
870 #endif 890 #endif
871 } 891 }
872 892
873 if(sh_audio) 893 if(sh_audio)
1034 case VCODEC_FRAMENO: 1054 case VCODEC_FRAMENO:
1035 mux_v->buffer=&decoded_frameno; // tricky 1055 mux_v->buffer=&decoded_frameno; // tricky
1036 if(skip_flag<=0) aviwrite_write_chunk(muxer,mux_v,muxer_f,sizeof(int),0x10); 1056 if(skip_flag<=0) aviwrite_write_chunk(muxer,mux_v,muxer_f,sizeof(int),0x10);
1037 break; 1057 break;
1038 case VCODEC_DIVX4: 1058 case VCODEC_DIVX4:
1059 #ifndef HAVE_DIVX4ENCORE
1060 printf("No support for Divx4 encore compiled in\n");
1061 return 0; /* FIXME */
1062 #else
1039 blit_frame=decode_video(&video_out,sh_video,start,in_size,0); 1063 blit_frame=decode_video(&video_out,sh_video,start,in_size,0);
1040 if(skip_flag>0) break; 1064 if(skip_flag>0) break;
1041 if(!blit_frame){ 1065 if(!blit_frame){
1042 // empty. 1066 // empty.
1043 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); 1067 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0);
1069 1093
1070 // printf("encoding...\n"); 1094 // printf("encoding...\n");
1071 // printf(" len=%d key:%d qualt:%d \n",enc_frame.length,enc_result.is_key_frame,enc_result.quantizer); 1095 // printf(" len=%d key:%d qualt:%d \n",enc_frame.length,enc_result.is_key_frame,enc_result.quantizer);
1072 aviwrite_write_chunk(muxer,mux_v,muxer_f,enc_frame.length,enc_result.is_key_frame?0x10:0); 1096 aviwrite_write_chunk(muxer,mux_v,muxer_f,enc_frame.length,enc_result.is_key_frame?0x10:0);
1073 break; 1097 break;
1098 #endif
1074 case VCODEC_LIBAVCODEC: 1099 case VCODEC_LIBAVCODEC:
1075 { 1100 {
1076 #ifndef USE_LIBAVCODEC 1101 #ifndef USE_LIBAVCODEC
1077 printf("No support for FFmpeg's libavcodec compiled in\n"); 1102 printf("No support for FFmpeg's libavcodec compiled in\n");
1078 #else 1103 #else
1172 printf("\n\nCBR audio effective bitrate: %8.3f kbit/s (%d bytes/sec)\n", 1197 printf("\n\nCBR audio effective bitrate: %8.3f kbit/s (%d bytes/sec)\n",
1173 mux_a->h.dwRate*8.0f/1000.0f,mux_a->h.dwRate); 1198 mux_a->h.dwRate*8.0f/1000.0f,mux_a->h.dwRate);
1174 } 1199 }
1175 #endif 1200 #endif
1176 1201
1202 #ifdef USE_LIBAVCODEC
1203 if (mux_v->codec == VCODEC_LIBAVCODEC)
1204 avcodec_close(&lavc_venc_context);
1205 #endif
1206
1177 printf("\nWriting AVI index...\n"); 1207 printf("\nWriting AVI index...\n");
1178 aviwrite_write_index(muxer,muxer_f); 1208 aviwrite_write_index(muxer,muxer_f);
1179 printf("Fixup AVI header...\n"); 1209 printf("Fixup AVI header...\n");
1180 fseek(muxer_f,0,SEEK_SET); 1210 fseek(muxer_f,0,SEEK_SET);
1181 aviwrite_write_header(muxer,muxer_f); // update header 1211 aviwrite_write_header(muxer,muxer_f); // update header