]> git.sesse.net Git - ffmpeg/blobdiff - cmdutils.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / cmdutils.c
index 4363e8a8426496d30af10348694f5c48f3d5a93b..2bc6b7417f9ce992da472a0d7d4a9affde6dea1f 100644 (file)
@@ -76,7 +76,8 @@ void uninit_opts(void)
     av_freep(&avformat_opts->key);
     av_freep(&avformat_opts);
 #if CONFIG_SWSCALE
-    av_freep(&sws_opts);
+    sws_freeContext(sws_opts);
+    sws_opts = NULL;
 #endif
     for (i = 0; i < opt_name_count; i++) {
         av_freep(&opt_names[i]);
@@ -84,6 +85,7 @@ void uninit_opts(void)
     }
     av_freep(&opt_names);
     av_freep(&opt_values);
+    opt_name_count = 0;
 }
 
 void log_callback_help(void* ptr, int level, const char* fmt, va_list vl)
@@ -271,15 +273,13 @@ unknown_opt:
                 *po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
             } else if (po->flags & OPT_FLOAT) {
                 *po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
-            } else if (po->flags & OPT_FUNC2) {
-                if (po->u.func2_arg(opt, arg) < 0) {
-                    fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
-                    exit(1);
-                }
             } else if (po->flags & OPT_DUMMY) {
                 /* Do nothing for this option */
             } else {
-                po->u.func_arg(arg);
+                if (po->u.func_arg(opt, arg) < 0) {
+                    fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt);
+                    exit(1);
+                }
             }
             if(po->flags & OPT_EXIT)
                 exit(0);
@@ -300,7 +300,7 @@ int opt_default(const char *opt, const char *arg){
     AVInputFormat *iformat = NULL;
 
     while ((p = av_codec_next(p))) {
-        AVClass *c = p->priv_class;
+        const AVClass *c = p->priv_class;
         if (c && av_find_opt(&c, opt, NULL, 0, 0))
             break;
     }
@@ -410,13 +410,25 @@ int opt_timelimit(const char *opt, const char *arg)
     return 0;
 }
 
+static void *alloc_priv_context(int size, const AVClass *class)
+{
+    void *p = av_mallocz(size);
+    if (p) {
+        *(const AVClass **)p = class;
+        av_opt_set_defaults(p);
+    }
+    return p;
+}
+
 void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec)
 {
     int i;
     void *priv_ctx=NULL;
     if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){
         AVCodecContext *avctx= ctx;
-        if(codec && codec->priv_class && avctx->priv_data){
+        if(codec && codec->priv_class){
+            if(!avctx->priv_data && codec->priv_data_size)
+                avctx->priv_data= alloc_priv_context(codec->priv_data_size, codec->priv_class);
             priv_ctx= avctx->priv_data;
         }
     } else if (!strcmp("AVFormatContext", (*(AVClass**)ctx)->class_name)) {
@@ -434,7 +446,7 @@ void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec)
         const char *str;
         if (priv_ctx) {
             if (av_find_opt(priv_ctx, opt_names[i], NULL, flags, flags)) {
-                if (av_set_string3(priv_ctx, opt_names[i], opt_values[i], 0, NULL) < 0) {
+                if (av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL) < 0) {
                     fprintf(stderr, "Invalid value '%s' for option '%s'\n",
                             opt_names[i], opt_values[i]);
                     exit(1);
@@ -836,6 +848,23 @@ FILE *get_preset_file(char *filename, size_t filename_size,
         av_strlcpy(filename, preset_name, filename_size);
         f = fopen(filename, "r");
     } else {
+#ifdef _WIN32
+        char datadir[MAX_PATH], *ls;
+        base[2] = NULL;
+
+        if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
+        {
+            for (ls = datadir; ls < datadir + strlen(datadir); ls++)
+                if (*ls == '\\') *ls = '/';
+
+            if (ls = strrchr(datadir, '/'))
+            {
+                *ls = 0;
+                strncat(datadir, "/ffpresets",  sizeof(datadir) - 1 - strlen(datadir));
+                base[2] = datadir;
+            }
+        }
+#endif
         for (i = 0; i < 3 && !f; i++) {
             if (!base[i])
                 continue;
@@ -896,6 +925,7 @@ int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
 {
     int ret;
     AVFilterBufferRef *picref;
+    *picref_ptr = NULL;
 
     if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0)
         return ret;
@@ -907,10 +937,12 @@ int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
 
     memcpy(frame->data,     picref->data,     sizeof(frame->data));
     memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
+    frame->pkt_pos          = picref->pos;
     frame->interlaced_frame = picref->video->interlaced;
     frame->top_field_first  = picref->video->top_field_first;
     frame->key_frame        = picref->video->key_frame;
     frame->pict_type        = picref->video->pict_type;
+    frame->sample_aspect_ratio = picref->video->sample_aspect_ratio;
 
     return 1;
 }