diff --git a/libmpcodecs/Makefile b/libmpcodecs/Makefile index c6d14286db..e0975d5fd2 100644 --- a/libmpcodecs/Makefile +++ b/libmpcodecs/Makefile @@ -2,10 +2,12 @@ include ../config.mak LIBNAME = libmpcodecs.a +LIBNAME2 = libmpencoders.a AUDIO_SRCS=dec_audio.c ad.c ad_a52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dk4adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_vorbis.c ad_libmad.c VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c vd_msrle.c vd_huffyuv.c vd_zlib.c vd_mpegpes.c VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_fame.c vf_format.c vf_yuy2.c +ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ifeq ($(PNG),yes) VIDEO_SRCS += vd_mpng.c @@ -15,9 +17,12 @@ ifeq ($(JPEG),yes) VIDEO_SRCS += vd_ijpg.c endif -SRCS=$(AUDIO_SRCS) $(VIDEO_SRCS) $(VFILTER_SRCS) +SRCS=$(AUDIO_SRCS) $(VIDEO_SRCS) $(VFILTER_SRCS) $(ENCODER_SRCS) OBJS=$(SRCS:.c=.o) +SRCS2=$(ENCODER_SRCS) +OBJS2=$(SRCS2:.c=.o) + CFLAGS = -Wall $(OPTFLAGS) -I. -I.. -I../libmpdemux -I../loader $(EXTRA_INC) .SUFFIXES: .c .o @@ -27,10 +32,13 @@ CFLAGS = -Wall $(OPTFLAGS) -I. -I.. -I../libmpdemux -I../loader $(EXTRA_INC) .c.o: $(CC) -c $(CFLAGS) -o $@ $< +all: $(LIBNAME) $(LIBNAME2) + $(LIBNAME): $(OBJS) $(AR) r $(LIBNAME) $(OBJS) -all: $(LIBNAME) +$(LIBNAME2): $(OBJS2) + $(AR) r $(LIBNAME2) $(OBJS2) clean: rm -f *.o *.a *~ @@ -41,7 +49,7 @@ distclean: dep: depend depend: - $(CC) -MM $(CFLAGS) $(SRCS) 1>.depend + $(CC) -MM $(CFLAGS) $(SRCS) $(SRCS2) 1>.depend # # include dependency files if they exist diff --git a/libmpcodecs/ve.c b/libmpcodecs/ve.c new file mode 100644 index 0000000000..c12fa8d502 --- /dev/null +++ b/libmpcodecs/ve.c @@ -0,0 +1,34 @@ +#include +#include +#include + +#include "../config.h" +#include "../mp_msg.h" + +#include "../libvo/img_format.h" +#include "../mp_image.h" +#include "vf.h" + +extern vf_info_t ve_info_divx4; +extern vf_info_t ve_info_lavc; +extern vf_info_t ve_info_vfw; +extern vf_info_t ve_info_rawrgb; + +static vf_info_t* encoder_list[]={ +#ifdef HAVE_DIVX4ENCORE + &ve_info_divx4, +#endif +#ifdef USE_LIBAVCODEC + &ve_info_lavc, +#endif +#ifdef USE_WIN32DLL + &ve_info_vfw, +#endif + &ve_info_rawrgb, + NULL +}; + +vf_instance_t* vf_open_encoder(vf_instance_t* next, char *name, char *args){ + return vf_open_plugin(encoder_list,next,name,args); +} + diff --git a/libmpcodecs/ve_divx4.c b/libmpcodecs/ve_divx4.c new file mode 100644 index 0000000000..c272efbe1f --- /dev/null +++ b/libmpcodecs/ve_divx4.c @@ -0,0 +1,194 @@ +#include +#include +#include + +#include "../config.h" +#include "../mp_msg.h" + +#ifdef HAVE_DIVX4ENCORE + +#include "codec-cfg.h" +#include "stream.h" +#include "demuxer.h" +#include "stheader.h" + +#include "aviwrite.h" + +#include "../libvo/img_format.h" +#include "../mp_image.h" +#include "vf.h" + +//===========================================================================// + +#include "divx4_vbr.h" + +extern int pass; +extern char* passtmpfile; + +#include + +ENC_PARAM divx4_param; +int divx4_crispness; + +#include "cfgparser.h" + +struct config divx4opts_conf[]={ + {"br", &divx4_param.bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, + {"rc_period", &divx4_param.rc_period, CONF_TYPE_INT, 0,0,0, NULL}, + {"rc_reaction_period", &divx4_param.rc_reaction_period, CONF_TYPE_INT, 0,0,0, NULL}, + {"rc_reaction_ratio", &divx4_param.rc_reaction_ratio, CONF_TYPE_INT, 0,0,0, NULL}, + {"min_quant", &divx4_param.min_quantizer, CONF_TYPE_INT, CONF_RANGE,0,32, NULL}, + {"max_quant", &divx4_param.max_quantizer, CONF_TYPE_INT, CONF_RANGE,0,32, NULL}, + {"key", &divx4_param.max_key_interval, CONF_TYPE_INT, CONF_MIN,0,0, NULL}, + {"deinterlace", &divx4_param.deinterlace, CONF_TYPE_FLAG, 0,0,1, NULL}, + {"q", &divx4_param.quality, CONF_TYPE_INT, CONF_RANGE, 1, 5, NULL}, + {"crispness", &divx4_crispness, CONF_TYPE_INT, CONF_RANGE,0,100, NULL}, + {"help", "TODO: divx4opts help!\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL}, + {NULL, NULL, 0, 0, 0, 0, NULL} +}; + +struct vf_priv_s { + aviwrite_stream_t* mux; + ENC_RESULT enc_result; + ENC_FRAME enc_frame; + void* enc_handle; +}; + +#define mux_v (vf->priv->mux) + +static int config(struct vf_instance_s* vf, + int width, int height, int d_width, int d_height, + unsigned int flags, unsigned int outfmt){ + + mux_v->bih->biWidth=width; + mux_v->bih->biHeight=height; + + divx4_param.x_dim=width; + divx4_param.y_dim=height; + divx4_param.framerate=(float)mux_v->h.dwRate/mux_v->h.dwScale; + mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*3; + + if(!divx4_param.bitrate) divx4_param.bitrate=800000; + else if(divx4_param.bitrate<=16000) divx4_param.bitrate*=1000; + if(!divx4_param.quality) divx4_param.quality=5; // the quality of compression ( 1 - fastest, 5 - best ) + + divx4_param.handle=NULL; + encore(NULL,ENC_OPT_INIT,&divx4_param,NULL); + vf->priv->enc_handle=divx4_param.handle; + switch(outfmt){ + case IMGFMT_YV12: vf->priv->enc_frame.colorspace=ENC_CSP_YV12; break; + case IMGFMT_IYUV: + case IMGFMT_I420: vf->priv->enc_frame.colorspace=ENC_CSP_I420; break; + case IMGFMT_YUY2: vf->priv->enc_frame.colorspace=ENC_CSP_YUY2; break; + case IMGFMT_UYVY: vf->priv->enc_frame.colorspace=ENC_CSP_UYVY; break; + case IMGFMT_RGB24: + case IMGFMT_BGR24: + vf->priv->enc_frame.colorspace=ENC_CSP_RGB24; break; + default: + mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported picture format (%s)!\n", + vo_format_name(outfmt)); + return 0; + } + + switch(pass){ + case 1: + if (VbrControl_init_2pass_vbr_analysis(passtmpfile, divx4_param.quality) == -1){ + mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); + pass=0; + } + break; + case 2: + if (VbrControl_init_2pass_vbr_encoding(passtmpfile, + divx4_param.bitrate, + divx4_param.framerate, + divx4_crispness, + divx4_param.quality) == -1){ + mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); + pass=0; + } + break; + } + + return 1; +} + +static int control(struct vf_instance_s* vf, int request, void* data){ + + return CONTROL_UNKNOWN; +} + +static int query_format(struct vf_instance_s* vf, unsigned int fmt){ + switch(fmt){ + case IMGFMT_YV12: + case IMGFMT_IYUV: + case IMGFMT_I420: + return 3; // no conversion + case IMGFMT_YUY2: + case IMGFMT_UYVY: + case IMGFMT_RGB24: + case IMGFMT_BGR24: + return 1; // conversion + } + return 0; +} + +static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ + ENC_RESULT enc_result; + vf->priv->enc_frame.image=mpi->planes[0]; + vf->priv->enc_frame.bitstream=mux_v->buffer; + vf->priv->enc_frame.length=mux_v->buffer_size; + vf->priv->enc_frame.mvs=NULL; + if(pass==2){ // handle 2-pass: + vf->priv->enc_frame.quant = VbrControl_get_quant(); + vf->priv->enc_frame.intra = VbrControl_get_intra(); + encore(vf->priv->enc_handle,ENC_OPT_ENCODE_VBR,&vf->priv->enc_frame,&enc_result); + VbrControl_update_2pass_vbr_encoding(enc_result.motion_bits, + enc_result.texture_bits, + enc_result.total_bits); + } else { + vf->priv->enc_frame.quant=0; + vf->priv->enc_frame.intra=0; + encore(vf->priv->enc_handle,ENC_OPT_ENCODE,&vf->priv->enc_frame,&enc_result); + if(pass==1){ + VbrControl_update_2pass_vbr_analysis(enc_result.is_key_frame, + enc_result.motion_bits, + enc_result.texture_bits, + enc_result.total_bits, + enc_result.quantizer); + } + } + mencoder_write_frame(mux_v,vf->priv->enc_frame.length,enc_result.is_key_frame?0x10:0); +} + +//===========================================================================// + +static int vf_open(vf_instance_t *vf, char* args){ + vf->config=config; + vf->control=control; + vf->query_format=query_format; + vf->put_image=put_image; + vf->priv=malloc(sizeof(struct vf_priv_s)); + memset(vf->priv,0,sizeof(struct vf_priv_s)); + vf->priv->mux=args; + + mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); + mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); + mux_v->bih->biWidth=0; + mux_v->bih->biHeight=0; + mux_v->bih->biPlanes=1; + mux_v->bih->biBitCount=24; + mux_v->bih->biCompression=mmioFOURCC('d','i','v','x'); + + return 1; +} + +vf_info_t ve_info_divx4 = { + "divx4 encoder", + "divx4", + "A'rpi", + "for internal use by mencoder", + vf_open +}; + +//===========================================================================// +#endif diff --git a/libmpcodecs/ve_lavc.c b/libmpcodecs/ve_lavc.c new file mode 100644 index 0000000000..a29104055a --- /dev/null +++ b/libmpcodecs/ve_lavc.c @@ -0,0 +1,291 @@ +#include +#include +#include + +#include "../config.h" + +#ifdef USE_LIBAVCODEC + +#include "../mp_msg.h" +#include "../help_mp.h" + +#include "codec-cfg.h" +#include "stream.h" +#include "demuxer.h" +#include "stheader.h" + +#include "aviwrite.h" + +#include "../libvo/img_format.h" +#include "../mp_image.h" +#include "vf.h" + +#include "divx4_vbr.h" + +extern int pass; +extern char* passtmpfile; + +//===========================================================================// + +#ifdef USE_LIBAVCODEC_SO +#include +#else +#include "libavcodec/avcodec.h" +#endif + +extern int avcodec_inited; + +/* video options */ +static char *lavc_param_vcodec = NULL; +static int lavc_param_vbitrate = -1; +static int lavc_param_vrate_tolerance = 1024*8; +static int lavc_param_vhq = 0; /* default is realtime encoding */ +static int lavc_param_v4mv = 0; +static int lavc_param_vme = 3; +static int lavc_param_vqscale = 0; +static int lavc_param_vqmin = 3; +static int lavc_param_vqmax = 15; +static int lavc_param_vqdiff = 3; +static float lavc_param_vqcompress = 0.5; +static float lavc_param_vqblur = 0.5; +static int lavc_param_keyint = -1; + +#include "cfgparser.h" + +#ifdef USE_LIBAVCODEC +struct config lavcopts_conf[]={ + {"vcodec", &lavc_param_vcodec, CONF_TYPE_STRING, 0, 0, 0, NULL}, + {"vbitrate", &lavc_param_vbitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, + {"vratetol", &lavc_param_vrate_tolerance, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, + {"vhq", &lavc_param_vhq, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + {"v4mv", &lavc_param_v4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + {"vme", &lavc_param_vme, CONF_TYPE_INT, CONF_RANGE, 0, 5, NULL}, + {"vqscale", &lavc_param_vqscale, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, + {"vqmin", &lavc_param_vqmin, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, + {"vqmax", &lavc_param_vqmax, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, + {"vqdiff", &lavc_param_vqdiff, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, + {"vqcomp", &lavc_param_vqcompress, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL}, + {"vqblur", &lavc_param_vqblur, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL}, + {"keyint", &lavc_param_keyint, CONF_TYPE_INT, 0, 0, 0, NULL}, + {NULL, NULL, 0, 0, 0, 0, NULL} +}; +#endif + +struct vf_priv_s { + aviwrite_stream_t* mux; + AVCodecContext context; + AVCodec *codec; +}; + +#define mux_v (vf->priv->mux) +#define lavc_venc_context (vf->priv->context) + +static int config(struct vf_instance_s* vf, + int width, int height, int d_width, int d_height, + unsigned int flags, unsigned int outfmt){ + + mux_v->bih->biWidth=width; + mux_v->bih->biHeight=height; + mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); + + memset(&lavc_venc_context, 0, sizeof(lavc_venc_context)); + + printf("videocodec: libavcodec (%dx%d fourcc=%x [%.4s])\n", + mux_v->bih->biWidth, mux_v->bih->biHeight, mux_v->bih->biCompression, + (char *)&mux_v->bih->biCompression); + + lavc_venc_context.width = width; + lavc_venc_context.height = height; + if (lavc_param_vbitrate >= 0) /* != -1 */ + lavc_venc_context.bit_rate = lavc_param_vbitrate*1000; + else + lavc_venc_context.bit_rate = 800000; /* default */ + lavc_venc_context.bit_rate_tolerance= lavc_param_vrate_tolerance*1000; + lavc_venc_context.frame_rate = (float)mux_v->h.dwRate/mux_v->h.dwScale * FRAME_RATE_BASE; + lavc_venc_context.qmin= lavc_param_vqmin; + lavc_venc_context.qmax= lavc_param_vqmax; + lavc_venc_context.max_qdiff= lavc_param_vqdiff; + lavc_venc_context.qcompress= lavc_param_vqcompress; + lavc_venc_context.qblur= lavc_param_vqblur; + /* keyframe interval */ + if (lavc_param_keyint >= 0) /* != -1 */ + lavc_venc_context.gop_size = lavc_param_keyint; + else + lavc_venc_context.gop_size = 250; /* default */ + + if (lavc_param_vhq) + { + printf("High quality encoding selected (non real time)!\n"); + lavc_venc_context.flags = CODEC_FLAG_HQ; + } + else + lavc_venc_context.flags = 0; + + lavc_venc_context.flags|= lavc_param_v4mv ? CODEC_FLAG_4MV : 0; + + /* motion estimation (0 = none ... 3 = high quality but slow) */ + /* this is just an extern from libavcodec but it should be in the + encoder context - FIXME */ + motion_estimation_method = lavc_param_vme; + + /* fixed qscale :p */ + if (lavc_param_vqscale) + { + printf("Using constant qscale = %d (VBR)\n", lavc_param_vqscale); + lavc_venc_context.flags |= CODEC_FLAG_QSCALE; + lavc_venc_context.quality = lavc_param_vqscale; + } + + switch(pass){ + case 1: + if (VbrControl_init_2pass_vbr_analysis(passtmpfile, 5) == -1){ + mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); + pass=0; + } + break; + case 2: + if (VbrControl_init_2pass_vbr_encoding(passtmpfile, + lavc_venc_context.bit_rate, + (float)mux_v->h.dwRate/mux_v->h.dwScale, + 100, /* crispness */ + 5) == -1){ + mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); + pass=0; + } + break; + } + + if (avcodec_open(&lavc_venc_context, vf->priv->codec) != 0) { + mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); + return 0; + } + + if (lavc_venc_context.codec->encode == NULL) { + mp_msg(MSGT_MENCODER,MSGL_ERR,"avcodec init failed (ctx->codec->encode == NULL)!\n"); + return 0; + } + + return 1; +} + +static int control(struct vf_instance_s* vf, int request, void* data){ + + return CONTROL_UNKNOWN; +} + +static int query_format(struct vf_instance_s* vf, unsigned int fmt){ + switch(fmt){ + case IMGFMT_YV12: + case IMGFMT_IYUV: + case IMGFMT_I420: + return 1; + } + return 0; +} + +static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ + int out_size; + AVPicture lavc_venc_picture; + + lavc_venc_picture.data[0]=mpi->planes[0]; + lavc_venc_picture.data[1]=mpi->planes[1]; + lavc_venc_picture.data[2]=mpi->planes[2]; + lavc_venc_picture.linesize[0]=mpi->stride[0]; + lavc_venc_picture.linesize[1]=mpi->stride[1]; + lavc_venc_picture.linesize[2]=mpi->stride[2]; + + if(pass==2){ // handle 2-pass: + lavc_venc_context.flags|=CODEC_FLAG_QSCALE; // enable VBR + lavc_venc_context.quality=VbrControl_get_quant(); +#ifdef CODEC_FLAG_TYPE + lavc_venc_context.flags|=CODEC_FLAG_TYPE; // force keyframes + lavc_venc_context.key_frame=VbrControl_get_intra(); + lavc_venc_context.gop_size=0x3fffffff; +#else +#error you should upgrade libavcodec... get latest CVS +#endif + out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, + &lavc_venc_picture); + VbrControl_update_2pass_vbr_encoding(lavc_venc_context.mv_bits, + lavc_venc_context.i_tex_bits+lavc_venc_context.p_tex_bits, + 8*out_size); + } else { + out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, + &lavc_venc_picture); + + if(pass==1){ + VbrControl_update_2pass_vbr_analysis(lavc_venc_context.key_frame, + lavc_venc_context.mv_bits, + lavc_venc_context.i_tex_bits+lavc_venc_context.p_tex_bits, + 8*out_size, lavc_venc_context.quality); + } + + } + + mencoder_write_chunk(mux_v,out_size,lavc_venc_context.key_frame?0x10:0); +} + +//===========================================================================// + +static int vf_open(vf_instance_t *vf, char* args){ + vf->config=config; + vf->control=control; + vf->query_format=query_format; + vf->put_image=put_image; + vf->priv=malloc(sizeof(struct vf_priv_s)); + memset(vf->priv,0,sizeof(struct vf_priv_s)); + vf->priv->mux=args; + + mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); + mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); + mux_v->bih->biWidth=0; + mux_v->bih->biHeight=0; + mux_v->bih->biPlanes=1; + mux_v->bih->biBitCount=24; + if (!lavc_param_vcodec) + { + printf("No libavcodec codec specified! It's requested!\n"); + return 0; + } + + if (!strcasecmp(lavc_param_vcodec, "mpeg1") || !strcasecmp(lavc_param_vcodec, "mpeg1video")) + mux_v->bih->biCompression = mmioFOURCC('m', 'p', 'g', '1'); + else if (!strcasecmp(lavc_param_vcodec, "h263") || !strcasecmp(lavc_param_vcodec, "h263p")) + mux_v->bih->biCompression = mmioFOURCC('h', '2', '6', '3'); + else if (!strcasecmp(lavc_param_vcodec, "rv10")) + mux_v->bih->biCompression = mmioFOURCC('R', 'V', '1', '0'); + else if (!strcasecmp(lavc_param_vcodec, "mjpeg")) + mux_v->bih->biCompression = mmioFOURCC('M', 'J', 'P', 'G'); + else if (!strcasecmp(lavc_param_vcodec, "mpeg4")) + mux_v->bih->biCompression = mmioFOURCC('D', 'I', 'V', 'X'); + else if (!strcasecmp(lavc_param_vcodec, "msmpeg4")) + mux_v->bih->biCompression = mmioFOURCC('d', 'i', 'v', '3'); + else + mux_v->bih->biCompression = mmioFOURCC(lavc_param_vcodec[0], + lavc_param_vcodec[1], lavc_param_vcodec[2], lavc_param_vcodec[3]); /* FIXME!!! */ + + if (!avcodec_inited){ + avcodec_init(); + avcodec_register_all(); + avcodec_inited=1; + } + + vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_vcodec); + if (!vf->priv->codec) { + mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, lavc_param_vcodec); + return 0; + } + + return 1; +} + +vf_info_t ve_info_lavc = { + "libavcodec encoder", + "lavc", + "A'rpi", + "for internal use by mencoder", + vf_open +}; + +//===========================================================================// +#endif diff --git a/libmpcodecs/ve_rawrgb.c b/libmpcodecs/ve_rawrgb.c new file mode 100644 index 0000000000..813c66d3b7 --- /dev/null +++ b/libmpcodecs/ve_rawrgb.c @@ -0,0 +1,81 @@ +#include +#include +#include + +#include "../config.h" +#include "../mp_msg.h" + +#include "codec-cfg.h" +#include "stream.h" +#include "demuxer.h" +#include "stheader.h" + +#include "aviwrite.h" + +#include "../libvo/img_format.h" +#include "../mp_image.h" +#include "vf.h" + +//===========================================================================// + +struct vf_priv_s { + aviwrite_stream_t* mux; +}; +#define mux_v (vf->priv->mux) + +static int config(struct vf_instance_s* vf, + int width, int height, int d_width, int d_height, + unsigned int flags, unsigned int outfmt){ + + mux_v->bih->biWidth=width; + mux_v->bih->biHeight=height; + mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); + + return 1; +} + +static int control(struct vf_instance_s* vf, int request, void* data){ + + return CONTROL_UNKNOWN; +} + +static int query_format(struct vf_instance_s* vf, unsigned int fmt){ + if(fmt==IMGFMT_BGR24) return 1; + return 0; +} + +static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ + mux_v->buffer=mpi->planes[0]; + mencoder_write_chunk(mux_v, mpi->width*mpi->height*3, 0x10); +} + +//===========================================================================// + +static int vf_open(vf_instance_t *vf, char* args){ + vf->config=config; + vf->control=control; + vf->query_format=query_format; + vf->put_image=put_image; + vf->priv=malloc(sizeof(struct vf_priv_s)); + memset(vf->priv,0,sizeof(struct vf_priv_s)); + vf->priv->mux=args; + + mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); + mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); + mux_v->bih->biWidth=0; + mux_v->bih->biHeight=0; + mux_v->bih->biCompression=0; + mux_v->bih->biPlanes=1; + + return 1; +} + +vf_info_t ve_info_rawrgb = { + "rawrgb encoder", + "rawrgb", + "A'rpi", + "for internal use by mencoder", + vf_open +}; + +//===========================================================================// diff --git a/libmpcodecs/ve_vfw.c b/libmpcodecs/ve_vfw.c new file mode 100644 index 0000000000..fecf6754ec --- /dev/null +++ b/libmpcodecs/ve_vfw.c @@ -0,0 +1,100 @@ +#include +#include +#include + +#include "../config.h" +#ifdef USE_WIN32DLL + +#include "../mp_msg.h" + +#include "codec-cfg.h" +#include "stream.h" +#include "demuxer.h" +#include "stheader.h" + +#include "aviwrite.h" + +#include "../libvo/img_format.h" +#include "../mp_image.h" +#include "vf.h" + +//===========================================================================// + +#include "dll_init.h" + +struct vf_priv_s { + aviwrite_stream_t* mux; + BITMAPINFOHEADER* bih; +}; + +#define mux_v (vf->priv->mux) +#define vfw_bih (vf->priv->bih) + +static int config(struct vf_instance_s* vf, + int width, int height, int d_width, int d_height, + unsigned int flags, unsigned int outfmt){ + + vfw_bih->biWidth=width; + vfw_bih->biHeight=height; + vfw_bih->biSizeImage=width*height*((vfw_bih->biBitCount+7)/8); + mux_v->bih->biWidth=width; + mux_v->bih->biHeight=height; + mux_v->bih->biSizeImage=width*height*((mux_v->bih->biBitCount+7)/8); + + return 1; +} + +static int control(struct vf_instance_s* vf, int request, void* data){ + + return CONTROL_UNKNOWN; +} + +static int query_format(struct vf_instance_s* vf, unsigned int fmt){ + if(fmt==IMGFMT_BGR24) return 1; + return 0; +} + +static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ + long flags=0; + int ret; +// flip_upside_down(vo_image_ptr,vo_image_ptr,3*vo_w,vo_h); // dirty hack + ret=vfw_encode_frame(mux_v->bih, mux_v->buffer, vfw_bih, mpi->planes[0], &flags, 10000); + mencoder_write_chunk(mux_v,mux_v->bih->biSizeImage,flags); +} + +//===========================================================================// + +static int vf_open(vf_instance_t *vf, char* args){ + vf->config=config; + vf->control=control; + vf->query_format=query_format; + vf->put_image=put_image; + vf->priv=malloc(sizeof(struct vf_priv_s)); + memset(vf->priv,0,sizeof(struct vf_priv_s)); + vf->priv->mux=args; + + vfw_bih=malloc(sizeof(BITMAPINFOHEADER)); + vfw_bih->biSize=sizeof(BITMAPINFOHEADER); + vfw_bih->biWidth=0; // FIXME ? + vfw_bih->biHeight=0; + vfw_bih->biPlanes=1; + vfw_bih->biBitCount=24; + vfw_bih->biCompression=0; +// vfw_bih->biSizeImage=vo_w*vo_h*((vfw_bih->biBitCount+7)/8); +// mux_v->bih=vfw_open_encoder("divxc32.dll",vfw_bih,mmioFOURCC('D', 'I', 'V', '3')); + mux_v->bih=vfw_open_encoder("AvidAVICodec.dll",vfw_bih, 0); + if(!mux_v->bih) return 0; + + return 1; +} + +vf_info_t ve_info_vfw = { + "Win32/VfW encoders", + "vfw", + "A'rpi", + "for internal use by mencoder", + vf_open +}; + +//===========================================================================// +#endif diff --git a/libmpcodecs/vf.c b/libmpcodecs/vf.c index 67dc49fe62..a71b246381 100644 --- a/libmpcodecs/vf.c +++ b/libmpcodecs/vf.c @@ -142,7 +142,7 @@ mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, //============================================================================ -vf_instance_t* vf_open_filter(vf_instance_t* next, char *name, char *args){ +vf_instance_t* vf_open_plugin(vf_info_t** filter_list, vf_instance_t* next, char *name, char *args){ vf_instance_t* vf; int i; for(i=0;;i++){ @@ -166,6 +166,10 @@ vf_instance_t* vf_open_filter(vf_instance_t* next, char *name, char *args){ return NULL; } +vf_instance_t* vf_open_filter(vf_instance_t* next, char *name, char *args){ + return vf_open_plugin(filter_list,next,name,args); +} + //============================================================================ int vf_next_config(struct vf_instance_s* vf, diff --git a/libmpcodecs/vf.h b/libmpcodecs/vf.h index 27ac46bd4e..afdfa3962f 100644 --- a/libmpcodecs/vf.h +++ b/libmpcodecs/vf.h @@ -49,7 +49,10 @@ typedef struct vf_instance_s { // functions: mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h); + +vf_instance_t* vf_open_plugin(vf_info_t** filter_list, vf_instance_t* next, char *name, char *args); vf_instance_t* vf_open_filter(vf_instance_t* next, char *name, char *args); +vf_instance_t* vf_open_encoder(vf_instance_t* next, char *name, char *args); // default wrappers: int vf_next_config(struct vf_instance_s* vf, @@ -58,6 +61,6 @@ int vf_next_config(struct vf_instance_s* vf, int vf_next_control(struct vf_instance_s* vf, int request, void* data); int vf_next_query_format(struct vf_instance_s* vf, unsigned int fmt); void vf_next_put_image(struct vf_instance_s* vf,mp_image_t *mpi); + vf_instance_t* append_filters(vf_instance_t* last); -