
Property changes on: .
___________________________________________________________________
Modified: svn:ignore
   - *.d
*.exe
*.ho
*-test
*_g
config.*
ffmpeg
ffplay
ffserver
version.h

   + *.d
*.exe
*.ho
*-test
*_g
config.*
ffmpeg
ffplay
ffserver
version.h
build
build_cgr
build_clonebd
build_clonedvd
libextern
*.patch
build_clonedvd_debug


Index: cmdutils.c
===================================================================
--- cmdutils.c	(revision 19189)
+++ cmdutils.c	(working copy)
@@ -272,6 +272,7 @@
 
 static void print_all_lib_versions(FILE* outstream, int indent)
 {
+    return; // silence
     unsigned int version;
     PRINT_LIB_VERSION(outstream, avutil,   AVUTIL,   indent);
     PRINT_LIB_VERSION(outstream, avcodec,  AVCODEC,  indent);
@@ -288,6 +289,17 @@
 
 void show_banner(void)
 {
+    fprintf(stderr, "%s version from svn, Copyright (c) %d-2008 Fabrice Bellard, et al.\n", program_name, program_birth_year);
+    fprintf(stderr, "\n"
+                    "NOTICE: This app contains changes made by SlySoft Inc. in compliance with GPL.\n" 
+                    "        All changes are available as patches from http://oss.slysoft.com\n"
+                    "\n"
+                    "        This file was digitally signed by SlySoft Inc.\n"
+                    "\n"
+                    "        FFmpeg maintainers receive SlySoft products free of charge. If you're\n"
+                    "        interested then please contact us at support@slysoft.com\n\n");
+
+    return; // silence
     fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d Fabrice Bellard, et al.\n",
             program_name, program_birth_year, this_year);
     fprintf(stderr, "  configuration: " FFMPEG_CONFIGURATION "\n");
@@ -301,6 +313,7 @@
 }
 
 void show_version(void) {
+    return; // silence
     printf("%s " FFMPEG_VERSION "\n", program_name);
     print_all_lib_versions(stdout, 0);
 }
@@ -383,6 +396,7 @@
     AVBitStreamFilter *bsf=NULL;
     const char *last_name;
 
+    return; // silence
     printf("File formats:\n");
     last_name= "000";
     for(;;){
Index: configure
===================================================================
--- configure	(revision 19189)
+++ configure	(working copy)
@@ -1494,7 +1494,7 @@
     die "C compiler test failed."
 fi
 
-check_cflags -std=c99
+# check_cflags -std=c99    LIBFAAC is broken
 check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cflags -D_FILE_OFFSET_BITS=64
 #include <stdlib.h>
 EOF
@@ -2101,7 +2101,7 @@
 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 &&
                       { 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
@@ -2232,6 +2232,8 @@
 check_cflags -Wundef
 enabled extra_warnings && check_cflags -Winline
 
+check_cflags -ggdb
+
 # add some linker flags
 check_ldflags -Wl,--warn-common
 check_ldflags -Wl,--as-needed
@@ -2248,7 +2250,7 @@
     elif enabled ccc; then
         add_cflags -fast
     else
-        add_cflags -O3
+        add_cflags "-O5 -fno-zero-initialized-in-bss -fno-exceptions"
     fi
 fi
 check_cflags -fno-math-errno
Index: configure_clonedvd
===================================================================
--- configure_clonedvd	(revision 0)
+++ configure_clonedvd	(revision 0)
@@ -0,0 +1,90 @@
+#!/bin/sh
+#
+# FFmpeg configure script     
+
+../configure \
+  \
+  --enable-gpl \
+  --enable-nonfree \
+  \
+  --cpu=athlon \
+  --enable-memalign-hack \
+  --disable-debug \
+  --enable-w32threads \
+  --extra-cflags='-I../libextern' \
+  --extra-ldflags='-L../libextern' \
+  \
+  --disable-decoders \
+  --disable-encoders \
+  --disable-parsers \
+  --disable-muxers \
+  --disable-demuxers \
+  --disable-bsfs \
+  --disable-protocols \
+  --disable-devices \
+  --disable-filters \
+  --disable-network \
+  --disable-ffplay \
+  --disable-ffserver \
+  \
+  --enable-libmp3lame \
+  --enable-libfaac \
+  --enable-libx264 \
+  --enable-libxvid \
+  --enable-libamr_nb \
+  --enable-libamr_wb \
+  \
+  --enable-ffmpeg \
+  --enable-protocol=file \
+  --enable-protocol=pipe \
+  --enable-demuxer=cham \
+  --enable-muxer=avi \
+  --enable-muxer=asf \
+  --enable-muxer=mpeg \
+  --enable-muxer=mpeg1vcd \
+  --enable-muxer=mpeg2vob \
+  --enable-muxer=mpeg2svcd \
+  --enable-muxer=mpeg2dvd \
+  --enable-muxer=mp4 \
+  --enable-muxer=psp \
+  --enable-muxer=tgp \
+  --enable-muxer=tg2 \
+  --enable-muxer=matroska \
+  --enable-decoder=mpeg2video \
+  --enable-decoder=mp2 \
+  --enable-decoder=ac3 \
+  --enable-decoder=dca \
+  --enable-decoder=dvdsub \
+  --enable-decoder=pcm_dvd \
+  --enable-decoder=pcm_s16be \
+  --enable-encoder=mjpeg \
+  --enable-encoder=mpeg1video \
+  --enable-encoder=mpeg2video \
+  --enable-encoder=mpeg4 \
+  --enable-encoder=mp2 \
+  --enable-encoder=wmv2 \
+  --enable-encoder=wmav2 \
+  --enable-encoder=libmp3lame \
+  --enable-encoder=libfaac \
+  --enable-encoder=libx264 \
+  --enable-encoder=libxvid \
+  --enable-encoder=libamr_nb \
+  --enable-encoder=libamr_wb
+
+# DECODER
+# -------
+# VIDEO  mpeg2video
+# AUDIO  mp2 ac3 dca lpcm
+# SUBPIC dvdsub
+
+# MUXERS
+# ------
+# avi asf(wmv) mpeg's psp(mp4) 3gp(mp4) 3g2(mp4)           | 3gp => tgp
+#
+# mpeg2vob = generic ; mpeg2svcd = 2324 ; mpeg2dvd = nav
+#
+
+# ENCODER
+# -------
+# VIDEO  mpeg1 mpeg2 mjpeg h.263(mpeg4) h.264(x264) wmv2
+# AUDIO  mp2 mp3(lame) aac(faac) wma2
Index: ffmpeg.c
===================================================================
--- ffmpeg.c	(revision 19189)
+++ ffmpeg.c	(working copy)
@@ -23,6 +23,7 @@
 #define _XOPEN_SOURCE 600
 
 #include "config.h"
+#include "version.h"
 #include <ctype.h>
 #include <string.h>
 #include <math.h>
@@ -38,6 +39,7 @@
 #include "libavcodec/audioconvert.h"
 #include "libavcodec/colorspace.h"
 #include "libavutil/fifo.h"
+#include "libavutil/file.h"
 #include "libavutil/avstring.h"
 #include "libavformat/os_support.h"
 
@@ -125,6 +127,8 @@
 static int frame_bottomBand = 0;
 static int frame_leftBand  = 0;
 static int frame_rightBand = 0;
+static int video_width = 0;
+static int video_height = 0;
 static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
 static AVRational frame_rate;
 static float video_qscale = 0;
@@ -161,6 +165,8 @@
 static char *audio_language = NULL;
 
 static int subtitle_disable = 0;
+static int subtitle_etching = 0;
+static int subtitle_id = 0;
 static char *subtitle_codec_name = NULL;
 static char *subtitle_language = NULL;
 static int subtitle_codec_tag = 0;
@@ -780,6 +786,10 @@
 /* we begin to correct av delay at this threshold */
 #define AV_DELAY_MAX 0.100
 
+static AVSubtitle subtitle_etch;
+static uint64_t subtitle_etch_start;
+static uint64_t subtitle_etch_end;
+
 static void do_subtitle_out(AVFormatContext *s,
                             AVOutputStream *ost,
                             AVInputStream *ist,
@@ -836,6 +846,7 @@
 
 static int bit_buffer_size= 1024*256;
 static uint8_t *bit_buffer= NULL;
+static int frame_dropping = 0;
 
 static void do_video_out(AVFormatContext *s,
                          AVOutputStream *ost,
@@ -844,10 +855,11 @@
                          int *frame_size)
 {
     int nb_frames, i, ret;
-    AVFrame *final_picture, *formatted_picture, *resampling_dst, *padding_src;
-    AVFrame picture_crop_temp, picture_pad_temp;
+    AVFrame *final_picture, *formatted_picture, *etched_picture, *resampling_dst, *padding_src;
+    AVFrame picture_etching_temp, picture_crop_temp, picture_pad_temp;
     AVCodecContext *enc, *dec;
 
+    avcodec_get_frame_defaults(&picture_etching_temp);
     avcodec_get_frame_defaults(&picture_crop_temp);
     avcodec_get_frame_defaults(&picture_pad_temp);
 
@@ -873,9 +885,20 @@
         }else if (vdelta > 1.1)
             nb_frames = lrintf(vdelta);
 //fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, get_sync_ipts(ost), nb_frames);
+        if (nb_frames > 3) {
+            fprintf(stderr, "*** BONG! %d frames dup, vdelta = %f (method=%d), [%d, %I64d, %I64d, %I64d]\n", nb_frames, vdelta, video_sync_method, ost->frame_number, ost->sync_ist->start, ost->sync_ist->pts, ost->sync_ist->next_pts);
+            exit(1);
+        }
+        if (nb_frames == 0 && ++frame_dropping > 3) {
+            fprintf(stderr, "*** BONG! %d frames drop, vdelta = %f (method=%d), [%d, %I64d, %I64d, %I64d]\n", nb_frames, vdelta, video_sync_method, ost->frame_number, ost->sync_ist->start, ost->sync_ist->pts, ost->sync_ist->next_pts);
+            exit(1);
+        }
+        if (nb_frames > 0)
+          frame_dropping = 0;
+
         if (nb_frames == 0){
             ++nb_frames_drop;
-            if (verbose>2)
+            if (verbose>2 && frame_dropping != 1)
                 fprintf(stderr, "*** drop!\n");
         }else if (nb_frames > 1) {
             nb_frames_dup += nb_frames;
@@ -889,8 +912,18 @@
     if (nb_frames <= 0)
         return;
 
+    if (subtitle_etch.num_rects && subtitle_etch_start <= ist->pts && ist->pts <= subtitle_etch_end) {
+        if (av_picture_harddup((AVPicture *)&picture_etching_temp, in_picture, dec->pix_fmt, dec->width, dec->height, &subtitle_etch) < 0) {
+              av_log(NULL, AV_LOG_ERROR, "error harddupping picture\n");
+              return;
+        }
+        etched_picture = &picture_etching_temp;
+    } else {
+        etched_picture = in_picture;
+    }
+
     if (ost->video_crop) {
-        if (av_picture_crop((AVPicture *)&picture_crop_temp, (AVPicture *)in_picture, dec->pix_fmt, ost->topBand, ost->leftBand) < 0) {
+        if (av_picture_crop((AVPicture *)&picture_crop_temp, etched_picture, dec->pix_fmt, ost->topBand, ost->leftBand) < 0) {
             fprintf(stderr, "error cropping picture\n");
             if (exit_on_error)
                 av_exit(1);
@@ -898,7 +931,7 @@
         }
         formatted_picture = &picture_crop_temp;
     } else {
-        formatted_picture = in_picture;
+        formatted_picture = etched_picture;
     }
 
     final_picture = formatted_picture;
@@ -1023,7 +1056,7 @@
 
     /* this is executed just the first time do_video_stats is called */
     if (!vstats_file) {
-        vstats_file = fopen(vstats_filename, "w");
+        vstats_file = av_fopen(vstats_filename, "w");
         if (!vstats_file) {
             perror("fopen");
             av_exit(1);
@@ -1251,6 +1284,9 @@
                     /* XXX: allocate picture correctly */
                     avcodec_get_frame_defaults(&picture);
 
+                    video_width = ist->st->codec->width;
+                    video_height = ist->st->codec->height;
+
                     ret = avcodec_decode_video2(ist->st->codec,
                                                 &picture, &got_picture, &avpkt);
                     ist->st->quality= picture.quality;
@@ -1269,14 +1305,164 @@
                     avpkt.size = 0;
                     break;
             case CODEC_TYPE_SUBTITLE:
+
+                if (subtitle_etching) {
+                    if (subtitle_etch.rects != NULL) {
+                        for (i = 0; i < subtitle_etch.num_rects; i++) {
+                            av_freep(&subtitle_etch.rects[i]->image);
+                            av_freep(&subtitle_etch.rects[i]->pict.data[0]);
+                            av_freep(&subtitle_etch.rects[i]->pict.data[1]);
+                            av_freep(&subtitle_etch.rects[i]);
+                        }
+                        av_freep(&subtitle_etch.rects);
+                    }
+                    subtitle_etch.num_rects = 0;
+                    subtitle_etch.rects = NULL;
+
+                    /* initialize decoder if it wasn't initialized (no mapped output stream) */
+                    if (!ist->st->codec->codec) {
+                        AVCodec *codec = avcodec_find_decoder(ist->st->codec->codec_id);
+                        if (!codec) {
+                            fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n", ist->st->codec->codec_id, ist->file_index, ist->index);
+                            av_exit(1);
+                        }
+
+                        if (avcodec_open(ist->st->codec, codec) < 0) {
+                            fprintf(stderr, "Error while opening codec for input stream #%d.%d\n", ist->file_index, ist->index);
+                            av_exit(1);
+                        }
+                    }
+                }
+
                 ret = avcodec_decode_subtitle2(ist->st->codec,
-                                               &subtitle, &got_subtitle, &avpkt);
+                                               &subtitle_etch, &got_subtitle, &avpkt);
+                subtitle = subtitle_etch;
+
                 if (ret < 0)
                     goto fail_decode;
                 if (!got_subtitle) {
                     goto discard_packet;
                 }
-                subtitle_to_free = &subtitle;
+
+                subtitle_etch_start = ist->pts + 1000 * subtitle_etch.start_display_time;
+                subtitle_etch_end   = ist->pts + 1000 * subtitle_etch.end_display_time;
+
+                BOOL Shrink = TRUE;
+again:
+
+                if (!subtitle_etching)
+                    subtitle_to_free = &subtitle;
+                else {
+                    INT i;
+                    INT l, t, r, b;
+                    INT cl, ct, cr, cb;
+                    INT dx, dy;
+                    double scale = 0;
+
+                    l = video_width;
+                    t = video_height;
+                    r = 0;
+                    b = 0;
+
+                    for (i = 0; i < subtitle_etch.num_rects; ++i) {
+                        AVSubtitleRect *rr = subtitle_etch.rects[i];
+
+                        if (rr->x < l)
+                          l = rr->x;
+                        if (rr->y < t)
+                          t = rr->y;
+                        if (rr->x + rr->w > r)
+                          r = rr->x + rr->w;
+                        if (rr->y + rr->h > b)
+                          b = rr->y + rr->h;
+                    }
+
+                    cl = frame_leftBand + 15;
+                    ct = frame_topBand + 15;
+                    cr = video_width - frame_rightBand - 15;
+                    cb = video_height - frame_bottomBand - 15;
+
+                    dx = 0;
+                    dy = 0;
+
+                    if (l < cl)
+                      dx = cl - l;
+                    if (r > cr)
+                      if (!dx) dx = cr - r; // else scale = 1.0 * (cr - cl) / (r - l);
+                    if (t < ct)
+                      dy = ct - t;
+                    if (b > cb)
+                      if (!dy) dy = cb - b;
+
+                    if (Shrink)
+                    {
+                      INT crop = frame_leftBand + frame_rightBand;
+
+                      scale = 1.0 * (video_width - crop) / video_width;
+                    }
+
+                    if (scale && scale < 1 && subtitle_etch.num_rects == 1) {
+
+                      for (i = 0; i < subtitle_etch.num_rects; ++i) {
+                          AVSubtitleRect *rr = subtitle_etch.rects[i];
+
+                          uint8_t *sptr = rr->pict.data[0];
+                          uint32_t *pal = (uint32_t*)rr->pict.data[1];
+                          int ls = rr->pict.linesize[0];
+
+                          INT x, y;
+                          INT nw = (INT)(rr->w * scale + 0.5);
+                          INT nh = (INT)(rr->h * scale + 0.5);
+
+                          rr->image = av_malloc(nw * nh * 4);
+
+                          for (y = 0; y < nh; y++) {
+                              for (x = 0; x < nw; x++) {
+                                double ix = x / scale;
+                                double iy = y / scale;
+                                double px = 1 - (ix - (INT) ix);
+                                double py = 1 - (iy - (INT) iy);
+
+                                INT ix1 = (INT) ix;     if (ix1 >= rr->w) px = 1, ix1 = rr->w - 1;
+                                INT ix2 = (INT) ix + 1; if (ix2 >= rr->w) px = 1, ix2 = rr->w - 1;
+                                INT iy1 = (INT) iy;     if (iy1 >= rr->h) py = 1, iy1 = rr->h - 1;
+                                INT iy2 = (INT) iy + 1; if (iy2 >= rr->h) py = 1, iy2 = rr->h - 1;
+
+                                INT vx1y1 = pal[sptr[iy1 * ls + ix1]];
+                                INT vx2y1 = pal[sptr[iy1 * ls + ix2]];
+                                INT vx1y2 = pal[sptr[iy2 * ls + ix1]];
+                                INT vx2y2 = pal[sptr[iy2 * ls + ix2]];
+
+                                INT ccA = (INT)( (vx1y1 >> 24 & 0xFF) * px * py + (vx2y1 >> 24 & 0xFF) * (1 - px) * py + (vx1y2 >> 24 & 0xFF) * px * (1 - py) + (vx2y2 >> 24 & 0xFF) * (1 - px) * (1 - py) + 0.5 ) ;
+                                INT ccY = (INT)( (vx1y1 >> 16 & 0xFF) * px * py + (vx2y1 >> 16 & 0xFF) * (1 - px) * py + (vx1y2 >> 16 & 0xFF) * px * (1 - py) + (vx2y2 >> 16 & 0xFF) * (1 - px) * (1 - py) + 0.5 ) ;
+                                INT ccU = (INT)( (vx1y1 >>  8 & 0xFF) * px * py + (vx2y1 >>  8 & 0xFF) * (1 - px) * py + (vx1y2 >>  8 & 0xFF) * px * (1 - py) + (vx2y2 >>  8 & 0xFF) * (1 - px) * (1 - py) + 0.5 ) ;
+                                INT ccV = (INT)( (vx1y1 >>  0 & 0xFF) * px * py + (vx2y1 >>  0 & 0xFF) * (1 - px) * py + (vx1y2 >>  0 & 0xFF) * px * (1 - py) + (vx2y2 >>  0 & 0xFF) * (1 - px) * (1 - py) + 0.5 ) ;
+
+                                INT cc  = ccA << 24 | ccY << 16 | ccU << 8 | ccV;
+
+                                rr->image[y * nw + x] = cc;
+                              }
+                          }
+
+                          rr->pict.linesize[0] = nw;
+                          rr->x += (rr->w - nw) / 2;
+                          rr->y += (rr->h - nh) / 2;
+                          rr->w = nw;
+                          rr->h = nh;
+                      }
+
+                      Shrink = FALSE;
+                      goto again;
+                    }
+
+                    for (i = 0; i < subtitle_etch.num_rects; ++i) {
+                        AVSubtitleRect *rr = subtitle_etch.rects[i];
+
+                        rr->x += dx;
+                        rr->y += dy;
+                    }
+                }
+
                 avpkt.size = 0;
                 break;
             default:
@@ -1328,7 +1514,7 @@
             int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE);
             int64_t now = av_gettime() - ist->start;
             if (pts > now)
-                usleep(pts - now);
+                /* usleep(pts - now) */ ;
         }
 
         /* if output time reached then transcode raw format,
@@ -1889,19 +2075,19 @@
                 int size;
                 char *logbuffer;
 
+                snprintf(logfilename, sizeof(logfilename), "%s-%d-enc.log",
+                         pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX,
+                         i);
+
+                codec->encoder_stage_log = av_strdup(logfilename);
+
                 snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
                          pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX,
                          i);
-                if (codec->flags & CODEC_FLAG_PASS1) {
-                    f = fopen(logfilename, "w");
-                    if (!f) {
-                        fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno));
-                        av_exit(1);
-                    }
-                    ost->logfile = f;
-                } else {
+                
+                if (codec->flags & CODEC_FLAG_PASS2) {
                     /* read the log file */
-                    f = fopen(logfilename, "r");
+                    f = av_fopen(logfilename, "r");
                     if (!f) {
                         fprintf(stderr, "Cannot read log file '%s' for pass-2 encoding: %s\n", logfilename, strerror(errno));
                         av_exit(1);
@@ -1919,6 +2105,15 @@
                     logbuffer[size] = '\0';
                     codec->stats_in = logbuffer;
                 }
+
+                if (codec->flags & CODEC_FLAG_PASS1) {
+                    f = av_fopen(logfilename, "w");
+                    if (!f) {
+                        fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno));
+                        av_exit(1);
+                    }
+                    ost->logfile = f;
+                }
             }
         }
         if(codec->codec_type == CODEC_TYPE_VIDEO){
@@ -2172,6 +2367,11 @@
             goto discard_packet;
         ist_index = file_table[file_index].ist_index + pkt.stream_index;
         ist = ist_table[ist_index];
+
+        if (subtitle_etching && ist->st->codec->codec_type == CODEC_TYPE_SUBTITLE) {
+            if (ist->discard && !ist->decoding_needed) ist->discard = 0, ist->decoding_needed = 1;
+        }
+
         if (ist->discard)
             goto discard_packet;
 
@@ -2678,6 +2878,56 @@
         subtitle_codec_tag= arg[0] + (arg[1]<<8) + (arg[2]<<16) + (arg[3]<<24);
 }
 
+static void opt_subtitle_palette(const char *arg)
+{
+    FILE *ifo_file;
+    size_t ifo_size;
+    uint8_t *ifo;
+    int vts_pgcit, pgcs, pgc;
+
+    ifo_file = av_fopen(arg, "rb");
+    if (!ifo_file) return;
+
+    fseek(ifo_file, 0, FILE_END);
+    ifo_size = ftell(ifo_file);
+    ifo = av_malloc(ifo_size);
+
+    fseek(ifo_file, 0, FILE_BEGIN);
+    fread(ifo, 1, ifo_size, ifo_file);
+    fclose(ifo_file);
+
+    if (memcmp(ifo, "DVDVIDEO-VTS", 12) != 0)
+      goto quit;
+
+    vts_pgcit = (ifo[0xcc] << 24 | ifo[0xcd] << 16 | ifo[0xce] << 8 | ifo[0xcf]) * 2048;
+    if (!vts_pgcit) goto quit;
+
+    pgcs = ifo[vts_pgcit + 0] << 8 | ifo[vts_pgcit + 1];
+    for (pgc = 0; pgc < pgcs; ++pgc) {
+        int pgc_start, pal_start;
+        int empty, i, yuv;
+
+        pgc_start = vts_pgcit + (ifo[vts_pgcit + 8 + 8 * pgc + 4] << 24 | ifo[vts_pgcit + 8 + 8 * pgc + 5] << 16 | ifo[vts_pgcit + 8 + 8 * pgc + 6] << 8 | ifo[vts_pgcit + 8 + 8 * pgc + 7]);
+        pal_start = pgc_start + 0xA5;
+
+        empty = 1;
+        for (i = 0; empty && i < 16 * 4; ++i) empty = ifo[pal_start + i] == 0;
+
+        if (!empty) {
+            for (i = 0; i < 16; ++i) {
+                yuv = ifo[pal_start + i * 4 + 0] << 16 | ifo[pal_start + i * 4 + 1] << 8 | ifo[pal_start + i * 4 + 2];
+                subtitle_etch.palette[i] = yuv;
+            }
+
+            subtitle_etch.have_palette = 1;
+            break;
+        }
+    }
+
+quit:
+    av_free(ifo);
+}
+
 static void opt_map(const char *arg)
 {
     AVStreamMap *m;
@@ -3108,8 +3358,10 @@
         if (do_pass) {
             if (do_pass == 1) {
                 video_enc->flags |= CODEC_FLAG_PASS1;
+            } else if (do_pass == 2) {
+                video_enc->flags |= CODEC_FLAG_PASS2;
             } else {
-                video_enc->flags |= CODEC_FLAG_PASS2;
+                video_enc->flags |= CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2;
             }
         }
     }
@@ -3424,8 +3676,8 @@
 {
     int pass;
     pass = atoi(pass_str);
-    if (pass != 1 && pass != 2) {
-        fprintf(stderr, "pass number can be only 1 or 2\n");
+    if (pass != 1 && pass != 2 && pass != 3) {
+        fprintf(stderr, "pass number can be only 1, 2 or 3\n");
         av_exit(1);
     }
     do_pass = pass;
@@ -3487,8 +3739,18 @@
     vfprintf(stdout, fmt, vl);
 }
 
+#include "build_clonedvd\appinfo.h"
+#include "libextern\libx264\x264\libinfo.h"
+
 static void show_help(void)
 {
+    printf("%s version " FFMPEG_VERSION ", Copyright (c) %d-%d Fabrice Bellard, et al.\n", program_name, program_birth_year, this_year);
+    printf("NOTICE: Program cannot be called directly. No parameter information given.\n\n");
+    printf("        Compiled on " FFMPEG_NOW " by gcc " __VERSION__ "\n");
+    printf("          with ffmpeg revision " FFMPEG_REV " from " FFMPEG_REV_DATE "\n");
+    printf("          with x264   revision " LIBX264_REV "  from " LIBX264_REV_DATE "\n");
+    return;
+
     av_log_set_callback(log_callback_help);
     printf("usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...\n"
            "Hyper fast Audio and Video encoder\n");
@@ -3588,7 +3850,7 @@
 
         opt_frame_size(norm ? "352x240" : "352x288");
         opt_frame_rate(NULL, frame_rates[norm]);
-        opt_default("gop", norm ? "18" : "15");
+        opt_default("g", norm ? "18" : "15");
 
         opt_default("b", "1150000");
         opt_default("maxrate", "1150000");
@@ -3616,7 +3878,7 @@
 
         opt_frame_size(norm ? "480x480" : "480x576");
         opt_frame_rate(NULL, frame_rates[norm]);
-        opt_default("gop", norm ? "18" : "15");
+        opt_default("g", norm ? "18" : "15");
 
         opt_default("b", "2040000");
         opt_default("maxrate", "2516000");
@@ -3638,7 +3900,7 @@
 
         opt_frame_size(norm ? "720x480" : "720x576");
         opt_frame_rate(NULL, frame_rates[norm]);
-        opt_default("gop", norm ? "18" : "15");
+        opt_default("g", norm ? "18" : "15");
 
         opt_default("b", "6000000");
         opt_default("maxrate", "9000000");
@@ -3718,19 +3980,19 @@
 
     for(i=!base[0]; i<2 && !f; i++){
         snprintf(filename, sizeof(filename), "%s%s/%s.ffpreset", base[i], i ? "" : "/.ffmpeg", arg);
-        f= fopen(filename, "r");
+        f= av_fopen(filename, "r");
         if(!f){
             char *codec_name= *opt == 'v' ? video_codec_name :
                               *opt == 'a' ? audio_codec_name :
                                             subtitle_codec_name;
             snprintf(filename, sizeof(filename), "%s%s/%s-%s.ffpreset", base[i],  i ? "" : "/.ffmpeg", codec_name, arg);
-            f= fopen(filename, "r");
+            f= av_fopen(filename, "r");
         }
     }
     if(!f && ((arg[0]=='.' && arg[1]=='/') || arg[0]=='/' ||
               is_dos_path(arg))){
         av_strlcpy(filename, arg, sizeof(filename));
-        f= fopen(filename, "r");
+        f= av_fopen(filename, "r");
     }
 
     if(!f){
@@ -3869,6 +4131,9 @@
     { "newsubtitle", OPT_SUBTITLE, {(void*)opt_new_subtitle_stream}, "add a new subtitle stream to the current output stream" },
     { "slang", HAS_ARG | OPT_STRING | OPT_SUBTITLE, {(void *)&subtitle_language}, "set the ISO 639 language code (3 letters) of the current subtitle stream" , "code" },
     { "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE, {(void*)opt_subtitle_tag}, "force subtitle tag/fourcc", "fourcc/tag" },
+    { "se", OPT_BOOL | OPT_SUBTITLE, {(void*)&subtitle_etching}, "subtitle etching" },
+    { "sid", HAS_ARG | OPT_INT | OPT_SUBTITLE, {(void*)&subtitle_id}, "subtitle identifer (0x20..0x3F)" },
+    { "spal", HAS_ARG | OPT_SUBTITLE, {(void*)&opt_subtitle_palette}, "subtitle palette (from .ifo file)" },
 
     /* grab options */
     { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "set video grab channel (DV1394 only)", "channel" },
@@ -3896,6 +4161,52 @@
     int i;
     int64_t ti;
 
+    /* load parameters by UNICODE and then convert them to UTF-8
+     * linux normally initiates parameters as UTF-8, windows has UNICODE, so sync them
+     */
+    {
+        WCHAR *CommandLineW = GetCommandLineW();
+        CHAR   CommandLineA[2048];
+
+        CHAR *PR = CommandLineA, *PW = PR, *PP[256]; INT PPN = 0; BOOL InEscape = FALSE; PP[PPN++] = PW;
+
+        WideCharToMultiByte(CP_UTF8, 0, CommandLineW, -1, CommandLineA, sizeof(CommandLineA), NULL, NULL);
+
+        while (*PR) {
+
+            if (*PR == '\\' && PR[1] == '\\')
+                *PW++ = '\\', PR++;
+
+            else if (*PR == '\\' && PR[1] == '"')
+                *PW++ = '"', PR++;
+
+            else if (*PR == '"')
+                InEscape = !InEscape;
+
+            else if (*PR == ' ' && !InEscape) {
+                *PW++ = 0, PP[PPN++] = PW;
+
+                if (PPN >= sizeof(PP) / sizeof(PP[0]))
+                    return av_exit(1);
+            }
+
+            else
+                *PW++ = *PR;
+
+            PR++;
+        }
+
+        *PW = 0;
+
+        argc = PPN;
+        argv = PP;
+    }
+
+    /* those pthread-"be"holes don't check for initialized crit_sects nor do they call it themselves.
+     * it should be pthreads responsibilty to check for a proper environment, not ours!!!
+     */
+    pthread_win32_process_attach_np();
+
     avcodec_register_all();
     avdevice_register_all();
     av_register_all();
Index: libavcodec/avcodec.h
===================================================================
--- libavcodec/avcodec.h	(revision 19189)
+++ libavcodec/avcodec.h	(working copy)
@@ -1607,6 +1607,20 @@
 #define FF_PRED_PLANE  1
 #define FF_PRED_MEDIAN 2
 
+     /**
+     * enhanced encoder configuration (for x264)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+     char *encoder_cfg;
+
+     /**
+     * enhanced encoder staging file (for x264)
+     * - encoding: Set by user.
+     * - decoding: unused
+     */
+     char *encoder_stage_log;
+
     /**
      * sample aspect ratio (0 if unknown)
      * That is the width of a pixel divided by the height of the pixel.
@@ -2726,6 +2740,10 @@
      * struct.
      */
     char *ass;
+    /**
+     * used for scaled subtitle pictures
+     */
+    uint32_t *image;
 } AVSubtitleRect;
 
 typedef struct AVSubtitle {
@@ -2734,6 +2752,8 @@
     uint32_t end_display_time; /* relative to packet pts, in ms */
     unsigned num_rects;
     AVSubtitleRect **rects;
+    int have_palette;
+    uint32_t palette[16];
 } AVSubtitle;
 
 /* packet functions */
@@ -3670,6 +3690,11 @@
             int padtop, int padbottom, int padleft, int padright, int *color);
 
 unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
+/**
+ * Harddup image.
+ */
+int av_picture_harddup(AVPicture *dst, const AVPicture *src, int pix_fmt, int width, int height, 
+            const AVSubtitle *subtitle);
 
 /**
  * Parses str and put in width_ptr and height_ptr the detected values.
@@ -3753,4 +3778,4 @@
  */
 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
 
-#endif /* AVCODEC_AVCODEC_H */
+#endif /* AVCODEC_AVCODEC_H */
\ No newline at end of file
Index: libavcodec/dvdsubdec.c
===================================================================
--- libavcodec/dvdsubdec.c	(revision 19189)
+++ libavcodec/dvdsubdec.c	(working copy)
@@ -158,6 +158,20 @@
     }
 }
 
+static void have_palette(uint32_t *rgba_palette,
+                         uint8_t *colormap,
+                         uint8_t *alpha,
+                         uint32_t *palette)
+{
+    int i, a, c;
+
+    for (i = 0; i < 4; i++) {
+        a = alpha[i];
+        c = palette[colormap[i]];
+        rgba_palette[i] = (c & 0x00ffffff) | ((a * 17) << 24);
+    }
+}
+
 #define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a))
 
 static int decode_dvd_subtitles(AVSubtitle *sub_header,
@@ -314,7 +328,7 @@
             w = x2 - x1 + 1;
             if (w < 0)
                 w = 0;
-            h = y2 - y1;
+            h = y2 - y1 + 1;
             if (h < 0)
                 h = 0;
             if (w > 0 && h > 0) {
@@ -346,8 +360,12 @@
                 } else {
                     sub_header->rects[0]->pict.data[1] = av_malloc(4 * 4);
                     sub_header->rects[0]->nb_colors = 4;
-                    guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1],
-                                  colormap, alpha, 0xffff00);
+                    if (sub_header->have_palette)
+                        have_palette((uint32_t*)sub_header->rects[0]->pict.data[1],
+                                     colormap, alpha, sub_header->palette);
+                    else
+                        guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1],
+                                      colormap, alpha, 0xffff00);
                 }
                 sub_header->rects[0]->x = x1;
                 sub_header->rects[0]->y = y1;
Index: libavcodec/imgconvert.c
===================================================================
--- libavcodec/imgconvert.c	(revision 19189)
+++ libavcodec/imgconvert.c	(working copy)
@@ -638,6 +638,8 @@
     return 0;
 }
 
+#define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
+
 int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width)
 {
     int w2;
@@ -657,6 +659,7 @@
     case PIX_FMT_YUVJ422P:
     case PIX_FMT_YUVJ444P:
     case PIX_FMT_YUVJ440P:
+        width = ALIGN(width, 64);
         w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
         picture->linesize[0] = width;
         picture->linesize[1] = w2;
@@ -1287,6 +1290,68 @@
         ps->pixel_type == FF_PIXEL_PLANAR;
 }
 
+static AVPicture temp_harddup;
+
+int av_picture_harddup(AVPicture *dst, const AVPicture *src, int pix_fmt, int width, int height, const AVSubtitle *subtitle)
+{
+    uint8_t *optr, *sptr;
+    int y_shift;
+    int x_shift;
+    int i, j, h, w, y, x, dy, dx;
+    int cc, c, ls;
+    double a;
+    uint32_t v, *pal;
+
+    if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB ||
+        !is_yuv_planar(&pix_fmt_info[pix_fmt])) return -1;
+
+    if (!temp_harddup.data[0])
+      avpicture_alloc(&temp_harddup, pix_fmt, width, height);
+
+    dst->data[0] = temp_harddup.data[0];
+    dst->data[1] = temp_harddup.data[1];
+    dst->data[2] = temp_harddup.data[2];
+
+    dst->linesize[0] = temp_harddup.linesize[0];
+    dst->linesize[1] = temp_harddup.linesize[1];
+    dst->linesize[2] = temp_harddup.linesize[2];
+
+    av_picture_copy(dst, src, pix_fmt, width, height);
+
+    for (i = 0; i < 3; i++) {
+        x_shift = i ? pix_fmt_info[pix_fmt].x_chroma_shift : 0;
+        y_shift = i ? pix_fmt_info[pix_fmt].y_chroma_shift : 0;
+
+        for (j = 0; j < subtitle->num_rects; ++j) {
+            AVSubtitleRect *r = subtitle->rects[j];
+
+            optr = dst->data[i] + dst->linesize[i] * (r->y >> y_shift) + (r->x >> x_shift);
+            sptr = r->pict.data[0];
+            pal = (uint32_t*)r->pict.data[1];
+
+            dy = 1 << y_shift;
+            dx = 1 << x_shift;
+            h  = r->h;
+            w  = r->w;
+            cc = 16 - i * 8;
+            ls = r->pict.linesize[0];
+
+            for (y = 0; y < h; y += dy) {
+                for (x = 0; x < w; x += dx) {
+                    v = r->image ? r->image[y * ls + x] : pal[sptr[y * ls + x]];
+                    if (v & 0xFF000000) {
+                        a = 1.0 / 255.0 * (v >> 24);
+                        c = (v >> cc) & 0xff;
+                        optr[x >> x_shift] = av_clip((int)((1 - a) * optr[x >> x_shift] + a * c), 0, 255);
+                    }
+                }
+                optr += dst->linesize[i];
+            }
+        }
+    }
+    return 0;
+}
+
 int av_picture_crop(AVPicture *dst, const AVPicture *src,
               int pix_fmt, int top_band, int left_band)
 {
Index: libavcodec/libmp3lame.c
===================================================================
--- libavcodec/libmp3lame.c	(revision 19189)
+++ libavcodec/libmp3lame.c	(working copy)
@@ -172,6 +172,8 @@
                 s->buffer + s->buffer_index,
                 BUFFER_SIZE - s->buffer_index
                 );
+        if (lame_result == -1)
+          return 0; // not enough samples
     }
 
     if(lame_result < 0){
Index: libavcodec/libx264.c
===================================================================
--- libavcodec/libx264.c	(revision 19189)
+++ libavcodec/libx264.c	(working copy)
@@ -255,7 +255,7 @@
     x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
 
     x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
-    x4->params.i_log_level = X264_LOG_DEBUG;
+    x4->params.i_log_level = X264_LOG_INFO;
 
     x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
 
@@ -267,9 +267,39 @@
         x4->params.b_repeat_headers = 0;
     }
 
+    if (avctx->encoder_stage_log) {
+        x4->params.rc.psz_stat_in  = avctx->encoder_stage_log;
+        x4->params.rc.psz_stat_out = avctx->encoder_stage_log;
+    }
+
+    if (avctx->encoder_cfg) {
+        char *P = avctx->encoder_cfg, *V, *N; int Last = 0;
+
+        while (!Last) {
+            N = strchr(P, '|');
+            V = strchr(P, '='); 
+
+            if (!N) N = P + strlen(P), Last = 1;
+            if (V > N) V = NULL;
+
+            *N = 0; if (V) *V++ = 0;
+
+            if (x264_param_parse(&x4->params, P, V))
+            {
+              av_log(avctx, AV_LOG_ERROR, "x264_param_parse() revoked %s with value '%s'\n", P, V);
+              return -1;
+            }
+
+            P = N + 1;
+        }
+    }
+
     x4->enc = x264_encoder_open(&x4->params);
     if(!x4->enc)
+    {
+        av_log(avctx, AV_LOG_ERROR, "x264_encoder_open() revoked configuration\n");
         return -1;
+    }
 
     avctx->coded_frame = &x4->out_pic;
 
Index: libavcodec/Makefile
===================================================================
--- libavcodec/Makefile	(revision 19189)
+++ libavcodec/Makefile	(working copy)
@@ -37,7 +37,7 @@
 # decoders/encoders/hardware accelerators
 OBJS-$(CONFIG_AAC_DECODER)             += aac.o aactab.o mpeg4audio.o aac_parser.o aac_ac3_parser.o
 OBJS-$(CONFIG_AASC_DECODER)            += aasc.o msrledec.o
-OBJS-$(CONFIG_AC3_DECODER)             += eac3dec.o ac3dec.o ac3tab.o ac3dec_data.o ac3.o
+OBJS-$(CONFIG_AC3_DECODER)             += eac3dec.o ac3dec.o ac3tab.o ac3dec_data.o ac3.o ac3_parser.o aac_ac3_parser.o
 OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc.o ac3tab.o ac3.o
 OBJS-$(CONFIG_ALAC_DECODER)            += alac.o
 OBJS-$(CONFIG_ALAC_ENCODER)            += alacenc.o lpc.o
Index: libavcodec/mpegvideo.c
===================================================================
--- libavcodec/mpegvideo.c	(revision 19189)
+++ libavcodec/mpegvideo.c	(working copy)
@@ -726,6 +726,30 @@
     avcodec_default_free_buffers(s->avctx);
 }
 
+AVFrame *MPV_get_current_picture(AVCodecContext *avctx)
+{
+   MpegEncContext *s = avctx->priv_data;
+
+   /* current_picture_ptr is of type Picture* with is derived from AVFrame* [FF_COMMON_FRAME] */
+   return (AVFrame *) s->current_picture_ptr;
+}
+
+AVFrame *MPV_get_next_picture(AVCodecContext *avctx)
+{
+   MpegEncContext *s = avctx->priv_data;
+
+   /* next_picture_ptr is of type Picture* with is derived from AVFrame* [FF_COMMON_FRAME] */
+   return (AVFrame *) s->next_picture_ptr;
+}
+
+AVFrame *MPV_get_last_picture(AVCodecContext *avctx)
+{
+   MpegEncContext *s = avctx->priv_data;
+
+   /* last_picture_ptr is of type Picture* with is derived from AVFrame* [FF_COMMON_FRAME] */
+   return (AVFrame *) s->last_picture_ptr;
+}
+
 void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3])
 {
     int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1];
Index: libavcodec/mpegvideo.h
===================================================================
--- libavcodec/mpegvideo.h	(revision 19189)
+++ libavcodec/mpegvideo.h	(working copy)
@@ -678,6 +678,9 @@
 void MPV_decode_defaults(MpegEncContext *s);
 int MPV_common_init(MpegEncContext *s);
 void MPV_common_end(MpegEncContext *s);
+AVFrame *MPV_get_current_picture(AVCodecContext *avctx);
+AVFrame *MPV_get_next_picture(AVCodecContext *avctx);
+AVFrame *MPV_get_last_picture(AVCodecContext *avctx);
 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]);
 int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
 void MPV_frame_end(MpegEncContext *s);
Index: libavcodec/mpegvideo_enc.c
===================================================================
--- libavcodec/mpegvideo_enc.c	(revision 19189)
+++ libavcodec/mpegvideo_enc.c	(working copy)
@@ -437,8 +437,12 @@
     if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4
        && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO
        && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){
+#if VETO_MULTITHREADED
         av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n");
         return -1;
+#else   
+        s->avctx->thread_count = 1;
+#endif
     }
 
     if(s->avctx->thread_count > 1)
Index: libavcodec/options.c
===================================================================
--- libavcodec/options.c	(revision 19189)
+++ libavcodec/options.c	(working copy)
@@ -177,6 +177,7 @@
 {"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
 {"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
 {"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
+{"encoder_cfg", "set encoder configuarion", OFFSET(encoder_cfg), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
 {"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
 {"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
 {"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|E},
Index: libavcodec/utils.c
===================================================================
--- libavcodec/utils.c	(revision 19189)
+++ libavcodec/utils.c	(working copy)
@@ -1047,7 +1047,7 @@
         return -1;
     }
 #if !HAVE_MKSTEMP
-    fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
+    fd = av_open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
 #else
     snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
     fd = mkstemp(*filename);
Index: libavformat/allformats.c
===================================================================
--- libavformat/allformats.c	(revision 19189)
+++ libavformat/allformats.c	(working copy)
@@ -66,6 +66,7 @@
     REGISTER_DEMUXER  (BFI, bfi);
     REGISTER_DEMUXER  (C93, c93);
     REGISTER_DEMUXER  (CAVSVIDEO, cavsvideo);
+    REGISTER_DEMUXER  (CHAM, cham);
     REGISTER_MUXER    (CRC, crc);
     REGISTER_MUXDEMUX (DAUD, daud);
     REGISTER_MUXDEMUX (DIRAC, dirac);
Index: libavformat/avformat.h
===================================================================
--- libavformat/avformat.h	(revision 19189)
+++ libavformat/avformat.h	(working copy)
@@ -566,6 +566,8 @@
 #define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.
 #define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
 #define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
+#define AVFMT_FLAG_NOODML       0x0008
+#define AVFMT_FLAG_NOINFO       0x0010
 
     int loop_input;
     /** decoding: size of data to probe; encoding: unused. */
Index: libavformat/avienc.c
===================================================================
--- libavformat/avienc.c	(revision 19189)
+++ libavformat/avienc.c	(working copy)
@@ -160,6 +160,14 @@
     put_le32(pb, 14 * 4);
     bitrate = 0;
 
+    //if (s->flags & AVFMT_FLAG_NOODML)
+    //    s->flags |= AVFMT_FLAG_NOINFO;
+
+    if (s->flags & AVFMT_FLAG_NOODML)
+        av_log(s, AV_LOG_INFO, "switching to no-odml mode\n");
+    if (s->flags & AVFMT_FLAG_NOINFO)
+        av_log(s, AV_LOG_INFO, "switching to non-info/vprp data store mode\n");
+
     video_enc = NULL;
     for(n=0;n<s->nb_streams;n++) {
         stream = s->streams[n]->codec;
@@ -266,7 +274,7 @@
         end_tag(pb, strf);
       }
 
-        if (!url_is_streamed(pb)) {
+        if (!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_NOODML)) {
             unsigned char tag[5];
             int j;
 
@@ -290,7 +298,7 @@
             end_tag(pb, avi->indexes[i].indx_start);
         }
 
-        if(   stream->codec_type == CODEC_TYPE_VIDEO
+        if(   stream->codec_type == CODEC_TYPE_VIDEO && !(s->flags & AVFMT_FLAG_NOINFO)
            && s->streams[i]->sample_aspect_ratio.num>0
            && s->streams[i]->sample_aspect_ratio.den>0){
             int vprp= start_tag(pb, "vprp");
@@ -325,7 +333,7 @@
         end_tag(pb, list2);
     }
 
-    if (!url_is_streamed(pb)) {
+    if (!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_NOODML)) {
         /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
         avi->odml_list = start_tag(pb, "JUNK");
         put_tag(pb, "odml");
@@ -338,6 +346,7 @@
 
     end_tag(pb, list1);
 
+    if (!(s->flags & AVFMT_FLAG_NOINFO)) {
     list2 = start_tag(pb, "LIST");
     put_tag(pb, "INFO");
     avi_write_info_tag2(s, "INAM", "Title", NULL);
@@ -350,6 +359,7 @@
     if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
         avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT);
     end_tag(pb, list2);
+    }
 
     /* some padding for easier tag editing */
     list2 = start_tag(pb, "JUNK");
@@ -373,7 +383,7 @@
     char ix_tag[] = "ix00";
     int i, j;
 
-    assert(!url_is_streamed(pb));
+    assert(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_NOODML));
 
     if (avi->riff_id > AVI_MASTER_INDEX_SIZE)
         return -1;
@@ -491,7 +501,7 @@
     avi->packet_count[stream_index]++;
 
     // Make sure to put an OpenDML chunk when the file size exceeds the limits
-    if (!url_is_streamed(pb) &&
+    if (!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_NOODML) &&
         (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {
 
         avi_write_ix(s);
@@ -554,7 +564,7 @@
             end_tag(pb, avi->movi_list);
             res = avi_write_idx1(s);
             end_tag(pb, avi->riff_start);
-        } else {
+        } else if (!(s->flags & AVFMT_FLAG_NOODML)) {
             avi_write_ix(s);
             end_tag(pb, avi->movi_list);
             end_tag(pb, avi->riff_start);
Index: libavformat/chamdec.c
===================================================================
--- libavformat/chamdec.c	(revision 0)
+++ libavformat/chamdec.c	(revision 0)
@@ -0,0 +1,116 @@
+/*
+ * CHAMELEON format demuxer
+ * Copyright (c) 2009 Fernando Cabezas <fernando@slysoft.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <string.h>
+#include "avformat.h"
+
+static int cham_probe(AVProbeData *p)
+{
+    if (memcmp(p->buf, "chameleon", 9) == 0)
+        return AVPROBE_SCORE_MAX;
+
+    return 0;
+}
+
+static int cham_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+    AVStream *st; ByteIOContext *pb = s->pb; int vid, aid, sid;
+
+    url_fskip(pb, 9);
+
+    vid = get_byte(pb);
+    if (vid == 0xE0)
+    {
+      st = av_new_stream(s, 0);
+      if (!st)
+        return AVERROR(ENOMEM);
+
+      st->codec->codec_type = CODEC_TYPE_VIDEO;
+      st->codec->codec_id = CODEC_ID_MPEG2VIDEO;
+      st->codec->time_base.num = 1;
+      st->codec->time_base.den = 90000;
+      st->id = vid;
+    }
+
+    aid = get_byte(pb);
+    if (0x80 <= aid && aid <= 0x87)
+    {
+      st = av_new_stream(s, 1);
+      if (!st)
+        return AVERROR(ENOMEM);
+
+      st->codec->codec_type = CODEC_TYPE_AUDIO;
+      st->codec->codec_id = 0x80 <= aid && aid <= 0x87 ? CODEC_ID_AC3 : CODEC_ID_AC3;
+      st->codec->time_base.num = 1;
+      st->codec->time_base.den = 90000;
+      st->id = aid;
+    }
+
+    sid = get_byte(pb);
+    if (0x20 <= sid && sid <= 0x3F)
+    {
+      st = av_new_stream(s, 2);
+      if (!st)
+        return AVERROR(ENOMEM);
+
+      st->codec->codec_type = CODEC_TYPE_SUBTITLE;
+      st->codec->codec_id = CODEC_ID_DVD_SUBTITLE;
+      st->codec->time_base.num = 1;
+      st->codec->time_base.den = 90000;
+      st->id = sid;
+    }
+
+    //av_log(s, AV_LOG_ERROR, "CHAMELEON FORMAT START %xh / %xh / %xh\n", vid, aid, sid);
+    return 0;
+}
+
+static int cham_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    int stream, pkt_size, pkt_duration; int64_t pkt_pts; ByteIOContext *pb = s->pb;
+
+    stream = get_be32(pb);
+    pkt_size = get_be32(pb);
+    pkt_pts = get_be64(pb);
+    pkt_duration = get_be32(pb);
+
+    if (stream == 0 && pkt_size == 0 && pkt_pts == 0 && pkt_duration == 0)
+      return AVERROR_EOF;
+
+    //av_log(s, AV_LOG_ERROR, "CHAMELEON PACKET: stream=%d, size=%d, pts=%"PRId64", duration=%d\n", stream, pkt_size, pkt_pts, pkt_duration);
+
+    if (av_get_packet(pb, pkt, pkt_size) <= 0)
+        return AVERROR(EIO);
+
+    pkt->stream_index = stream;
+    pkt->pts = pkt_pts;
+    pkt->duration = pkt_duration;
+    pkt->flags |= PKT_FLAG_KEY;
+    return 0;
+}
+
+AVInputFormat cham_demuxer = {
+    "cham",
+    NULL_IF_CONFIG_SMALL("CHAMELEON format"),
+    0,
+    cham_probe,
+    cham_read_header,
+    cham_read_packet,
+};
Index: libavformat/file.c
===================================================================
--- libavformat/file.c	(revision 19189)
+++ libavformat/file.c	(working copy)
@@ -50,7 +50,7 @@
 #ifdef O_BINARY
     access |= O_BINARY;
 #endif
-    fd = open(filename, access, 0666);
+    fd = av_open(filename, access, 0666);
     if (fd < 0)
         return AVERROR(ENOENT);
     h->priv_data = (void *) (intptr_t) fd;
Index: libavformat/Makefile
===================================================================
--- libavformat/Makefile	(revision 19189)
+++ libavformat/Makefile	(working copy)
@@ -34,6 +34,7 @@
 OBJS-$(CONFIG_BFI_DEMUXER)               += bfi.o
 OBJS-$(CONFIG_C93_DEMUXER)               += c93.o vocdec.o voc.o
 OBJS-$(CONFIG_CAVSVIDEO_DEMUXER)         += raw.o
+OBJS-$(CONFIG_CHAM_DEMUXER)              += chamdec.o
 OBJS-$(CONFIG_CRC_MUXER)                 += crcenc.o
 OBJS-$(CONFIG_DAUD_DEMUXER)              += daud.o
 OBJS-$(CONFIG_DAUD_MUXER)                += daud.o
Index: libavformat/options.c
===================================================================
--- libavformat/options.c	(revision 19189)
+++ libavformat/options.c	(working copy)
@@ -46,6 +46,8 @@
 {"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, D|E, "fflags"},
 {"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNIDX, INT_MIN, INT_MAX, D, "fflags"},
 {"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_GENPTS, INT_MIN, INT_MAX, D, "fflags"},
+{"noodml", "don't create odml avi files", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_NOODML, INT_MIN, INT_MAX, E, "fflags"},
+{"noinfo", "don't create info/vprp data in avi files", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_NOINFO, INT_MIN, INT_MAX, E, "fflags"},
 #if LIBAVFORMAT_VERSION_INT < (53<<16)
 {"track", " set the track number", OFFSET(track), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
 {"year", "set the year", OFFSET(year), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E},
Index: libavutil/common.h
===================================================================
--- libavutil/common.h	(revision 19189)
+++ libavutil/common.h	(working copy)
@@ -28,7 +28,11 @@
 
 #include <ctype.h>
 #include <errno.h>
+#ifndef _MSC_VER
 #include <inttypes.h>
+#else
+#include <stdint.h>
+#endif
 #include <limits.h>
 #include <math.h>
 #include <stdio.h>
@@ -75,7 +79,7 @@
 
 #ifndef av_cold
 #if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
-#    define av_cold __attribute__((cold))
+#    define av_cold
 #else
 #    define av_cold
 #endif
Index: libavutil/file.c
===================================================================
--- libavutil/file.c	(revision 0)
+++ libavutil/file.c	(revision 0)
@@ -0,0 +1,39 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "common.h"
+#include "file.h"
+#include <windows.h>
+
+FILE* av_fopen(const char *filename, const char *mode)
+{
+    unsigned short FileNameW[1024], ModeW[32];
+
+    MultiByteToWideChar(CP_UTF8, 0, filename, -1, FileNameW, sizeof(FileNameW));
+    MultiByteToWideChar(CP_UTF8, 0, mode,     -1, ModeW,     sizeof(ModeW));
+
+    return _wfopen(FileNameW, ModeW);
+}
+
+int av_open(const char *filename, int oflag, int pmode)
+{
+    unsigned short FileNameW[1024];
+
+    MultiByteToWideChar(CP_UTF8, 0, filename, -1, FileNameW, sizeof(FileNameW));
+
+    return _wopen(FileNameW, oflag, pmode);
+}
Index: libavutil/file.h
===================================================================
--- libavutil/file.h	(revision 0)
+++ libavutil/file.h	(revision 0)
@@ -0,0 +1,27 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_FILE_H
+#define AVUTIL_FILE_H
+
+#include <stdio.h>
+
+FILE* av_fopen(const char *filename, const char *mode);
+int av_open(const char *filename, int oflag, int pmode);
+
+#endif /* AVUTIL_FILE_H */
Index: libavutil/Makefile
===================================================================
--- libavutil/Makefile	(revision 19189)
+++ libavutil/Makefile	(working copy)
@@ -9,6 +9,7 @@
           common.h                                                      \
           crc.h                                                         \
           fifo.h                                                        \
+          file.h                                                        \
           intfloat_readwrite.h                                          \
           log.h                                                         \
           lzo.h                                                         \
@@ -26,6 +27,7 @@
        crc.o                                                            \
        des.o                                                            \
        fifo.o                                                           \
+       file.o                                                           \
        intfloat_readwrite.o                                             \
        lfg.o                                                            \
        lls.o                                                            \
Index: stdint.h
===================================================================
--- stdint.h	(revision 0)
+++ stdint.h	(revision 0)
@@ -0,0 +1,206 @@
+/* ISO C9x  7.18  Integer types <stdint.h>
+ * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
+ *
+ *  THIS SOFTWARE IS NOT COPYRIGHTED
+ *
+ *  Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz>
+ *
+ *  This source code is offered for use in the public domain. You may
+ *  use, modify or distribute it freely.
+ *
+ *  This code is distributed in the hope that it will be useful but
+ *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
+ *  DISCLAIMED. This includes but is not limited to warranties of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *  Date: 2000-12-02
+ */
+
+
+#ifndef _STDINT_H
+#define _STDINT_H
+#define __need_wint_t
+#define __need_wchar_t
+#include <stddef.h>
+
+/* 7.18.1.1  Exact-width integer types */
+typedef signed char int8_t;
+typedef unsigned char   uint8_t;
+typedef short  int16_t;
+typedef unsigned short  uint16_t;
+typedef int  int32_t;
+typedef unsigned   uint32_t;
+typedef long long  int64_t;
+typedef unsigned long long   uint64_t;
+
+/* 7.18.1.2  Minimum-width integer types */
+typedef signed char int_least8_t;
+typedef unsigned char   uint_least8_t;
+typedef short  int_least16_t;
+typedef unsigned short  uint_least16_t;
+typedef int  int_least32_t;
+typedef unsigned   uint_least32_t;
+typedef long long  int_least64_t;
+typedef unsigned long long   uint_least64_t;
+
+/*  7.18.1.3  Fastest minimum-width integer types 
+ *  Not actually guaranteed to be fastest for all purposes
+ *  Here we use the exact-width types for 8 and 16-bit ints. 
+ */
+typedef char int_fast8_t;
+typedef unsigned char uint_fast8_t;
+typedef short  int_fast16_t;
+typedef unsigned short  uint_fast16_t;
+typedef int  int_fast32_t;
+typedef unsigned  int  uint_fast32_t;
+typedef long long  int_fast64_t;
+typedef unsigned long long   uint_fast64_t;
+
+/* 7.18.1.4  Integer types capable of holding object pointers */
+
+#ifndef _INTPTR_T_DEFINED
+#define _INTPTR_T_DEFINED
+#ifdef _WIN64
+  typedef __int64 intptr_t;
+#else
+  typedef int intptr_t;
+#endif
+#endif
+
+#ifndef _UINTPTR_T_DEFINED
+#define _UINTPTR_T_DEFINED
+#ifdef _WIN64
+  typedef unsigned __int64 uintptr_t;
+#else
+  typedef unsigned int uintptr_t;
+#endif
+#endif
+
+/* 7.18.1.5  Greatest-width integer types */
+typedef long long  intmax_t;
+typedef unsigned long long uintmax_t;
+
+/* 7.18.2  Limits of specified-width integer types */
+#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
+
+/* 7.18.2.1  Limits of exact-width integer types */
+#define INT8_MIN (-128) 
+#define INT16_MIN (-32768)
+#define INT32_MIN (-2147483647 - 1)
+#define INT64_MIN  (-9223372036854775807LL - 1)
+
+#define INT8_MAX 127
+#define INT16_MAX 32767
+#define INT32_MAX 2147483647
+#define INT64_MAX 9223372036854775807LL
+
+#define UINT8_MAX 0xff /* 255U */
+#define UINT16_MAX 0xffff /* 65535U */
+#define UINT32_MAX 0xffffffff  /* 4294967295U */
+#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
+
+/* 7.18.2.2  Limits of minimum-width integer types */
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST64_MIN INT64_MIN
+
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MAX INT64_MAX
+
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+/* 7.18.2.3  Limits of fastest minimum-width integer types */
+#define INT_FAST8_MIN INT8_MIN
+#define INT_FAST16_MIN INT16_MIN
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST64_MIN INT64_MIN
+
+#define INT_FAST8_MAX INT8_MAX
+#define INT_FAST16_MAX INT16_MAX
+#define INT_FAST32_MAX INT32_MAX
+#define INT_FAST64_MAX INT64_MAX
+
+#define UINT_FAST8_MAX UINT8_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+/* 7.18.2.4  Limits of integer types capable of holding
+    object pointers */
+#ifdef _WIN64
+#define INTPTR_MIN INT64_MIN
+#define INTPTR_MAX INT64_MAX
+#define UINTPTR_MAX UINT64_MAX
+#else
+#define INTPTR_MIN INT32_MIN
+#define INTPTR_MAX INT32_MAX
+#define UINTPTR_MAX UINT32_MAX
+#endif
+
+/* 7.18.2.5  Limits of greatest-width integer types */
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+/* 7.18.3  Limits of other integer types */
+#define PTRDIFF_MIN INTPTR_MIN
+#define PTRDIFF_MAX INTPTR_MAX
+
+#define SIG_ATOMIC_MIN INTPTR_MIN
+#define SIG_ATOMIC_MAX INTPTR_MAX
+
+#define SIZE_MAX UINTPTR_MAX
+
+#ifndef WCHAR_MIN  /* also in wchar.h */ 
+#define WCHAR_MIN 0
+#define WCHAR_MAX 0xffff /* UINT16_MAX */
+#endif
+
+/*
+ * wint_t is unsigned short for compatibility with MS runtime
+ */
+#define WINT_MIN 0
+#define WINT_MAX 0xffff /* UINT16_MAX */
+
+#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
+
+
+/* 7.18.4  Macros for integer constants */
+#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS)
+
+/* 7.18.4.1  Macros for minimum-width integer constants
+
+    Accoding to Douglas Gwyn <gwyn@arl.mil>:
+	"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
+	9899:1999 as initially published, the expansion was required
+	to be an integer constant of precisely matching type, which
+	is impossible to accomplish for the shorter types on most
+	platforms, because C99 provides no standard way to designate
+	an integer constant with width less than that of type int.
+	TC1 changed this to require just an integer constant
+	*expression* with *promoted* type."
+*/
+
+#define INT8_C(val) ((int8_t) + (val))
+#define UINT8_C(val) ((uint8_t) + (val##U))
+#define INT16_C(val) ((int16_t) + (val))
+#define UINT16_C(val) ((uint16_t) + (val##U))
+
+#define INT32_C(val) val##L
+#define UINT32_C(val) val##UL
+#define INT64_C(val) val##LL
+#define UINT64_C(val) val##ULL
+
+/* 7.18.4.2  Macros for greatest-width integer constants */
+#define INTMAX_C(val)  INT64_C(val)
+#define UINTMAX_C(val) UINT64_C(val)
+
+#endif  /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
+
+#endif
