diff -ur -x.svn -xconfig.* ffmpeg.orig/configure ../ffmpeg/configure
--- ffmpeg.orig/configure	Wed Feb 11 14:36:51 2009
+++ ../ffmpeg/configure	Tue Feb 10 22:09:16 2009
@@ -1360,7 +1360,7 @@
     die "C compiler test failed."
 fi
 
-check_cflags -std=c99
+check_cflags -std=gnu99
 
 case "$arch" in
     i386|i486|i586|i686|i86pc|BePC)
@@ -1896,6 +1896,9 @@
         add_extralibs -pthreads
     elif check_func pthread_create -lpthreadGC2; then
         add_extralibs -lpthreadGC2
+    elif check_func pthread_create -lpthread -lwsock32; then
+        add_cflags -DPTW32_STATIC_LIB
+        add_extralibs -lpthread -lwsock32
     elif ! check_lib pthread.h pthread_create -lpthread; then
         die "ERROR: can't find pthreads library"
     fi
@@ -1937,10 +1940,10 @@
 enabled libspeex   && require  libspeex speex/speex.h speex_decoder_init -lspeex
 enabled libtheora  && require  libtheora theora/theora.h theora_info_init -ltheora -logg
 enabled libvorbis  && require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
-enabled libx264    && require  libx264 x264.h x264_encoder_open -lx264 -lm &&
+enabled libx264    && require  libx264 x264.h x264_encoder_open -lx264 -lm -lpthread -lwsock32 &&
                       { check_cpp_condition x264.h "X264_BUILD >= 65" ||
                         die "ERROR: libx264 version must be >= 0.65."; }
-enabled libxvid    && require  libxvid xvid.h xvid_global -lxvidcore
+enabled libxvid    && require  libxvid xvid.h xvid_global -lxvidcore  -lpthread -lwsock32
 enabled mlib       && require  mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
 
 # libdc1394 check
diff -ur -x.svn -xconfig.* ffmpeg.orig/ffmpeg.c ../ffmpeg/ffmpeg.c
--- ffmpeg.orig/ffmpeg.c	Wed Feb 11 14:36:51 2009
+++ ../ffmpeg/ffmpeg.c	Wed Feb 11 14:51:56 2009
@@ -50,6 +50,7 @@
 
 #if HAVE_SYS_SELECT_H
 #include <sys/select.h>
+#define usleep(t) Sleep((t) / 1000)
 #endif
 
 #if HAVE_TERMIOS_H
diff -ur -x.svn -xconfig.* ffmpeg.orig/libavcodec/libmp3lame.c ../ffmpeg/libavcodec/libmp3lame.c
--- ffmpeg.orig/libavcodec/libmp3lame.c	Wed Feb 11 14:36:43 2009
+++ ../ffmpeg/libavcodec/libmp3lame.c	Sun Feb  1 14:16:45 2009
@@ -34,6 +34,7 @@
     int stereo;
     uint8_t buffer[BUFFER_SIZE];
     int buffer_index;
+    int buffer_flushed;
 } Mp3AudioContext;
 
 static av_cold int MP3lame_encode_init(AVCodecContext *avctx)
@@ -73,6 +74,8 @@
     avctx->coded_frame= avcodec_alloc_frame();
     avctx->coded_frame->key_frame= 1;
 
+    s->buffer_flushed = 0;
+
     return 0;
 
 err_close:
@@ -166,13 +169,15 @@
                 BUFFER_SIZE - s->buffer_index
                 );
         }
-    }else{
+    }else if (data == NULL && s->buffer_flushed == 0){
         lame_result= lame_encode_flush(
                 s->gfp,
                 s->buffer + s->buffer_index,
                 BUFFER_SIZE - s->buffer_index
                 );
-    }
+        s->buffer_flushed = 1;
+    }else
+        lame_result = 0;
 
     if(lame_result < 0){
         if(lame_result==-1) {
diff -ur -x.svn -xconfig.* ffmpeg.orig/libavcodec/opt.c ../ffmpeg/libavcodec/opt.c
--- ffmpeg.orig/libavcodec/opt.c	Wed Feb 11 14:36:40 2009
+++ ../ffmpeg/libavcodec/opt.c	Sun Feb  1 14:16:43 2009
@@ -175,6 +175,7 @@
             if(o->type == FF_OPT_TYPE_FLAGS){
                 if     (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d;
                 else if(cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d;
+                else if(buf[0]=='0' && buf[1]=='x') d= strtoul(buf, NULL, 16);
             }else{
                 if     (cmd=='+') d= notfirst*av_get_double(obj, name, NULL) + d;
                 else if(cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d;
diff -ur -x.svn -xconfig.* ffmpeg.orig/libavcodec/pthread.c ../ffmpeg/libavcodec/pthread.c
--- ffmpeg.orig/libavcodec/pthread.c	Wed Feb 11 14:36:44 2009
+++ ../ffmpeg/libavcodec/pthread.c	Tue Jan 20 01:18:58 2009
@@ -130,10 +130,24 @@
     return 0;
 }
 
+#ifdef PTW32_STATIC_LIB
+static void detach_ptw32(void)
+{
+    pthread_win32_thread_detach_np();
+    pthread_win32_process_detach_np();
+}
+#endif
+
 int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
 {
     int i;
     ThreadContext *c;
+
+#ifdef PTW32_STATIC_LIB
+    pthread_win32_process_attach_np();
+    pthread_win32_thread_attach_np();
+    atexit(detach_ptw32);
+#endif
 
     c = av_mallocz(sizeof(ThreadContext));
     if (!c)
diff -ur -x.svn -xconfig.* ffmpeg.orig/libavformat/utils.c ../ffmpeg/libavformat/utils.c
--- ffmpeg.orig/libavformat/utils.c	Wed Feb 11 14:36:50 2009
+++ ../ffmpeg/libavformat/utils.c	Tue Feb 10 19:27:22 2009
@@ -1831,6 +1831,10 @@
            (enc->codec_id == CODEC_ID_VORBIS ||
             enc->codec_id == CODEC_ID_AAC))
             return 0;
+#if CONFIG_LIBFAAD
+        if(enc->codec_id == CODEC_ID_AAC)
+            return 0;
+#endif
         break;
     case CODEC_TYPE_VIDEO:
         val = enc->width && enc->pix_fmt != PIX_FMT_NONE;
