OSDN Git Service

avconv: remove me_threshold option.
[coroid/libav_saccubus.git] / avconv.c
index 984c263..28e171e 100644 (file)
--- a/avconv.c
+++ b/avconv.c
@@ -101,30 +101,18 @@ static const OptionDef options[];
 static int *streamid_map = NULL;
 static int nb_streamid_map = 0;
 
-static int frame_width  = 0;
-static int frame_height = 0;
-static float frame_aspect_ratio = 0;
-static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
-static AVRational frame_rate;
-static float video_qscale = 0;
 static uint16_t *intra_matrix = NULL;
 static uint16_t *inter_matrix = NULL;
-static const char *video_rc_override_string=NULL;
 static int video_discard = 0;
 static int same_quant = 0;
 static int do_deinterlace = 0;
 static int top_field_first = -1;
-static int me_threshold = 0;
 static int intra_dc_precision = 8;
 static int qp_hist = 0;
 #if CONFIG_AVFILTER
 static char *vfilters = NULL;
 #endif
 
-static int audio_sample_rate = 0;
-#define QSCALE_NONE -99999
-static float audio_qscale = QSCALE_NONE;
-
 static int file_overwrite = 0;
 static int do_benchmark = 0;
 static int do_hex_dump = 0;
@@ -153,8 +141,6 @@ static int64_t extra_size = 0;
 static int nb_frames_dup = 0;
 static int nb_frames_drop = 0;
 static int input_sync;
-static int force_fps = 0;
-static char *forced_key_frames = NULL;
 
 static float dts_delta_threshold = 10;
 
@@ -219,6 +205,7 @@ typedef struct OutputStream {
     int resample_width;
     int resample_pix_fmt;
     AVRational frame_rate;
+    int force_fps;
 
     float frame_aspect_ratio;
 
@@ -280,6 +267,14 @@ typedef struct OptionsContext {
     int        nb_codec_names;
     SpecifierOpt *audio_channels;
     int        nb_audio_channels;
+    SpecifierOpt *audio_sample_rate;
+    int        nb_audio_sample_rate;
+    SpecifierOpt *frame_rates;
+    int        nb_frame_rates;
+    SpecifierOpt *frame_sizes;
+    int        nb_frame_sizes;
+    SpecifierOpt *frame_pix_fmts;
+    int        nb_frame_pix_fmts;
 
     /* input options */
     int64_t input_ts_offset;
@@ -320,6 +315,16 @@ typedef struct OptionsContext {
     int        nb_codec_tags;
     SpecifierOpt *sample_fmts;
     int        nb_sample_fmts;
+    SpecifierOpt *qscale;
+    int        nb_qscale;
+    SpecifierOpt *forced_key_frames;
+    int        nb_forced_key_frames;
+    SpecifierOpt *force_fps;
+    int        nb_force_fps;
+    SpecifierOpt *frame_aspect_ratios;
+    int        nb_frame_aspect_ratios;
+    SpecifierOpt *rc_overrides;
+    int        nb_rc_overrides;
 } OptionsContext;
 
 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
@@ -1211,7 +1216,7 @@ static void do_video_out(AVFormatContext *s,
             /* handles same_quant here. This is not correct because it may
                not be a global option */
             big_picture.quality = quality;
-            if(!me_threshold)
+            if (!enc->me_threshold)
                 big_picture.pict_type = 0;
 //            big_picture.pts = AV_NOPTS_VALUE;
             big_picture.pts= ost->sync_opts;
@@ -2086,7 +2091,7 @@ static int transcode_init(OutputFile *output_files,
 
                 if (!ost->frame_rate.num)
                     ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1};
-                if (ost->enc && ost->enc->supported_framerates && !force_fps) {
+                if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) {
                     int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
                     ost->frame_rate = ost->enc->supported_framerates[idx];
                 }
@@ -2181,6 +2186,9 @@ static int transcode_init(OutputFile *output_files,
                 av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low."
                                              "It takes bits/s as argument, not kbits/s\n");
             extra_size += ost->st->codec->extradata_size;
+
+            if (ost->st->codec->me_threshold)
+                input_streams[ost->source_index].st->codec->debug |= FF_DEBUG_MV;
         }
     }
 
@@ -2496,58 +2504,13 @@ static int transcode(OutputFile *output_files,
     return ret;
 }
 
-static int opt_video_rc_override_string(const char *opt, const char *arg)
-{
-    video_rc_override_string = arg;
-    return 0;
-}
-
-static int opt_me_threshold(const char *opt, const char *arg)
-{
-    me_threshold = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
-    return 0;
-}
-
 static int opt_verbose(const char *opt, const char *arg)
 {
     verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10);
     return 0;
 }
 
-static int opt_frame_rate(const char *opt, const char *arg)
-{
-    if (av_parse_video_rate(&frame_rate, arg) < 0) {
-        fprintf(stderr, "Incorrect value for %s: %s\n", opt, arg);
-        exit_program(1);
-    }
-    return 0;
-}
-
-static int opt_frame_size(const char *opt, const char *arg)
-{
-    if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) {
-        fprintf(stderr, "Incorrect frame size\n");
-        return AVERROR(EINVAL);
-    }
-    return 0;
-}
-
-static int opt_frame_pix_fmt(const char *opt, const char *arg)
-{
-    if (strcmp(arg, "list")) {
-        frame_pix_fmt = av_get_pix_fmt(arg);
-        if (frame_pix_fmt == PIX_FMT_NONE) {
-            fprintf(stderr, "Unknown pixel format requested: %s\n", arg);
-            return AVERROR(EINVAL);
-        }
-    } else {
-        show_pix_fmts();
-        exit_program(0);
-    }
-    return 0;
-}
-
-static int opt_frame_aspect_ratio(const char *opt, const char *arg)
+static double parse_frame_aspect_ratio(const char *arg)
 {
     int x = 0, y = 0;
     double ar = 0;
@@ -2566,20 +2529,9 @@ static int opt_frame_aspect_ratio(const char *opt, const char *arg)
 
     if (!ar) {
         fprintf(stderr, "Incorrect aspect ratio specification.\n");
-        return AVERROR(EINVAL);
-    }
-    frame_aspect_ratio = ar;
-    return 0;
-}
-
-static int opt_qscale(const char *opt, const char *arg)
-{
-    video_qscale = parse_number_or_die(opt, arg, OPT_FLOAT, 0, 255);
-    if (video_qscale == 0) {
-        fprintf(stderr, "qscale must be > 0.0 and <= 255\n");
-        return AVERROR(EINVAL);
+        exit_program(1);
     }
-    return 0;
+    return ar;
 }
 
 static int opt_top_field_first(const char *opt, const char *arg)
@@ -2588,12 +2540,6 @@ static int opt_top_field_first(const char *opt, const char *arg)
     return 0;
 }
 
-static int opt_audio_rate(const char *opt, const char *arg)
-{
-    audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
-    return 0;
-}
-
 static int opt_audio_codec(OptionsContext *o, const char *opt, const char *arg)
 {
     return parse_option(o, "codec:a", arg, options);
@@ -2829,8 +2775,6 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
                 dec->height >>= dec->lowres;
                 dec->width  >>= dec->lowres;
             }
-            if(me_threshold)
-                dec->debug |= FF_DEBUG_MV;
 
             if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) {
 
@@ -2890,24 +2834,22 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
         print_error(filename, AVERROR(ENOMEM));
         exit_program(1);
     }
-    if (audio_sample_rate) {
-        snprintf(buf, sizeof(buf), "%d", audio_sample_rate);
+    if (o->nb_audio_sample_rate) {
+        snprintf(buf, sizeof(buf), "%d", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i);
         av_dict_set(&format_opts, "sample_rate", buf, 0);
     }
     if (o->nb_audio_channels) {
         snprintf(buf, sizeof(buf), "%d", o->audio_channels[o->nb_audio_channels - 1].u.i);
         av_dict_set(&format_opts, "channels", buf, 0);
     }
-    if (frame_rate.num) {
-        snprintf(buf, sizeof(buf), "%d/%d", frame_rate.num, frame_rate.den);
-        av_dict_set(&format_opts, "framerate", buf, 0);
+    if (o->nb_frame_rates) {
+        av_dict_set(&format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
     }
-    if (frame_width && frame_height) {
-        snprintf(buf, sizeof(buf), "%dx%d", frame_width, frame_height);
-        av_dict_set(&format_opts, "video_size", buf, 0);
+    if (o->nb_frame_sizes) {
+        av_dict_set(&format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
     }
-    if (frame_pix_fmt != PIX_FMT_NONE)
-        av_dict_set(&format_opts, "pixel_format", av_get_pix_fmt_name(frame_pix_fmt), 0);
+    if (o->nb_frame_pix_fmts)
+        av_dict_set(&format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
 
     ic->flags |= AVFMT_FLAG_NONBLOCK;
 
@@ -2963,12 +2905,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena
     input_files[nb_input_files - 1].ts_offset  = o->input_ts_offset - (copy_ts ? 0 : timestamp);
     input_files[nb_input_files - 1].nb_streams = ic->nb_streams;
 
-    frame_rate    = (AVRational){0, 0};
-    frame_pix_fmt = PIX_FMT_NONE;
-    frame_height = 0;
-    frame_width  = 0;
-    audio_sample_rate = 0;
-
     for (i = 0; i < orig_nb_streams; i++)
         av_dict_free(&opts[i]);
     av_freep(&opts);
@@ -3008,6 +2944,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
     int64_t max_frames = INT64_MAX;
     char *bsf = NULL, *next, *codec_tag = NULL;
     AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
+    double qscale = -1;
 
     if (!st) {
         av_log(NULL, AV_LOG_ERROR, "Could not alloc stream.\n");
@@ -3057,6 +2994,12 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
         st->codec->codec_tag = tag;
     }
 
+    MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
+    if (qscale >= 0 || same_quant) {
+        st->codec->flags |= CODEC_FLAG_QSCALE;
+        st->codec->global_quality = FF_QP2LAMBDA * qscale;
+    }
+
     ost->sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
     return ost;
 }
@@ -3070,8 +3013,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
     ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO);
     st  = ost->st;
     if (!st->stream_copy) {
-        ost->frame_aspect_ratio = frame_aspect_ratio;
-        frame_aspect_ratio = 0;
 #if CONFIG_AVFILTER
         ost->avfilter= vfilters;
         vfilters = NULL;
@@ -3084,32 +3025,41 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
         video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
     }
 
-    if (st->stream_copy) {
-        video_enc->sample_aspect_ratio =
-        st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
-    } else {
-        const char *p;
-        int i;
+    if (!st->stream_copy) {
+        const char *p = NULL;
+        char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL;
+        char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL;
+        int i, force_fps = 0;
+
+        MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
+        if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Invalid framerate value: %s\n", frame_rate);
+            exit_program(1);
+        }
 
-        if (frame_rate.num)
-            ost->frame_rate = frame_rate;
+        MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
+        if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
+            av_log(NULL, AV_LOG_ERROR, "Invalid frame size: %s.\n", frame_size);
+            exit_program(1);
+        }
 
-        video_enc->width = frame_width;
-        video_enc->height = frame_height;
-        video_enc->pix_fmt = frame_pix_fmt;
-        st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
+        MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
+        if (frame_aspect_ratio)
+            ost->frame_aspect_ratio = parse_frame_aspect_ratio(frame_aspect_ratio);
 
-        if (video_qscale || same_quant) {
-            video_enc->flags |= CODEC_FLAG_QSCALE;
-            video_enc->global_quality = FF_QP2LAMBDA * video_qscale;
+        MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
+        if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) {
+            av_log(NULL, AV_LOG_ERROR, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
+            exit_program(1);
         }
+        st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
 
         if(intra_matrix)
             video_enc->intra_matrix = intra_matrix;
         if(inter_matrix)
             video_enc->inter_matrix = inter_matrix;
 
-        p= video_rc_override_string;
+        MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
         for(i=0; p; i++){
             int start, end, q;
             int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
@@ -3136,7 +3086,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
         video_enc->rc_override_count=i;
         if (!video_enc->rc_initial_buffer_occupancy)
             video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
-        video_enc->me_threshold= me_threshold;
         video_enc->intra_dc_precision= intra_dc_precision - 8;
 
         if (do_psnr)
@@ -3151,13 +3100,14 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)
             }
         }
 
+        MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st);
         if (forced_key_frames)
             parse_forced_key_frames(forced_key_frames, ost, video_enc);
+
+        MATCH_PER_STREAM_OPT(force_fps, i, force_fps, oc, st);
+        ost->force_fps = force_fps;
     }
 
-    /* reset some key parameters */
-    av_freep(&forced_key_frames);
-    frame_pix_fmt = PIX_FMT_NONE;
     return ost;
 }
 
@@ -3179,10 +3129,6 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc)
     if (!st->stream_copy) {
         char *sample_fmt = NULL;
 
-        if (audio_qscale > QSCALE_NONE) {
-            audio_enc->flags |= CODEC_FLAG_QSCALE;
-            audio_enc->global_quality = FF_QP2LAMBDA * audio_qscale;
-        }
         MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
 
         MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
@@ -3192,8 +3138,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc)
             exit_program(1);
         }
 
-        if (audio_sample_rate)
-            audio_enc->sample_rate = audio_sample_rate;
+        MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
     }
 
     return ost;
@@ -3618,15 +3563,9 @@ static void opt_output_file(void *optctx, const char *filename)
         av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
     }
 
-    frame_rate    = (AVRational){0, 0};
-    frame_width   = 0;
-    frame_height  = 0;
-    audio_sample_rate = 0;
-
     av_freep(&streamid_map);
     nb_streamid_map = 0;
 
-    av_freep(&forced_key_frames);
     reset_options(o);
 }
 
@@ -3702,6 +3641,11 @@ static void opt_intra_matrix(const char *arg)
     parse_matrix_coeffs(intra_matrix, arg);
 }
 
+static int opt_audio_qscale(OptionsContext *o, const char *opt, const char *arg)
+{
+    return parse_option(o, "q:a", arg, options);
+}
+
 static void show_usage(void)
 {
     printf("Hyper fast Audio and Video encoder\n");
@@ -3794,34 +3738,25 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
         norm = FILM;
         arg += 5;
     } else {
-        int fr;
-        /* Calculate FR via float to avoid int overflow */
-        fr = (int)(frame_rate.num * 1000.0 / frame_rate.den);
-        if(fr == 25000) {
-            norm = PAL;
-        } else if((fr == 29970) || (fr == 23976)) {
-            norm = NTSC;
-        } else {
-            /* Try to determine PAL/NTSC by peeking in the input files */
-            if(nb_input_files) {
-                int i, j;
-                for (j = 0; j < nb_input_files; j++) {
-                    for (i = 0; i < input_files[j].nb_streams; i++) {
-                        AVCodecContext *c = input_files[j].ctx->streams[i]->codec;
-                        if(c->codec_type != AVMEDIA_TYPE_VIDEO)
-                            continue;
-                        fr = c->time_base.den * 1000 / c->time_base.num;
-                        if(fr == 25000) {
-                            norm = PAL;
-                            break;
-                        } else if((fr == 29970) || (fr == 23976)) {
-                            norm = NTSC;
-                            break;
-                        }
-                    }
-                    if(norm != UNKNOWN)
+        /* Try to determine PAL/NTSC by peeking in the input files */
+        if(nb_input_files) {
+            int i, j, fr;
+            for (j = 0; j < nb_input_files; j++) {
+                for (i = 0; i < input_files[j].nb_streams; i++) {
+                    AVCodecContext *c = input_files[j].ctx->streams[i]->codec;
+                    if(c->codec_type != AVMEDIA_TYPE_VIDEO)
+                        continue;
+                    fr = c->time_base.den * 1000 / c->time_base.num;
+                    if(fr == 25000) {
+                        norm = PAL;
+                        break;
+                    } else if((fr == 29970) || (fr == 23976)) {
+                        norm = NTSC;
                         break;
+                    }
                 }
+                if(norm != UNKNOWN)
+                    break;
             }
         }
         if(verbose > 0 && norm != UNKNOWN)
@@ -3840,8 +3775,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
         opt_audio_codec(o, "c:a", "mp2");
         parse_option(o, "f", "vcd", options);
 
-        opt_frame_size("s", norm == PAL ? "352x288" : "352x240");
-        opt_frame_rate("r", frame_rates[norm]);
+        parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
+        parse_option(o, "r", frame_rates[norm], options);
         opt_default("g", norm == PAL ? "15" : "18");
 
         opt_default("b", "1150000");
@@ -3850,7 +3785,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
         opt_default("bufsize", "327680"); // 40*1024*8;
 
         opt_default("b:a", "224000");
-        audio_sample_rate = 44100;
+        parse_option(o, "ar", "44100", options);
         parse_option(o, "ac", "2", options);
 
         opt_default("packetsize", "2324");
@@ -3868,8 +3803,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
         opt_audio_codec(o, "c:a", "mp2");
         parse_option(o, "f", "svcd", options);
 
-        opt_frame_size("s", norm == PAL ? "480x576" : "480x480");
-        opt_frame_rate("r", frame_rates[norm]);
+        parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
+        parse_option(o, "r", frame_rates[norm], options);
         opt_default("g", norm == PAL ? "15" : "18");
 
         opt_default("b", "2040000");
@@ -3880,7 +3815,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
 
 
         opt_default("b:a", "224000");
-        audio_sample_rate = 44100;
+        parse_option(o, "ar", "44100", options);
 
         opt_default("packetsize", "2324");
 
@@ -3890,8 +3825,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
         opt_audio_codec(o, "c:a", "ac3");
         parse_option(o, "f", "dvd", options);
 
-        opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480");
-        opt_frame_rate("r", frame_rates[norm]);
+        parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
+        parse_option(o, "r", frame_rates[norm], options);
         opt_default("g", norm == PAL ? "15" : "18");
 
         opt_default("b", "6000000");
@@ -3903,18 +3838,18 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg)
         opt_default("muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
 
         opt_default("b:a", "448000");
-        audio_sample_rate = 48000;
+        parse_option(o, "ar", "48000", options);
 
     } else if(!strncmp(arg, "dv", 2)) {
 
         parse_option(o, "f", "dv", options);
 
-        opt_frame_size("s", norm == PAL ? "720x576" : "720x480");
-        opt_frame_pix_fmt("pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
-                          norm == PAL ? "yuv420p" : "yuv411p");
-        opt_frame_rate("r", frame_rates[norm]);
+        parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
+        parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
+                          norm == PAL ? "yuv420p" : "yuv411p", options);
+        parse_option(o, "r", frame_rates[norm], options);
 
-        audio_sample_rate = 48000;
+        parse_option(o, "ar", "48000", options);
         parse_option(o, "ac", "2", options);
 
     } else {
@@ -4013,19 +3948,19 @@ static const OptionDef options[] = {
     { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)&copy_initial_nonkeyframes}, "copy initial non-keyframes" },
     { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, {.off = OFFSET(max_frames)}, "set the number of frames to record", "number" },
     { "tag",   OPT_STRING | HAS_ARG | OPT_SPEC, {.off = OFFSET(codec_tags)}, "force codec tag/fourcc", "fourcc/tag" },
+    { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" },
+    { "qscale", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" },
 
     /* video options */
     { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" },
-    { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
-    { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
-    { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
-    { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" },
+    { "r", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_rates)}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
+    { "s", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_sizes)}, "set frame size (WxH or abbreviation)", "size" },
+    { "aspect", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_aspect_ratios)}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
+    { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_pix_fmts)}, "set pixel format", "format" },
     { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(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 quantizer scale (VBR)", "q" },
-    { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
+    { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(rc_overrides)}, "rate control override for specific intervals", "override" },
     { "vcodec", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
-    { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimation threshold",  "threshold" },
     { "same_quant", OPT_BOOL | OPT_VIDEO, {(void*)&same_quant},
       "use same quantizer as source (implies VBR)" },
     { "pass", HAS_ARG | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" },
@@ -4044,14 +3979,14 @@ static const OptionDef options[] = {
     { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" },
     { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" },
     { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
-    { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&force_fps}, "force the selected framerate, disable the best supported framerate selection" },
+    { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(force_fps)}, "force the selected framerate, disable the best supported framerate selection" },
     { "streamid", HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" },
-    { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void *)&forced_key_frames}, "force key frames at specified timestamps", "timestamps" },
+    { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(forced_key_frames)}, "force key frames at specified timestamps", "timestamps" },
 
     /* audio options */
     { "aframes", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_frames}, "set the number of audio frames to record", "number" },
-    { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", },
-    { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
+    { "aq", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_qscale}, "set audio quality (codec-specific)", "quality", },
+    { "ar", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_sample_rate)}, "set audio sampling rate (in Hz)", "rate" },
     { "ac", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_channels)}, "set number of audio channels", "channels" },
     { "an", OPT_BOOL | OPT_AUDIO | OPT_OFFSET, {.off = OFFSET(audio_disable)}, "disable audio" },
     { "acodec", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },