--- vlc-0.8.1/modules/codec/Modules.am.xvid~	2004-11-06 17:36:05.000000000 +0100
+++ vlc-0.8.1/modules/codec/Modules.am	2004-11-26 04:23:05.000000000 +0100
@@ -23,3 +23,4 @@
 SOURCES_mash = mash.cpp
 SOURCES_x264 = x264.c
 SOURCES_toolame = toolame.c
+SOURCES_xvid = xvidenc.c
--- vlc-0.8.1/modules/codec/xvidenc.c.xvid~	2004-11-26 04:23:05.000000000 +0100
+++ vlc-0.8.1/modules/codec/xvidenc.c	2004-11-26 04:30:26.000000000 +0100
@@ -0,0 +1,287 @@
+/*****************************************************************************
+ * xvidenc.c: xvid video encoder
+ *****************************************************************************
+ * Copyright (C) 2004 LINUX4MEDIA GmbH
+ * $Id$
+ *
+ * Authors: Bernhard Rosenkraenzer <bero@arklinux.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  0211, USA.
+ ****************************************************************************/
+
+/****************************************************************************
+ * Preamble
+ ****************************************************************************/
+#include <vlc/vlc.h>
+#include <vlc/vout.h>
+#include <vlc/sout.h>
+#include <vlc/decoder.h>
+
+#include <xvid.h>
+
+#define SOUT_CFG_PREFIX "sout-xvid-"
+
+/****************************************************************************
+ * Module descriptor
+ ****************************************************************************/
+static int  Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
+
+vlc_module_begin();
+    set_description( _("MPEG-4 video encoder using the xvid library"));
+    set_capability( "encoder", 200 );
+    set_callbacks( Open, Close );
+vlc_module_end();
+
+/****************************************************************************
+ * Local prototypes
+ ****************************************************************************/
+static const char *ppsz_sout_options[] = {
+    NULL
+};
+
+static block_t *Encode( encoder_t *, picture_t * );
+
+struct encoder_sys_t
+{
+    xvid_plugin_single_t	xvid_1pass;
+    xvid_enc_create_t		xvid_enc;
+    xvid_enc_plugin_t		xvid_plugins[1];
+    xvid_gbl_init_t		xvid_init;
+    uint8_t			*buffer;
+};
+
+/****************************************************************************
+ * Chroma fourcc -> xvid_id mapping
+ ****************************************************************************/
+static struct
+{
+    vlc_fourcc_t		i_chroma;
+    int				i_chroma_id;
+} chroma_table[] =
+{
+    { VLC_FOURCC('I', '4', '2', '0'), XVID_CSP_I420 },
+    { VLC_FOURCC('Y', 'V', '1', '2'), XVID_CSP_YV12 },
+    { VLC_FOURCC('Y', 'U', 'Y', '2'), XVID_CSP_YUY2 },
+    { VLC_FOURCC('U', 'Y', 'V', 'Y'), XVID_CSP_UYVY },
+    { VLC_FOURCC('Y', 'V', 'Y', 'U'), XVID_CSP_YVYU },
+    { VLC_FOURCC('B', 'G', 'R', 'A'), XVID_CSP_BGRA },
+    { VLC_FOURCC('A', 'B', 'G', 'R'), XVID_CSP_ABGR },
+    { VLC_FOURCC('R', 'G', 'B', 'A'), XVID_CSP_RGBA },
+    { VLC_FOURCC('A', 'R', 'G', 'B'), XVID_CSP_ARGB },
+    { VLC_FOURCC('B', 'G', 'R', ' '), XVID_CSP_BGR },
+    { VLC_FOURCC('R', 'V', '1', '5'), XVID_CSP_RGB555 },
+    { VLC_FOURCC('R', 'V', '1', '6'), XVID_CSP_RGB565 },
+    { VLC_FOURCC('R', 'V', '3', '2'), XVID_CSP_RGBA },
+    { 0 }
+};
+
+int E_(GetXvidChroma)( vlc_fourcc_t i_chroma )
+{
+    int i;
+    for( i = 0; chroma_table[i].i_chroma; i++ )
+    {
+        if( chroma_table[i].i_chroma == i_chroma )
+            return chroma_table[i].i_chroma_id;
+    }
+    return -1;
+}
+
+vlc_fourcc_t E_(GetVlcChromaXvid)( int i_xvid_chroma )
+{
+    int i;
+    for( i = 0; chroma_table[i].i_chroma; i++ )
+    {
+        if( chroma_table[i].i_chroma_id == i_xvid_chroma )
+		return chroma_table[i].i_chroma;
+    }
+    return 0;
+}
+
+/****************************************************************************
+ * Stuff missing from the XVid API
+ ****************************************************************************/
+static const char *xvid_strerror(int err)
+{
+    const char *error;
+    switch(err) {
+    case XVID_ERR_FAIL:
+        error = "General failure";
+	break;
+    case XVID_ERR_MEMORY:
+	error = "Out of memory";
+	break;
+    case XVID_ERR_FORMAT:
+        error = "File format error";
+	break;
+    case XVID_ERR_VERSION:
+        error = "Wrong structure version";
+	break;
+    case XVID_ERR_END:
+        error = "End of stream reached";
+	break;
+    default:
+	error=(const char*)malloc(128);
+	snprintf(error, 128, "Unknown error #%d", err);
+    }
+    return error;
+}
+
+/****************************************************************************
+ * Open: probe the encoder
+ ****************************************************************************/
+static int  Open ( vlc_object_t *p_this )
+{
+    encoder_t     *p_enc = (encoder_t *)p_this;
+    encoder_sys_t *p_sys;
+    vlc_value_t    val;
+    int            result;
+
+    if( p_enc->fmt_out.i_codec != VLC_FOURCC( 'X', 'V', 'I', 'D' ) &&
+        !p_enc->b_force )
+    {
+        return VLC_EGENERIC;
+    }
+
+    sout_CfgParse( p_enc, SOUT_CFG_PREFIX, ppsz_sout_options, p_enc->p_cfg );
+
+    if( !E_(GetXvidChroma)( p_enc->fmt_out.i_codec ) < 0 )
+        return VLC_EGENERIC;
+
+    p_enc->fmt_in.i_codec = VLC_FOURCC( 'I', '4', '2', '0' );
+    p_enc->fmt_out.i_codec = VLC_FOURCC( 'X', 'V', 'I', 'D' );
+
+    p_enc->pf_encode_video = Encode;
+    p_enc->pf_encode_audio = NULL;
+    p_enc->p_sys = p_sys = malloc( sizeof( encoder_sys_t ) );
+
+    memset( &p_sys->xvid_1pass, 0, sizeof( xvid_plugin_single_t ) );
+    memset( &p_sys->xvid_enc, 0, sizeof( xvid_enc_create_t ) );
+    memset( &p_sys->xvid_plugins, 0, sizeof( xvid_enc_plugin_t ) * 2 );
+    memset( &p_sys->xvid_init, 0, sizeof( xvid_gbl_init_t ) );
+
+    p_sys->xvid_init.version = XVID_VERSION;
+    p_sys->xvid_init.debug = 0;
+
+    if ( (result = xvid_global( NULL, XVID_GBL_INIT, &p_sys->xvid_init, NULL ) ) < 0 ) {
+        msg_Warn( p_enc, "Failed to initialize xvid: %s", xvid_strerror(result) );
+	return VLC_EGENERIC;
+    }
+
+    p_sys->xvid_1pass.version = XVID_VERSION;
+    p_sys->xvid_1pass.bitrate = 1024000;
+
+    p_sys->xvid_enc.version = XVID_VERSION;
+    p_sys->xvid_enc.width = p_enc->fmt_in.video.i_width;
+    p_sys->xvid_enc.height = p_enc->fmt_in.video.i_height;
+    p_sys->xvid_enc.fincr = p_enc->fmt_in.video.i_frame_rate;
+    p_sys->xvid_enc.fbase = p_enc->fmt_in.video.i_frame_rate_base;
+    p_sys->xvid_enc.profile = XVID_PROFILE_AS_L4;
+    p_sys->xvid_enc.num_zones = 0;
+    p_sys->xvid_enc.plugins = p_sys->xvid_plugins;
+    p_sys->xvid_enc.num_plugins = 0;
+    p_sys->xvid_enc.max_key_interval = 250;
+    p_sys->xvid_enc.max_bframes = 2;
+    p_sys->xvid_enc.bquant_ratio = 150;
+    p_sys->xvid_enc.bquant_offset = 100;
+    p_sys->xvid_enc.frame_drop_ratio = 0;
+    p_sys->xvid_enc.global = 0;
+
+    p_sys->xvid_enc.plugins[p_sys->xvid_enc.num_plugins].func = xvid_plugin_single;
+    p_sys->xvid_enc.plugins[p_sys->xvid_enc.num_plugins++].param = &p_sys->xvid_1pass;
+
+    p_sys->buffer=(uint8_t*)malloc(p_sys->xvid_enc.width * p_sys->xvid_enc.height * 4 * 2);
+    
+    result=xvid_encore(NULL, XVID_ENC_CREATE, &p_sys->xvid_enc, NULL);
+    if ( result < 0 ) {
+        msg_Warn( p_enc, "Failed to initialize encoder: %s", xvid_strerror(result) );
+	return VLC_EGENERIC;
+    }
+
+    return VLC_SUCCESS;
+}
+
+/****************************************************************************
+ * Encode:
+ ****************************************************************************/
+static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
+{
+    encoder_sys_t *p_sys = p_enc->p_sys;
+
+    xvid_enc_frame_t frame;
+    xvid_enc_stats_t stats;
+
+    block_t *p_block;
+
+    int i, ret;
+
+    memset( &frame, 0, sizeof( xvid_enc_frame_t ) );
+    memset( &stats, 0, sizeof( xvid_enc_stats_t ) );
+
+    frame.version = XVID_VERSION;
+    stats.version = XVID_VERSION;
+
+    frame.bitstream = p_sys->buffer;
+    frame.input.csp = XVID_CSP_I420;
+    for( i = 0; i < p_pict->i_planes; i++ ) {
+    	frame.input.plane[i] = p_pict->p[i].p_pixels;
+	frame.input.stride[i] = p_pict->p[i].i_pitch;
+    }
+    frame.length = -1;
+    frame.vol_flags = XVID_VOL_GMC | XVID_VOL_QUARTERPEL;
+    frame.vop_flags = XVID_VOP_HALFPEL | XVID_VOP_INTER4V | XVID_VOP_TRELLISQUANT | XVID_VOP_HQACPRED;
+    frame.type = XVID_TYPE_AUTO;
+    frame.quant = 0;
+    frame.motion = XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 | XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP | XVID_ME_GME_REFINE | XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8;
+
+    ret = xvid_encore( p_sys->xvid_enc.handle, XVID_ENC_ENCODE, &frame, &stats);
+    if ( ret < 0 ) {
+        msg_Warn( p_enc, "Failed to encode frame: %s", xvid_strerror(ret) );
+    }
+
+    p_block = block_New( p_enc, ret );
+    p_block->i_dts = p_pict->date;
+    p_block->i_pts = p_pict->date;
+    memcpy( p_block->p_buffer, p_sys->buffer, ret );
+
+    if(stats.type == XVID_TYPE_IVOP)
+        p_block->i_flags |= BLOCK_FLAG_TYPE_I;
+    else if(stats.type == XVID_TYPE_PVOP)
+        p_block->i_flags |= BLOCK_FLAG_TYPE_P;
+    else if(stats.type == XVID_TYPE_BVOP)
+        p_block->i_flags |= BLOCK_FLAG_TYPE_B;
+    
+    return p_block;
+}
+
+/****************************************************************************
+ * Close: Close encoder
+ ****************************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+    encoder_t     *p_enc = (encoder_t *)p_this;
+    encoder_sys_t *p_sys = p_enc->p_sys;
+    int           result;
+
+    if ( p_sys->xvid_enc.handle ) {
+        result = xvid_encore( p_sys->xvid_enc.handle, XVID_ENC_DESTROY, NULL, NULL );
+	if ( result < 0 )
+            msg_Warn( p_enc, "Failed to stop encoder: %s", xvid_strerror(result) );
+    }
+    if ( p_sys->buffer ) {
+        free(p_sys->buffer);
+	p_sys->buffer = NULL;
+    }
+}
--- vlc-0.8.1/configure.ac.xvid~	2004-11-26 04:23:05.000000000 +0100
+++ vlc-0.8.1/configure.ac	2004-11-26 04:23:05.000000000 +0100
@@ -2568,6 +2568,20 @@
 fi
 
 dnl
+dnl MPEG-4 encoder plugin (using xvid)
+dnl
+AC_ARG_ENABLE(xvid,
+  [  --enable-xvid           MPEG-4 encoding support with xvid (default enabled)])
+if test "${enable_xvid}" != "no"; then
+  LDFLAGS="${LDFLAGS_save} ${LDFLAGS_xvid}"
+  AC_CHECK_HEADERS(xvid.h, [
+      VLC_ADD_PLUGINS([xvid])
+      VLC_ADD_LDFLAGS([xvid],[-lxvidcore])
+  ])
+  LDFLAGS="${LDFLAGS_save}"
+fi
+
+dnl
 dnl  CMML plugin
 dnl
 AC_ARG_ENABLE(cmml,
