]> git.sesse.net Git - ffmpeg/blobdiff - ffmpeg.c
Original Commit: r103 | ods15 | 2006-10-01 18:00:43 +0200 (Sun, 01 Oct 2006) | 2...
[ffmpeg] / ffmpeg.c
index 691d2c9dd55778e59e9aabe088c85d8ff5bb344f..580f6280074fc62677608e72888b1a0d4e0e9a9e 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -23,6 +23,7 @@
 #include "framehook.h"
 #include "dsputil.h"
 #include "opt.h"
+#include "fifo.h"
 
 #ifndef __MINGW32__
 #include <unistd.h>
@@ -106,14 +107,7 @@ static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
 static int frame_rate = 25;
 static int frame_rate_base = 1;
 static float video_qscale = 0;
-static int video_qmin = 2;
-static int video_qmax = 31;
-static int video_lmin = 2*FF_QP2LAMBDA;
-static int video_lmax = 31*FF_QP2LAMBDA;
-static int video_mb_lmin = 2*FF_QP2LAMBDA;
-static int video_mb_lmax = 31*FF_QP2LAMBDA;
 static int video_qdiff = 3;
-static float video_qsquish = 0.0;
 static uint16_t *intra_matrix = NULL;
 static uint16_t *inter_matrix = NULL;
 #if 0 //experimental, (can be removed)
@@ -123,28 +117,18 @@ static int video_rc_qmod_freq=0;
 #endif
 static char *video_rc_override_string=NULL;
 static char *video_rc_eq="tex^qComp";
-static float video_rc_buffer_aggressivity=1.0;
 static int me_method = ME_EPZS;
 static int video_disable = 0;
 static int video_discard = 0;
 static int video_codec_id = CODEC_ID_NONE;
 static int video_codec_tag = 0;
 static int same_quality = 0;
-static int b_frames = 0;
 static int do_deinterlace = 0;
-static int workaround_bugs = FF_BUG_AUTODETECT;
 static int packet_size = 0;
-static int error_rate = 0;
 static int strict = 0;
 static int top_field_first = -1;
-static int sc_threshold = 0;
 static int me_threshold = 0;
-static int mb_threshold = 0;
 static int intra_dc_precision = 8;
-static int me_penalty_compensation= 256;
-static int frame_skip_threshold= 0;
-static int frame_skip_factor= 0;
-static int frame_skip_exp= 0;
 static int loop_input = 0;
 static int loop_output = AVFMT_NOOUTPUTLOOP;
 static int qp_hist = 0;
@@ -274,7 +258,7 @@ typedef struct AVOutputStream {
     /* audio only */
     int audio_resample;
     ReSampleContext *resample; /* for audio resampling */
-    FifoBuffer fifo;     /* for compression: one audio fifo per codec */
+    AVFifoBuffer fifo;     /* for compression: one audio fifo per codec */
     FILE *logfile;
 } AVOutputStream;
 
@@ -478,7 +462,7 @@ static void do_audio_out(AVFormatContext *s,
 
     if(audio_sync_method){
         double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
-                - fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2);
+                - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2);
         double idelta= delta*ist->st->codec->sample_rate / enc->sample_rate;
         int byte_delta= ((int)idelta)*2*ist->st->codec->channels;
 
@@ -515,13 +499,13 @@ static void do_audio_out(AVFormatContext *s,
                 assert(ost->audio_resample);
                 if(verbose > 2)
                     fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate);
-//                fprintf(stderr, "drift:%f len:%d opts:%lld ipts:%lld fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2));
+//                fprintf(stderr, "drift:%f len:%d opts:%lld ipts:%lld fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2));
                 av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate);
             }
         }
     }else
         ost->sync_opts= lrintf(get_sync_ipts(ost) * enc->sample_rate)
-                        - fifo_size(&ost->fifo, ost->fifo.rptr)/(ost->st->codec->channels * 2); //FIXME wrong
+                        - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2); //FIXME wrong
 
     if (ost->audio_resample) {
         buftmp = audio_buf;
@@ -537,13 +521,11 @@ static void do_audio_out(AVFormatContext *s,
     /* now encode as many frames as possible */
     if (enc->frame_size > 1) {
         /* output resampled raw samples */
-        fifo_write(&ost->fifo, buftmp, size_out,
-                   &ost->fifo.wptr);
+        av_fifo_write(&ost->fifo, buftmp, size_out);
 
         frame_bytes = enc->frame_size * 2 * enc->channels;
 
-        while (fifo_read(&ost->fifo, audio_buf, frame_bytes,
-                     &ost->fifo.rptr) == 0) {
+        while (av_fifo_read(&ost->fifo, audio_buf, frame_bytes) == 0) {
             AVPacket pkt;
             av_init_packet(&pkt);
 
@@ -841,6 +823,10 @@ static void do_video_out(AVFormatContext *s,
             ret = avcodec_encode_video(enc,
                                        bit_buffer, bit_buffer_size,
                                        &big_picture);
+            if (ret == -1) {
+                fprintf(stderr, "Video encoding failed\n");
+                exit(1);
+            }
             //enc->frame_number = enc->real_pict_num;
             if(ret>0){
                 pkt.data= bit_buffer;
@@ -1324,14 +1310,13 @@ static int output_packet(AVInputStream *ist, int ist_index,
 
                         switch(ost->st->codec->codec_type) {
                         case CODEC_TYPE_AUDIO:
-                            fifo_bytes = fifo_size(&ost->fifo, NULL);
+                            fifo_bytes = av_fifo_size(&ost->fifo);
                             ret = 0;
                             /* encode any samples remaining in fifo */
                             if(fifo_bytes > 0 && enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
                                 int fs_tmp = enc->frame_size;
                                 enc->frame_size = fifo_bytes / (2 * enc->channels);
-                                if(fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes,
-                                        &ost->fifo.rptr) == 0) {
+                                if(av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes) == 0) {
                                     ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, samples);
                                 }
                                 enc->frame_size = fs_tmp;
@@ -1570,7 +1555,7 @@ static int av_encode(AVFormatContext **output_files,
         } else {
             switch(codec->codec_type) {
             case CODEC_TYPE_AUDIO:
-                if (fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
+                if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
                     goto fail;
 
                 if (codec->channels == icodec->channels &&
@@ -2025,8 +2010,8 @@ static int av_encode(AVFormatContext **output_files,
                     fclose(ost->logfile);
                     ost->logfile = NULL;
                 }
-                fifo_free(&ost->fifo); /* works even if fifo is not
-                                          initialized but set to zero */
+                av_fifo_free(&ost->fifo); /* works even if fifo is not
+                                             initialized but set to zero */
                 av_free(ost->pict_tmp.data[0]);
                 if (ost->video_resample)
                     sws_freeContext(ost->img_resample_ctx);
@@ -2107,22 +2092,11 @@ static void opt_video_rc_override_string(char *arg)
     video_rc_override_string = arg;
 }
 
-
-static void opt_workaround_bugs(const char *arg)
-{
-    workaround_bugs = atoi(arg);
-}
-
 static void opt_me_threshold(const char *arg)
 {
     me_threshold = atoi(arg);
 }
 
-static void opt_mb_threshold(const char *arg)
-{
-    mb_threshold = atoi(arg);
-}
-
 static void opt_verbose(const char *arg)
 {
     verbose = atoi(arg);
@@ -2336,18 +2310,6 @@ static void opt_frame_aspect_ratio(const char *arg)
     frame_aspect_ratio = ar;
 }
 
-static void opt_b_frames(const char *arg)
-{
-    b_frames = atoi(arg);
-    if (b_frames > FF_MAX_B_FRAMES) {
-        fprintf(stderr, "\nCannot have more than %d B frames, increase FF_MAX_B_FRAMES.\n", FF_MAX_B_FRAMES);
-        exit(1);
-    } else if (b_frames < 1) {
-        fprintf(stderr, "\nNumber of B frames must be higher than 0\n");
-        exit(1);
-    }
-}
-
 static void opt_qscale(const char *arg)
 {
     video_qscale = atof(arg);
@@ -2358,66 +2320,6 @@ static void opt_qscale(const char *arg)
     }
 }
 
-static void opt_qsquish(const char *arg)
-{
-    video_qsquish = atof(arg);
-    if (video_qsquish < 0.0 ||
-        video_qsquish > 99.0) {
-        fprintf(stderr, "qsquish must be >= 0.0 and <= 99.0\n");
-        exit(1);
-    }
-}
-
-static void opt_lmax(const char *arg)
-{
-    video_lmax = atof(arg)*FF_QP2LAMBDA;
-}
-
-static void opt_lmin(const char *arg)
-{
-    video_lmin = atof(arg)*FF_QP2LAMBDA;
-}
-
-static void opt_qmin(const char *arg)
-{
-    video_qmin = atoi(arg);
-    if (video_qmin < 1 ||
-        video_qmin > 51) {
-        fprintf(stderr, "qmin must be >= 1 and <= 51\n");
-        exit(1);
-    }
-}
-
-static void opt_qmax(const char *arg)
-{
-    video_qmax = atoi(arg);
-    if (video_qmax < 1 ||
-        video_qmax > 51) {
-        fprintf(stderr, "qmax must be >= 1 and <= 51\n");
-        exit(1);
-    }
-}
-
-static void opt_mb_lmin(const char *arg)
-{
-    video_mb_lmin = atof(arg)*FF_QP2LAMBDA;
-    if (video_mb_lmin < 1 ||
-        video_mb_lmin > FF_LAMBDA_MAX) {
-        fprintf(stderr, "mblmin must be >= 1 and <= %d\n", FF_LAMBDA_MAX / FF_QP2LAMBDA);
-        exit(1);
-    }
-}
-
-static void opt_mb_lmax(const char *arg)
-{
-    video_mb_lmax = atof(arg)*FF_QP2LAMBDA;
-    if (video_mb_lmax < 1 ||
-        video_mb_lmax > FF_LAMBDA_MAX) {
-        fprintf(stderr, "mblmax must be >= 1 and <= %d\n", FF_LAMBDA_MAX / FF_QP2LAMBDA);
-        exit(1);
-    }
-}
-
 static void opt_qdiff(const char *arg)
 {
     video_qdiff = atoi(arg);
@@ -2433,11 +2335,6 @@ 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);
@@ -2448,11 +2345,6 @@ static void opt_top_field_first(const char *arg)
     top_field_first= atoi(arg);
 }
 
-static void opt_sc_threshold(const char *arg)
-{
-    sc_threshold= atoi(arg);
-}
-
 static void opt_thread_count(const char *arg)
 {
     thread_count= atoi(arg);
@@ -2777,7 +2669,6 @@ static void opt_input_file(const char *filename)
             frame_pix_fmt = enc->pix_fmt;
             rfps      = ic->streams[i]->r_frame_rate.num;
             rfps_base = ic->streams[i]->r_frame_rate.den;
-            enc->workaround_bugs = workaround_bugs;
             if(enc->lowres) enc->flags |= CODEC_FLAG_EMU_EDGE;
             if(me_threshold)
                 enc->debug |= FF_DEBUG_MV;
@@ -2968,17 +2859,8 @@ static void new_video_stream(AVFormatContext *oc)
         if(inter_matrix)
             video_enc->inter_matrix = inter_matrix;
 
-        video_enc->max_b_frames = b_frames;
-        video_enc->qmin = video_qmin;
-        video_enc->qmax = video_qmax;
-        video_enc->lmin = video_lmin;
-        video_enc->lmax = video_lmax;
-        video_enc->rc_qsquish = video_qsquish;
-        video_enc->mb_lmin = video_mb_lmin;
-        video_enc->mb_lmax = video_mb_lmax;
         video_enc->max_qdiff = video_qdiff;
         video_enc->rc_eq = video_rc_eq;
-        video_enc->workaround_bugs = workaround_bugs;
         video_enc->thread_count = thread_count;
         p= video_rc_override_string;
         for(i=0; p; i++){
@@ -3006,17 +2888,9 @@ static void new_video_stream(AVFormatContext *oc)
         }
         video_enc->rc_override_count=i;
         video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
-        video_enc->rc_buffer_aggressivity= video_rc_buffer_aggressivity;
         video_enc->me_threshold= me_threshold;
-        video_enc->mb_threshold= mb_threshold;
         video_enc->intra_dc_precision= intra_dc_precision - 8;
         video_enc->strict_std_compliance = strict;
-        video_enc->error_rate = error_rate;
-        video_enc->scenechange_threshold= sc_threshold;
-        video_enc->me_penalty_compensation= me_penalty_compensation;
-        video_enc->frame_skip_threshold= frame_skip_threshold;
-        video_enc->frame_skip_factor= frame_skip_factor;
-        video_enc->frame_skip_exp= frame_skip_exp;
 
         if(packet_size){
             video_enc->rtp_mode= 1;
@@ -3906,25 +3780,14 @@ const OptionDef options[] = {
     { "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" },
     { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" },
     { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantiser scale (VBR)", "q" },
-    { "qmin", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qmin}, "min video quantiser scale (VBR)", "q" },
-    { "qmax", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qmax}, "max video quantiser scale (VBR)", "q" },
-    { "lmin", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_lmin}, "min video lagrange factor (VBR)", "lambda" },
-    { "lmax", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_lmax}, "max video lagrange factor (VBR)", "lambda" },
-    { "mblmin", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_lmin}, "min macroblock quantiser scale (VBR)", "q" },
-    { "mblmax", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_lmax}, "max macroblock quantiser scale (VBR)", "q" },
     { "qdiff", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qdiff}, "max difference between the quantiser scale (VBR)", "q" },
-    { "qsquish", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qsquish}, "how to keep quantiser between qmin and qmax (0 = clip, 1 = use differentiable function)", "squish" },
     { "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" },
     { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
     { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
     { "me", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_motion_estimation}, "set motion estimation method",
       "method" },
     { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold",  "" },
-    { "mb_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_mb_threshold}, "macroblock threshold",  "" },
-    { "bf", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_frames}, "use 'frames' B frames", "frames" },
-    { "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 standards", "strictness" },
     { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality},
       "use same video quality as source (implies VBR)" },
@@ -3938,13 +3801,8 @@ const OptionDef options[] = {
     { "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", "" },
-    { "sc_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_sc_threshold}, "scene change threshold", "threshold" },
     { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" },
-    { "mepc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&me_penalty_compensation}, "motion estimation bitrate penalty compensation", "factor (1.0 = 256)" },
     { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" },
-    { "skip_threshold", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&frame_skip_threshold}, "frame skip threshold", "threshold" },
-    { "skip_factor", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&frame_skip_factor}, "frame skip factor", "factor" },
-    { "skip_exp", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&frame_skip_exp}, "frame skip exponent", "exponent" },
     { "newvideo", OPT_VIDEO, {(void*)opt_new_video_stream}, "add a new video stream to the current output stream" },
     { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
 
@@ -3988,7 +3846,7 @@ const OptionDef options[] = {
 
 static void show_banner(void)
 {
-    fprintf(stderr, "FFmpeg version " FFMPEG_VERSION ", Copyright (c) 2000-2004 Fabrice Bellard\n");
+    fprintf(stderr, "FFmpeg version " FFMPEG_VERSION ", Copyright (c) 2000-2006 Fabrice Bellard, et al.\n");
     fprintf(stderr, "  configuration: " FFMPEG_CONFIGURATION "\n");
     fprintf(stderr, "  libavutil version: " AV_STRINGIFY(LIBAVUTIL_VERSION) "\n");
     fprintf(stderr, "  libavcodec version: " AV_STRINGIFY(LIBAVCODEC_VERSION) "\n");