]> git.sesse.net Git - ffmpeg/blobdiff - ffmpeg.c
10000l
[ffmpeg] / ffmpeg.c
index 21104f9ff481a3cbf70e6295be87081119d6b738..52492646dd4536dbca0ccfd267e5355e355fe2d1 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -111,13 +111,20 @@ static int video_codec_id = CODEC_ID_NONE;
 static int same_quality = 0;
 static int b_frames = 0;
 static int mb_decision = FF_MB_DECISION_SIMPLE;
+static int mb_cmp = FF_CMP_SAD;
+static int sub_cmp = FF_CMP_SAD;
+static int cmp = FF_CMP_SAD;
 static int use_4mv = 0;
 static int use_obmc = 0;
 static int use_aic = 0;
 static int use_aiv = 0;
 static int use_umv = 0;
+static int use_alt_scan = 0;
+static int use_trell = 0;
+static int use_scan_offset = 0;
 static int do_deinterlace = 0;
-static int do_interlace = 0;
+static int do_interlace_dct = 0;
+static int do_interlace_me = 0;
 static int workaround_bugs = FF_BUG_AUTODETECT;
 static int error_resilience = 2;
 static int error_concealment = 3;
@@ -125,8 +132,12 @@ static int dct_algo = 0;
 static int idct_algo = 0;
 static int use_part = 0;
 static int packet_size = 0;
+static int error_rate = 0;
 static int strict = 0;
+static int top_field_first = -1;
+static int noise_reduction = 0;
 static int debug = 0;
+static int debug_mv = 0;
 extern int loop_input; /* currently a hack */
 
 static int gop_size = 12;
@@ -465,7 +476,7 @@ static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void
 static void do_video_out(AVFormatContext *s, 
                          AVOutputStream *ost, 
                          AVInputStream *ist,
-                         AVPicture *in_picture,
+                         AVFrame *in_picture,
                          int *frame_size, AVOutputStream *audio_sync)
 {
     int nb_frames, i, ret;
@@ -557,13 +568,13 @@ static void do_video_out(AVFormatContext *s,
         avpicture_fill(formatted_picture, buf, target_pixfmt, dec->width, dec->height);
         
         if (img_convert(formatted_picture, target_pixfmt, 
-                        in_picture, dec->pix_fmt, 
+                        (AVPicture *)in_picture, dec->pix_fmt, 
                         dec->width, dec->height) < 0) {
             fprintf(stderr, "pixel format conversion not handled\n");
             goto the_end;
         }
     } else {
-        formatted_picture = in_picture;
+        formatted_picture = (AVPicture *)in_picture;
     }
 
     /* XXX: resampling could be done before raw format convertion in
@@ -627,7 +638,16 @@ static void do_video_out(AVFormatContext *s,
             
             memset(&big_picture, 0, sizeof(AVFrame));
             *(AVPicture*)&big_picture= *final_picture;
-                        
+            /* better than nothing: use input picture interlaced
+               settings */
+            big_picture.interlaced_frame = in_picture->interlaced_frame;
+            if(do_interlace_me || do_interlace_dct){
+                if(top_field_first == -1)
+                    big_picture.top_field_first = in_picture->top_field_first;
+                else
+                    big_picture.top_field_first = 1;
+            }
+
             /* handles sameq here. This is not correct because it may
                not be a global option */
             if (same_quality) {
@@ -756,8 +776,29 @@ static void print_report(AVFormatContext **output_files,
             frame_number = ost->frame_number;
             sprintf(buf + strlen(buf), "frame=%5d q=%2.1f ",
                     frame_number, enc->coded_frame ? enc->coded_frame->quality/(float)FF_QP2LAMBDA : 0);
-            if (enc->flags&CODEC_FLAG_PSNR)
-                sprintf(buf + strlen(buf), "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));
+            if(is_last_report)
+                sprintf(buf + strlen(buf), "L");
+            if (enc->flags&CODEC_FLAG_PSNR){
+                int j;
+                double error, error_sum=0;
+                double scale, scale_sum=0;
+                char type[3]= {'Y','U','V'};
+                sprintf(buf + strlen(buf), "PSNR=");
+                for(j=0; j<3; j++){
+                    if(is_last_report){
+                        error= enc->error[j];
+                        scale= enc->width*enc->height*255.0*255.0*frame_number;
+                    }else{
+                        error= enc->coded_frame->error[j];
+                        scale= enc->width*enc->height*255.0*255.0;
+                    }
+                    if(j) scale/=4;
+                    error_sum += error;
+                    scale_sum += scale;
+                    sprintf(buf + strlen(buf), "%c:%2.2f ", type[j], psnr(error/scale));
+                }
+                sprintf(buf + strlen(buf), "*:%2.2f ", psnr(error_sum/scale_sum));
+            }
             vid = 1;
         }
         /* compute min output value */
@@ -783,6 +824,197 @@ static void print_report(AVFormatContext **output_files,
         fprintf(stderr, "\n");
 }
 
+/* pkt = NULL means EOF (needed to flush decoder buffers) */
+static int output_packet(AVInputStream *ist, int ist_index,
+                         AVOutputStream **ost_table, int nb_ostreams,
+                         AVPacket *pkt)
+{
+    AVFormatContext *os;
+    AVOutputStream *ost;
+    uint8_t *ptr;
+    int len, ret, i;
+    uint8_t *data_buf;
+    int data_size, got_picture;
+    AVFrame picture;
+    short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2];
+    void *buffer_to_free;
+        
+    if (pkt && pkt->pts != AV_NOPTS_VALUE) {
+        ist->pts = pkt->pts;
+    } else {
+        ist->pts = ist->next_pts;
+    }
+    
+    if (pkt == NULL) {
+        /* EOF handling */
+        ptr = NULL;
+        len = 0;
+        goto handle_eof;
+    }
+
+    len = pkt->size;
+    ptr = pkt->data;
+    while (len > 0) {
+    handle_eof:
+        /* decode the packet if needed */
+        data_buf = NULL; /* fail safe */
+        data_size = 0;
+        if (ist->decoding_needed) {
+            switch(ist->st->codec.codec_type) {
+            case CODEC_TYPE_AUDIO:
+                    /* XXX: could avoid copy if PCM 16 bits with same
+                       endianness as CPU */
+                ret = avcodec_decode_audio(&ist->st->codec, samples, &data_size,
+                                           ptr, len);
+                if (ret < 0)
+                    goto fail_decode;
+                ptr += ret;
+                len -= ret;
+                /* Some bug in mpeg audio decoder gives */
+                /* data_size < 0, it seems they are overflows */
+                if (data_size <= 0) {
+                    /* no audio frame */
+                    continue;
+                }
+                data_buf = (uint8_t *)samples;
+                ist->next_pts += ((int64_t)AV_TIME_BASE * data_size) / 
+                    (2 * ist->st->codec.channels);
+                break;
+            case CODEC_TYPE_VIDEO:
+                    data_size = (ist->st->codec.width * ist->st->codec.height * 3) / 2;
+                    /* XXX: allocate picture correctly */
+                    memset(&picture, 0, sizeof(picture));
+                    ret = avcodec_decode_video(&ist->st->codec, 
+                                               &picture, &got_picture, ptr, len);
+                    ist->st->quality= picture.quality;
+                    if (ret < 0) 
+                        goto fail_decode;
+                    if (!got_picture) {
+                        /* no picture yet */
+                        goto discard_packet;
+                    }
+                    if (ist->st->codec.frame_rate_base != 0) {
+                        ist->next_pts += ((int64_t)AV_TIME_BASE * 
+                                          ist->st->codec.frame_rate_base) /
+                            ist->st->codec.frame_rate;
+                    }
+                    len = 0;
+                    break;
+                default:
+                    goto fail_decode;
+                }
+            } else {
+                data_buf = ptr;
+                data_size = len;
+                ret = len;
+                len = 0;
+            }
+
+            buffer_to_free = NULL;
+            if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO) {
+                pre_process_video_frame(ist, (AVPicture *)&picture, 
+                                        &buffer_to_free);
+            }
+
+            /* frame rate emulation */
+            if (ist->st->codec.rate_emu) {
+                int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec.frame_rate_base, 1000000, ist->st->codec.frame_rate);
+                int64_t now = av_gettime() - ist->start;
+                if (pts > now)
+                    usleep(pts - now);
+
+                ist->frame++;
+            }
+
+#if 0
+            /* mpeg PTS deordering : if it is a P or I frame, the PTS
+               is the one of the next displayed one */
+            /* XXX: add mpeg4 too ? */
+            if (ist->st->codec.codec_id == CODEC_ID_MPEG1VIDEO) {
+                if (ist->st->codec.pict_type != B_TYPE) {
+                    int64_t tmp;
+                    tmp = ist->last_ip_pts;
+                    ist->last_ip_pts  = ist->frac_pts.val;
+                    ist->frac_pts.val = tmp;
+                }
+            }
+#endif
+            /* if output time reached then transcode raw format, 
+              encode packets and output them */
+            if (start_time == 0 || ist->pts >= start_time)
+                for(i=0;i<nb_ostreams;i++) {
+                    int frame_size;
+
+                    ost = ost_table[i];
+                    if (ost->source_index == ist_index) {
+                        os = output_files[ost->file_index];
+
+#if 0
+                        printf("%d: got pts=%0.3f %0.3f\n", i, 
+                               (double)pkt->pts / AV_TIME_BASE, 
+                               ((double)ist->pts / AV_TIME_BASE) - 
+                               ((double)ost->st->pts.val * os->pts_num / os->pts_den));
+#endif
+                        /* set the input output pts pairs */
+                        ost->sync_ipts = (double)ist->pts / AV_TIME_BASE;
+                        /* XXX: take into account the various fifos,
+                           in particular for audio */
+                        ost->sync_opts = ost->st->pts.val;
+                        //printf("ipts=%lld sync_ipts=%f sync_opts=%lld pts.val=%lld pkt->pts=%lld\n", ist->pts, ost->sync_ipts, ost->sync_opts, ost->st->pts.val, pkt->pts); 
+
+                        if (ost->encoding_needed) {
+                            switch(ost->st->codec.codec_type) {
+                            case CODEC_TYPE_AUDIO:
+                                do_audio_out(os, ost, ist, data_buf, data_size);
+                                break;
+                            case CODEC_TYPE_VIDEO:
+                                /* find an audio stream for synchro */
+                                {
+                                    int i;
+                                    AVOutputStream *audio_sync, *ost1;
+                                    audio_sync = NULL;
+                                    for(i=0;i<nb_ostreams;i++) {
+                                        ost1 = ost_table[i];
+                                        if (ost1->file_index == ost->file_index &&
+                                            ost1->st->codec.codec_type == CODEC_TYPE_AUDIO) {
+                                            audio_sync = ost1;
+                                            break;
+                                        }
+                                    }
+
+                                    do_video_out(os, ost, ist, &picture, &frame_size, audio_sync);
+                                    if (do_vstats && frame_size)
+                                        do_video_stats(os, ost, frame_size);
+                                }
+                                break;
+                            default:
+                                av_abort();
+                            }
+                        } else {
+                            AVFrame avframe;
+                                                
+                            /* no reencoding needed : output the packet directly */
+                            /* force the input stream PTS */
+                        
+                            memset(&avframe, 0, sizeof(AVFrame));
+                            ost->st->codec.coded_frame= &avframe;
+                            avframe.key_frame = pkt->flags & PKT_FLAG_KEY; 
+                        
+                            av_write_frame(os, ost->index, data_buf, data_size);
+                            ost->st->codec.frame_number++;
+                            ost->frame_number++;
+                        }
+                    }
+                }
+            av_free(buffer_to_free);
+        }
+ discard_packet:
+    return 0;
+ fail_decode:
+    return -1;
+}
+
+
 /*
  * The following code is the main loop of the file converter
  */
@@ -1183,13 +1415,6 @@ static int av_encode(AVFormatContext **output_files,
     for(; received_sigterm == 0;) {
         int file_index, ist_index;
         AVPacket pkt;
-        uint8_t *ptr;
-        int len;
-        uint8_t *data_buf;
-        int data_size, got_picture;
-        AVPicture picture;
-        short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2];
-        void *buffer_to_free;
         double pts_min;
         
     redo:
@@ -1250,181 +1475,28 @@ static int av_encode(AVFormatContext **output_files,
             goto discard_packet;
 
         //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
-        
-        if (pkt.pts != AV_NOPTS_VALUE) {
-            ist->pts = pkt.pts;
-        } else {
-            ist->pts = ist->next_pts;
-        }
-
-        len = pkt.size;
-        ptr = pkt.data;
-        while (len > 0) {
-            /* decode the packet if needed */
-            data_buf = NULL; /* fail safe */
-            data_size = 0;
-            if (ist->decoding_needed) {
-                switch(ist->st->codec.codec_type) {
-                case CODEC_TYPE_AUDIO:
-                    /* XXX: could avoid copy if PCM 16 bits with same
-                       endianness as CPU */
-                    ret = avcodec_decode_audio(&ist->st->codec, samples, &data_size,
-                                               ptr, len);
-                    if (ret < 0)
-                        goto fail_decode;
-                    ptr += ret;
-                    len -= ret;
-                    /* Some bug in mpeg audio decoder gives */
-                    /* data_size < 0, it seems they are overflows */
-                    if (data_size <= 0) {
-                        /* no audio frame */
-                        continue;
-                    }
-                    data_buf = (uint8_t *)samples;
-                    ist->next_pts += ((int64_t)AV_TIME_BASE * data_size) / 
-                        (2 * ist->st->codec.channels);
-                    break;
-                case CODEC_TYPE_VIDEO:
-                    {
-                        AVFrame big_picture;
-
-                        data_size = (ist->st->codec.width * ist->st->codec.height * 3) / 2;
-                        ret = avcodec_decode_video(&ist->st->codec, 
-                                                   &big_picture, &got_picture, ptr, len);
-                        picture= *(AVPicture*)&big_picture;
-                        ist->st->quality= big_picture.quality;
-                        if (ret < 0) {
-                        fail_decode:
-                            fprintf(stderr, "Error while decoding stream #%d.%d\n",
-                                    ist->file_index, ist->index);
-                            av_free_packet(&pkt);
-                            goto redo;
-                        }
-                        if (!got_picture) {
-                            /* no picture yet */
-                            goto discard_packet;
-                        }
-                        if (ist->st->codec.frame_rate_base != 0) {
-                            ist->next_pts += ((int64_t)AV_TIME_BASE * 
-                                ist->st->codec.frame_rate_base) /
-                                ist->st->codec.frame_rate;
-                        }
-                        len = 0;
-                    }
-                    break;
-                default:
-                    goto fail_decode;
-                }
-            } else {
-                data_buf = ptr;
-                data_size = len;
-                ret = len;
-                len = 0;
-            }
-
-            buffer_to_free = NULL;
-            if (ist->st->codec.codec_type == CODEC_TYPE_VIDEO) {
-                pre_process_video_frame(ist, &picture, &buffer_to_free);
-            }
-
-            /* frame rate emulation */
-            if (ist->st->codec.rate_emu) {
-                int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec.frame_rate_base, 1000000, ist->st->codec.frame_rate);
-                int64_t now = av_gettime() - ist->start;
-                if (pts > now)
-                    usleep(pts - now);
-
-                ist->frame++;
-            }
-
-#if 0
-            /* mpeg PTS deordering : if it is a P or I frame, the PTS
-               is the one of the next displayed one */
-            /* XXX: add mpeg4 too ? */
-            if (ist->st->codec.codec_id == CODEC_ID_MPEG1VIDEO) {
-                if (ist->st->codec.pict_type != B_TYPE) {
-                    int64_t tmp;
-                    tmp = ist->last_ip_pts;
-                    ist->last_ip_pts  = ist->frac_pts.val;
-                    ist->frac_pts.val = tmp;
-                }
-            }
-#endif
-            /* if output time reached then transcode raw format, 
-              encode packets and output them */
-            if (start_time == 0 || ist->pts >= start_time)
-                for(i=0;i<nb_ostreams;i++) {
-                    int frame_size;
-
-                    ost = ost_table[i];
-                    if (ost->source_index == ist_index) {
-                        os = output_files[ost->file_index];
-
-#if 0
-                        printf("%d: got pts=%0.3f %0.3f\n", i, 
-                               (double)pkt.pts / AV_TIME_BASE, 
-                               ((double)ist->pts / AV_TIME_BASE) - 
-                               ((double)ost->st->pts.val * os->pts_num / os->pts_den));
-#endif
-                        /* set the input output pts pairs */
-                        ost->sync_ipts = (double)ist->pts / AV_TIME_BASE;
-                        /* XXX: take into account the various fifos,
-                           in particular for audio */
-                        ost->sync_opts = ost->st->pts.val;
-                        //printf("ipts=%lld sync_ipts=%f sync_opts=%lld pts.val=%lld pkt.pts=%lld\n", ist->pts, ost->sync_ipts, ost->sync_opts, ost->st->pts.val, pkt.pts); 
-
-                        if (ost->encoding_needed) {
-                            switch(ost->st->codec.codec_type) {
-                            case CODEC_TYPE_AUDIO:
-                                do_audio_out(os, ost, ist, data_buf, data_size);
-                                break;
-                            case CODEC_TYPE_VIDEO:
-                                /* find an audio stream for synchro */
-                                {
-                                    int i;
-                                    AVOutputStream *audio_sync, *ost1;
-                                    audio_sync = NULL;
-                                    for(i=0;i<nb_ostreams;i++) {
-                                        ost1 = ost_table[i];
-                                        if (ost1->file_index == ost->file_index &&
-                                            ost1->st->codec.codec_type == CODEC_TYPE_AUDIO) {
-                                            audio_sync = ost1;
-                                            break;
-                                        }
-                                    }
-
-                                    do_video_out(os, ost, ist, &picture, &frame_size, audio_sync);
-                                    if (do_vstats && frame_size)
-                                        do_video_stats(os, ost, frame_size);
-                                }
-                                break;
-                            default:
-                                av_abort();
-                            }
-                        } else {
-                            AVFrame avframe;
-                                                
-                            /* no reencoding needed : output the packet directly */
-                            /* force the input stream PTS */
-                        
-                            memset(&avframe, 0, sizeof(AVFrame));
-                            ost->st->codec.coded_frame= &avframe;
-                            avframe.key_frame = pkt.flags & PKT_FLAG_KEY; 
-                        
-                            av_write_frame(os, ost->index, data_buf, data_size);
-                            ost->st->codec.frame_number++;
-                            ost->frame_number++;
-                        }
-                    }
-                }
-            av_free(buffer_to_free);
+        if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {
+            fprintf(stderr, "Error while decoding stream #%d.%d\n",
+                    ist->file_index, ist->index);
+            av_free_packet(&pkt);
+            goto redo;
         }
+        
     discard_packet:
         av_free_packet(&pkt);
         
         /* dump report by using the output first video and audio streams */
         print_report(output_files, ost_table, nb_ostreams, 0);
     }
+
+    /* at the end of stream, we must flush the decoder buffers */
+    for(i=0;i<nb_istreams;i++) {
+        ist = ist_table[i];
+        if (ist->decoding_needed) {
+            output_packet(ist, i, ost_table, nb_ostreams, NULL);
+        }
+    }
+
     term_exit();
 
     /* dump report by using the first video and audio streams */
@@ -1567,7 +1639,7 @@ static void opt_video_bitrate_min(const char *arg)
 
 static void opt_video_buffer_size(const char *arg)
 {
-    video_rc_buffer_size = atoi(arg) * 1000;
+    video_rc_buffer_size = atoi(arg) * 1024;
 }
 
 static void opt_video_rc_eq(char *arg)
@@ -1612,6 +1684,11 @@ static void opt_debug(const char *arg)
     debug = atoi(arg);
 }
 
+static void opt_vismv(const char *arg)
+{
+    debug_mv = atoi(arg);
+}
+    
 static void opt_verbose(const char *arg)
 {
     verbose = atoi(arg);
@@ -1759,6 +1836,21 @@ static void opt_mb_decision(const char *arg)
     mb_decision = atoi(arg);
 }
 
+static void opt_mb_cmp(const char *arg)
+{
+    mb_cmp = atoi(arg);
+}
+
+static void opt_sub_cmp(const char *arg)
+{
+    sub_cmp = atoi(arg);
+}
+
+static void opt_cmp(const char *arg)
+{
+    cmp = atoi(arg);
+}
+
 static void opt_qscale(const char *arg)
 {
     video_qscale = atof(arg);
@@ -1855,11 +1947,26 @@ static void opt_packet_size(const char *arg)
     packet_size= atoi(arg);
 }
 
+static void opt_error_rate(const char *arg)
+{
+    error_rate= atoi(arg);
+}
+
 static void opt_strict(const char *arg)
 {
     strict= atoi(arg);
 }
 
+static void opt_top_field_first(const char *arg)
+{
+    top_field_first= atoi(arg);
+}
+
+static void opt_noise_reduction(const char *arg)
+{
+    noise_reduction= atoi(arg);
+}
+
 static void opt_audio_bitrate(const char *arg)
 {
     audio_bit_rate = atoi(arg) * 1000;
@@ -2091,8 +2198,9 @@ static void opt_input_file(const char *filename)
             enc->workaround_bugs = workaround_bugs;
             enc->error_resilience = error_resilience; 
             enc->error_concealment = error_concealment; 
-            enc->idct_algo= idct_algo;
-            enc->debug= debug;
+            enc->idct_algo = idct_algo;
+            enc->debug = debug;
+            enc->debug_mv = debug_mv;            
             if(bitexact)
                 enc->flags|= CODEC_FLAG_BITEXACT;
 
@@ -2263,6 +2371,9 @@ static void opt_output_file(const char *filename)
                     video_enc->flags |= CODEC_FLAG_BITEXACT;
 
                 video_enc->mb_decision = mb_decision;
+                video_enc->mb_cmp = mb_cmp;
+                video_enc->me_sub_cmp = sub_cmp;
+                video_enc->me_cmp = cmp;
                 
                 if (use_umv) {
                     video_enc->flags |= CODEC_FLAG_H263P_UMV;
@@ -2283,14 +2394,26 @@ static void opt_output_file(const char *filename)
                 if(use_part) {
                     video_enc->flags |= CODEC_FLAG_PART;
                 }
+               if (use_alt_scan) {
+                    video_enc->flags |= CODEC_FLAG_ALT_SCAN;
+                }
+               if (use_trell) {
+                    video_enc->flags |= CODEC_FLAG_TRELLIS_QUANT;
+                }
+               if (use_scan_offset) {
+                    video_enc->flags |= CODEC_FLAG_SVCD_SCAN_OFFSET;
+                }
                 if (b_frames) {
                     video_enc->max_b_frames = b_frames;
                     video_enc->b_frame_strategy = 0;
                     video_enc->b_quant_factor = 2.0;
                 }
-                if (do_interlace) {
+                if (do_interlace_dct) {
                     video_enc->flags |= CODEC_FLAG_INTERLACED_DCT;
                 }
+                if (do_interlace_me) {
+                    video_enc->flags |= CODEC_FLAG_INTERLACED_ME;
+                }
                 video_enc->qmin = video_qmin;
                 video_enc->qmax = video_qmax;
                 video_enc->mb_qmin = video_mb_qmin;
@@ -2299,8 +2422,8 @@ static void opt_output_file(const char *filename)
                 video_enc->qblur = video_qblur;
                 video_enc->qcompress = video_qcomp;
                 video_enc->rc_eq = video_rc_eq;
-                video_enc->debug= debug;
-                
+                video_enc->debug = debug;
+                video_enc->debug_mv = debug_mv;                
                 p= video_rc_override_string;
                 for(i=0; p; i++){
                     int start, end, q;
@@ -2339,6 +2462,8 @@ static void opt_output_file(const char *filename)
                 video_enc->dct_algo = dct_algo;
                 video_enc->idct_algo = idct_algo;
                 video_enc->strict_std_compliance = strict;
+                video_enc->error_rate = error_rate;
+                video_enc->noise_reduction= noise_reduction;
                 if(packet_size){
                     video_enc->rtp_mode= 1;
                     video_enc->rtp_payload_size= packet_size;
@@ -2767,6 +2892,7 @@ static void opt_target(const char *arg)
         video_bit_rate = 1150000;
         video_rc_max_rate = 1150000;
         video_rc_min_rate = 1150000;
+        video_rc_buffer_size = 40*1024*8;
 
         audio_bit_rate = 224000;
         audio_sample_rate = 44100;
@@ -2782,7 +2908,9 @@ static void opt_target(const char *arg)
 
         video_bit_rate = 2040000;
         video_rc_max_rate = 2516000;
-        video_rc_min_rate = 1145000;
+        video_rc_min_rate = 0; //1145000;
+        video_rc_buffer_size = 224*1024*8;
+        use_scan_offset = 1;
 
         audio_bit_rate = 224000;
         audio_sample_rate = 44100;
@@ -2798,7 +2926,8 @@ static void opt_target(const char *arg)
 
         video_bit_rate = 6000000;
         video_rc_max_rate = 9000000;
-        video_rc_min_rate = 1500000;
+        video_rc_min_rate = 0; //1500000;
+        video_rc_buffer_size = 224*1024*8;
 
         audio_bit_rate = 448000;
         audio_sample_rate = 48000;
@@ -2826,6 +2955,7 @@ const OptionDef options[] = {
     { "copyright", HAS_ARG | OPT_STRING, {(void*)&str_copyright}, "set the copyright", "string" },
     { "comment", HAS_ARG | OPT_STRING, {(void*)&str_comment}, "set the comment", "string" },
     { "debug", HAS_ARG | OPT_EXPERT, {(void*)opt_debug}, "print specific debug info", "" },
+    { "vismv", HAS_ARG | OPT_EXPERT, {(void*)opt_vismv}, "visualize motion vectors", "" },
     { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark}, 
       "add timings for benchmarking" },
     { "dump", OPT_BOOL | OPT_EXPERT, {(void*)&do_pkt_dump}, 
@@ -2881,11 +3011,15 @@ const OptionDef options[] = {
     { "bf", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_frames}, "use 'frames' B frames", "frames" },
     { "hq", OPT_BOOL, {(void*)&mb_decision}, "activate high quality settings" },
     { "mbd", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_decision}, "macroblock decision", "mode" },
+    { "mbcmp", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_cmp}, "macroblock compare function", "cmp function" },
+    { "subcmp", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_sub_cmp}, "subpel compare function", "cmp function" },
+    { "cmp", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_cmp}, "fullpel compare function", "cmp function" },
     { "4mv", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_4mv}, "use four motion vector by macroblock (MPEG4)" },
     { "obmc", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_obmc}, "use overlapped block motion compensation (h263+)" },
     { "part", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_part}, "use data partitioning (MPEG4)" },
     { "bug", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_workaround_bugs}, "workaround not auto detected encoder bugs", "param" },
     { "ps", HAS_ARG | OPT_EXPERT, {(void*)opt_packet_size}, "set packet size in bits", "size" },
+    { "error", HAS_ARG | OPT_EXPERT, {(void*)opt_error_rate}, "error rate", "rate" },
     { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to follow the standarts", "strictness" },
     { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality}, 
       "use same video quality as source (implies VBR)" },
@@ -2893,16 +3027,23 @@ const OptionDef options[] = {
     { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename}, "select two pass log file name", "file" },
     { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace}, 
       "deinterlace pictures" },
-    { "interlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_interlace}, 
-      "force interlacing support in encoder (MPEG2/MPEG4)" },
+    { "ildct", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_interlace_dct}, 
+      "force interlaced dct support in encoder (MPEG2/MPEG4)" },
+    { "ilme", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_interlace_me}, 
+      "force interlacied me support in encoder MPEG2" },
     { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
     { "vstats", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_vstats}, "dump video coding statistics to file" }, 
     { "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" },
     { "aic", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_aic}, "enable Advanced intra coding (h263+)" },
     { "aiv", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_aiv}, "enable Alternative inter vlc (h263+)" },
     { "umv", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_umv}, "enable Unlimited Motion Vector (h263+)" },
+    { "alt", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_alt_scan}, "enable alternate scantable (mpeg2)" },
+    { "trell", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_trell}, "enable trellis quantization" },
+    { "scan_offset", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_scan_offset}, "enable SVCD Scan Offset placeholder" },
     { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
     { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
+    { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
+    { "nr", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_noise_reduction}, "noise reduction", "" },
 
     /* audio options */
     { "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", },