#define VCODEC_COPY 0
#define VCODEC_FRAMENO 1
#define VCODEC_DIVX4 2
#define VCODEC_RAW 3
#define VCODEC_LIBAVCODEC 4
#define VCODEC_NULL 5
#define ACODEC_COPY 0
#define ACODEC_PCM 1
#define ACODEC_VBRMP3 2
#define ACODEC_NULL 3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "config.h"
#include "mp_msg.h"
#include "version.h"
#include "help_mp.h"
static char* banner_text=
"\n\n"
"MEncoder " VERSION "(C) 2000-2001 Arpad Gereoffy (see DOCS!)\n"
"\n";
#include "cpudetect.h"
#include "codec-cfg.h"
#include "cfgparser.h"
#include "stream.h"
#include "demuxer.h"
#include "stheader.h"
#include "playtree.h"
#include "aviwrite.h"
#ifdef USE_LIBVO2
#include "libvo2/libvo2.h"
#else
#include "libvo/video_out.h"
#endif
#include "dec_audio.h"
#include "dec_video.h"
#ifdef HAVE_DIVX4ENCORE
#include <encore2.h>
#include "divx4_vbr.h"
#endif
#ifdef HAVE_MP3LAME
#include <lame/lame.h>
#endif
#ifdef USE_LIBAVCODEC
#ifdef USE_LIBAVCODEC_SO
#include <libffmpeg/avcodec.h>
#else
#include "libavcodec/avcodec.h"
#endif
extern int avcodec_inited;
/* for video encoder */
static AVCodec *lavc_venc_codec=NULL;
static AVCodecContext lavc_venc_context;
static AVPicture lavc_venc_picture;
/* video options */
char *lavc_param_vcodec = NULL;
int lavc_param_vbitrate = -1;
int lavc_param_vhq = 0; /* default is realtime encoding */
int lavc_param_vme = 3;
int lavc_param_vqscale = 0;
int lavc_param_keyint = -1;
#endif
#ifdef HAVE_LIBCSS
#include "libmpdemux/dvdauth.h"
#endif
#include <inttypes.h>
#include "../postproc/swscale.h"
#include "fastmemcpy.h"
/**************************************************************************
Video accelerated architecture
**************************************************************************/
vo_vaa_t vo_vaa;
//--------------------------
// cache2:
static int stream_cache_size=0;
#ifdef USE_STREAM_CACHE
extern int cache_fill_status;
#else
#define cache_fill_status 0
#endif
int vcd_track=0;
int audio_id=-1;
int video_id=-1;
int dvdsub_id=-1;
static int has_audio=1;
char *audio_codec=NULL; // override audio codec
char *video_codec=NULL; // override video codec
int audio_family=-1; // override audio codec family
int video_family=-1; // override video codec family
#ifdef HAVE_MP3LAME
int out_audio_codec=ACODEC_VBRMP3;
#else
int out_audio_codec=ACODEC_PCM;
#endif
int out_video_codec=VCODEC_DIVX4;
// audio stream skip/resync functions requires only for seeking.
// (they should be implemented in the audio codec layer)
//void skip_audio_frame(sh_audio_t *sh_audio){}
//void resync_audio_stream(sh_audio_t *sh_audio){}
int verbose=0; // must be global!
double video_time_usage=0;
double vout_time_usage=0;
static double audio_time_usage=0;
static int total_time_usage_start=0;
static int benchmark=0;
// A-V sync:
int delay_corrected=1;
static float default_max_pts_correction=-1;//0.01f;
static float max_pts_correction=0;//default_max_pts_correction;
static float c_total=0;
float force_fps=0;
float force_ofps=0; // set to 24 for inverse telecine
int force_srate=0;
char* out_filename="test.avi";
char* mp3_filename=NULL;
char* ac3_filename=NULL;
char *force_fourcc=NULL;
#ifdef HAVE_DIVX4ENCORE
static int pass=0;
static char* passtmpfile="divx2pass.log";
int pass_working=0;
#endif
static int play_n_frames=-1;
//char *out_audio_codec=NULL; // override audio codec
//char *out_video_codec=NULL; // override video codec
//#include "libmpeg2/mpeg2.h"
//#include "libmpeg2/mpeg2_internal.h"
#ifdef HAVE_DIVX4ENCORE
ENC_PARAM divx4_param;
int divx4_crispness=100;
#endif
#ifdef HAVE_MP3LAME
int lame_param_quality=0; // best
int lame_param_vbr=vbr_default;
int lame_param_mode=-1; // unset
int lame_param_padding=-1; // unset
int lame_param_br=-1; // unset
int lame_param_ratio=-1; // unset
#endif
static int scale_srcW=0;
static int scale_srcH=0;
static int vo_w=0, vo_h=0;
//-------------------------- config stuff:
m_config_t* mconfig;
static int cfg_inc_verbose(struct config *conf){ ++verbose; return 0;}
static int cfg_include(struct config *conf, char *filename){
return m_config_parse_config_file(mconfig, filename);
}
static int parse_end_at(struct config *conf, const char* param);
#include "get_path.c"
#include "cfg-mplayer-def.h"
#include "cfg-mencoder.h"
#ifdef USE_DVDREAD
#include "spudec.h"
#endif
//---------------------------------------------------------------------------
// mini dummy libvo:
static unsigned char* vo_image=NULL;
static unsigned char* vo_image_ptr=NULL;
static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h, int x0,int y0){
int y;
// printf("draw_slice %dx%d %d;%d\n",w,h,x0,y0);
if(scale_srcW || scale_srcH)
{
uint8_t* dstPtr[3]= {
vo_image,
vo_image + vo_w*vo_h*5/4,
vo_image + vo_w*vo_h};
SwScale_YV12slice(src, stride, y0, h, dstPtr, vo_w, 12, scale_srcW, scale_srcH, vo_w, vo_h);
}
else
{
// copy Y:
for(y=0;y<h;y++){
unsigned char* s=src[0]+stride[0]*y;
unsigned char* d=vo_image+vo_w*(y0+y)+x0;
memcpy(d,s,w);
}
x0>>=1;y0>>=1;
w>>=1;h>>=1;
// copy U:
for(y=0;y<h;y++){
unsigned char* s=src[2]+stride[2]*y;
unsigned char* d=vo_image+vo_w*vo_h+(vo_w>>1)*(y0+y)+x0;
memcpy(d,s,w);
}
// copy V:
for(y=0;y<h;y++){
unsigned char* s=src[1]+stride[1]*y;
unsigned char* d=vo_image+vo_w*vo_h+vo_w*vo_h/4+(vo_w>>1)*(y0+y)+x0;
memcpy(d,s,w);
}
} // !swscaler
return(0);
}
static uint32_t draw_frame(uint8_t *src[]){
// printf("This function shouldn't be called - report bug!\n");
// later: add YUY2->YV12 conversion here!
vo_image_ptr=src[0];
return(0);
}
vo_functions_t video_out;
//---------------------------------------------------------------------------
void *vo_spudec=NULL;
static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
vo_draw_alpha_yv12(w,h,src,srca,stride,vo_image + vo_w * y0 + x0,vo_w);
}
static void draw_sub(void) {
#ifdef USE_DVDREAD
if (vo_spudec)
spudec_draw_scaled(vo_spudec, vo_w, vo_h, draw_alpha);
#endif
}
int dec_audio(sh_audio_t *sh_audio,unsigned char* buffer,int total){
int size=0;
int eof=0;
while(size<total && !eof){
int len=total-size;
if(len>MAX_OUTBURST) len=MAX_OUTBURST;
if(len>sh_audio->a_buffer_size) len=sh_audio->a_buffer_size;
if(len>sh_audio->a_buffer_len){
int ret=decode_audio(sh_audio,
&sh_audio->a_buffer[sh_audio->a_buffer_len],
len-sh_audio->a_buffer_len,
sh_audio->a_buffer_size-sh_audio->a_buffer_len);
if(ret
|