Mercurial > mplayer.hg
changeset 9520:2860f7c9d9ca
A new nuppel video encoder. Mainly for RT encoding on slow box.
author | albeu |
---|---|
date | Mon, 03 Mar 2003 11:03:19 +0000 |
parents | 34b636d19268 |
children | 7de2fabb1fa2 |
files | cfg-mencoder.h libmpcodecs/Makefile libmpcodecs/ve.c libmpcodecs/ve_nuv.c mencoder.c |
diffstat | 5 files changed, 231 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/cfg-mencoder.h Mon Mar 03 10:59:07 2003 +0000 +++ b/cfg-mencoder.h Mon Mar 03 11:03:19 2003 +0000 @@ -56,6 +56,8 @@ extern struct config xvidencopts_conf[]; #endif +extern struct config nuvopts_conf[]; + struct config ovc_conf[]={ {"copy", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_COPY, NULL}, {"frameno", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_FRAMENO, NULL}, @@ -68,6 +70,7 @@ {"libdv", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_LIBDV, NULL}, {"xvid", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_XVID, NULL}, {"qtvideo", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_QTVIDEO, NULL}, + {"nuv", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_NUV, NULL}, {"help", "\nAvailable codecs:\n" " copy - frame copy, without re-encoding. doesn't work with filters!\n" " frameno - special audio-only file for 3-pass encoding, see DOCS!\n" @@ -208,6 +211,8 @@ {"xvidencopts", xvidencopts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, #endif + {"nuvopts", nuvopts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, + #define MAIN_CONF #include "cfg-common.h" #undef MAIN_CONF
--- a/libmpcodecs/Makefile Mon Mar 03 10:59:07 2003 +0000 +++ b/libmpcodecs/Makefile Mon Mar 03 11:03:19 2003 +0000 @@ -15,7 +15,7 @@ VIDEO_SRCS=dec_video.c vd.c $(VIDEO_SRCS_NAT) $(VIDEO_SRCS_LIB) $(VIDEO_SRCS_OPT) VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c -ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c ve_xvid.c ve_qtvideo.c +ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c ve_xvid.c ve_qtvideo.c ve_nuv.c NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c native/svq1.c
--- a/libmpcodecs/ve.c Mon Mar 03 10:59:07 2003 +0000 +++ b/libmpcodecs/ve.c Mon Mar 03 11:03:19 2003 +0000 @@ -16,6 +16,7 @@ extern vf_info_t ve_info_libdv; extern vf_info_t ve_info_xvid; extern vf_info_t ve_info_qtvideo; +extern vf_info_t ve_info_nuv; static vf_info_t* encoder_list[]={ #ifdef HAVE_DIVX4ENCORE @@ -35,6 +36,7 @@ #if defined(HAVE_XVID) &ve_info_xvid, #endif + &ve_info_nuv, NULL };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmpcodecs/ve_nuv.c Mon Mar 03 11:03:19 2003 +0000 @@ -0,0 +1,219 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "../config.h" +#include "../mp_msg.h" + +#include "m_option.h" + +#include "codec-cfg.h" +#include "stream.h" +#include "demuxer.h" +#include "stheader.h" + +#include "muxer.h" + +#include "img_format.h" +#include "mp_image.h" +#include "vf.h" + +#include "libmpdemux/nuppelvideo.h" +#include "native/minilzo.h" +#include "native/RTjpegN.h" + +#define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long)) +#define LZO_IN_LEN (1024*1024L) +#define LZO_OUT_LEN (LZO_IN_LEN + LZO_IN_LEN / 64 + 16 + 3) + +//===========================================================================// + +struct vf_priv_s { + int raw; // Do not use RTjpeg + int lzo; // Use lzo + unsigned int l,c,q; // Mjpeg param + muxer_stream_t* mux; + uint8_t* buffer; + + int buf_size; + int tbl_wrote; + lzo_byte *zbuffer; + long __LZO_MMODEL *zmem; +}; +#define mux_v (vf->priv->mux) + +struct vf_priv_s nuv_priv_dflt = { + 0, // raw + 1, // lzo + 1,1, // l,c + 255, // q + NULL, + NULL, + 0,0, + NULL,NULL +}; + +m_option_t nuvopts_conf[]={ + {"raw", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + {"rtjpeg", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 1, 0, NULL}, + {"lzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + {"nolzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 1, 0, NULL}, + {"q", &nuv_priv_dflt.q, CONF_TYPE_INT, M_OPT_RANGE,3,255, NULL}, + {"l", &nuv_priv_dflt.l, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL}, + {"c", &nuv_priv_dflt.c, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL}, + {NULL, NULL, 0, 0, 0, 0, NULL} +}; + +//===========================================================================// + + +static int config(struct vf_instance_s* vf, + int width, int height, int d_width, int d_height, + unsigned int flags, unsigned int outfmt){ + + // We need a buffer wich can holda header and a whole YV12 picture + // or a RTJpeg table + vf->priv->buf_size = width*height*3/2+FRAMEHEADERSIZE; + if(vf->priv->buf_size < (int)(128*sizeof(long int) + FRAMEHEADERSIZE)) + vf->priv->buf_size = 128*sizeof(long int) + FRAMEHEADERSIZE; + + 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); + vf->priv->buffer = realloc(vf->priv->buffer,vf->priv->buf_size); + vf->priv->tbl_wrote = 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){ + if(fmt==IMGFMT_I420) return 3; + return 0; +} + +static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ + struct rtframeheader* ench = (struct rtframeheader*)vf->priv->buffer; + uint8_t* data = vf->priv->buffer + FRAMEHEADERSIZE; + uint8_t* zdata = vf->priv->zbuffer + FRAMEHEADERSIZE; + int len = 0, zlen = 0,r; + + memset(vf->priv->buffer,0,FRAMEHEADERSIZE); // Reset the header + if(vf->priv->lzo) + memset(vf->priv->zbuffer,0,FRAMEHEADERSIZE); + + // This has to be don here otherwise tv with sound doesn't work + if(!vf->priv->tbl_wrote) { + RTjpeg_init_compress((long int*)data,mpi->width,mpi->height,vf->priv->q); + RTjpeg_init_mcompress(); + + ench->frametype = 'D'; // compressor data + ench->comptype = 'R'; // compressor data for RTjpeg + ench->packetlength = 128*sizeof(long int); + + mux_v->buffer=vf->priv->buffer; + muxer_write_chunk(mux_v,FRAMEHEADERSIZE + 128*sizeof(long int), 0x10); + vf->priv->tbl_wrote = 1; + memset(ench,0,FRAMEHEADERSIZE); // Reset the header + } + + // Raw picture + if(vf->priv->raw) { + len = mpi->width*mpi->height*3/2; + // Try lzo ??? + if(vf->priv->lzo) { + r = lzo1x_1_compress(mpi->planes[0],mpi->width*mpi->height*3/2, + zdata,&zlen,vf->priv->zmem); + if(r != LZO_E_OK) { + mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n"); + zlen = 0; + } + } + + if(zlen <= 0 || zlen > len) { + memcpy(data,mpi->planes[0],len); + ench->comptype = '0'; + } else { // Use lzo only if it's littler + ench = (struct rtframeheader*)vf->priv->zbuffer; + ench->comptype = '3'; + len = zlen; + } + + } else { // RTjpeg compression + len = RTjpeg_mcompressYUV420(data,mpi->planes[0],vf->priv->l, + vf->priv->c); + if(len <= 0) { + mp_msg(MSGT_VFILTER,MSGL_ERR,"RTjpeg_mcompressYUV420 error (%d)\n",len); + return 0; + } + + if(vf->priv->lzo) { + r = lzo1x_1_compress(data,len,zdata,&zlen,vf->priv->zmem); + if(r != LZO_E_OK) { + mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n"); + zlen = 0; + } + } + + if(zlen <= 0 || zlen > len) + ench->comptype = '1'; + else { + ench = (struct rtframeheader*)vf->priv->zbuffer; + ench->comptype = '2'; + len = zlen; + } + + } + + ench->frametype = 'V'; // video frame + ench->packetlength = len; + mux_v->buffer=(void*)ench; + muxer_write_chunk(mux_v, len + FRAMEHEADERSIZE, 0x10); + return 1; +} + +//===========================================================================// + +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)); + memcpy(vf->priv, &nuv_priv_dflt,sizeof(struct vf_priv_s)); + //memset(vf->priv,0,sizeof(struct vf_priv_s)); + vf->priv->mux=(muxer_stream_t*)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=12; + mux_v->bih->biCompression = mmioFOURCC('N','U','V','1'); + + if(vf->priv->lzo) { + if(lzo_init() != LZO_E_OK) { + mp_msg(MSGT_VFILTER,MSGL_WARN,"LZO init failed: no lzo compression\n"); + vf->priv->lzo = 0; + } + vf->priv->zbuffer = (lzo_bytep)malloc(FRAMEHEADERSIZE + LZO_OUT_LEN); + vf->priv->zmem = (long*)malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS)); + } + + return 1; +} + +vf_info_t ve_info_nuv = { + "nuv encoder", + "nuv", + "Albeu", + "for internal use by mencoder", + vf_open +}; + +//===========================================================================//
--- a/mencoder.c Mon Mar 03 10:59:07 2003 +0000 +++ b/mencoder.c Mon Mar 03 11:03:19 2003 +0000 @@ -8,6 +8,7 @@ #define VCODEC_LIBDV 8 #define VCODEC_XVID 9 #define VCODEC_QTVIDEO 10 +#define VCODEC_NUV 11 #define ACODEC_COPY 0 #define ACODEC_PCM 1 @@ -671,6 +672,9 @@ sh_video->vfilter=vf_open_encoder(NULL,"xvid",(char *)mux_v); break; case VCODEC_QTVIDEO: sh_video->vfilter=vf_open_encoder(NULL,"qtvideo",(char *)mux_v); break; + case VCODEC_NUV: + sh_video->vfilter=vf_open_encoder(NULL,"nuv",(char *)mux_v); break; + } if(!mux_v->bih || !sh_video->vfilter){ mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_EncoderOpenFailed);