]> git.sesse.net Git - ffmpeg/blobdiff - cmdutils.c
Fix a bunch of common typos.
[ffmpeg] / cmdutils.c
index 1e873e66a1bd74a5b304ce4ff85f57640486ccaa..1c2bf4696b1f0633c04055bff2b76ac219ddbb26 100644 (file)
@@ -35,6 +35,7 @@
 #include "libswscale/swscale.h"
 #include "libpostproc/postprocess.h"
 #include "libavutil/avstring.h"
+#include "libavutil/mathematics.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/eval.h"
@@ -130,6 +131,16 @@ void show_help_options(const OptionDef *options, const char *msg, int mask, int
     }
 }
 
+void show_help_children(const AVClass *class, int flags)
+{
+    const AVClass *child = NULL;
+    av_opt_show2(&class, NULL, flags, 0);
+    printf("\n");
+
+    while (child = av_opt_child_class_next(class, child))
+        show_help_children(child, flags);
+}
+
 static const OptionDef* find_option(const OptionDef *po, const char *name){
     const char *p = strchr(name, ':');
     int len = p ? p - name : strlen(name);
@@ -335,11 +346,13 @@ static int locate_option(int argc, char **argv, const OptionDef *options, const
 void parse_loglevel(int argc, char **argv, const OptionDef *options)
 {
     int idx = locate_option(argc, argv, options, "loglevel");
+    if (!idx)
+        idx = locate_option(argc, argv, options, "v");
     if (idx && argv[idx + 1])
         opt_loglevel("loglevel", argv[idx + 1]);
 }
 
-#define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
+#define FLAGS (o->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
 int opt_default(const char *opt, const char *arg)
 {
     const AVOption *o;
@@ -359,7 +372,7 @@ int opt_default(const char *opt, const char *arg)
         av_dict_set(&format_opts, opt, arg, FLAGS);
     else if ((o = av_opt_find(&sc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
         // XXX we only support sws_flags, not arbitrary sws options
-        int ret = av_set_string3(sws_opts, opt, arg, 1, NULL);
+        int ret = av_opt_set(sws_opts, opt, arg, 0);
         if (ret < 0) {
             av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
             return ret;
@@ -773,8 +786,9 @@ int read_yesno(void)
     return yesno;
 }
 
-int read_file(const char *filename, char **bufptr, size_t *size)
+int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
 {
+    int ret;
     FILE *f = fopen(filename, "rb");
 
     if (!f) {
@@ -790,11 +804,22 @@ int read_file(const char *filename, char **bufptr, size_t *size)
         fclose(f);
         return AVERROR(ENOMEM);
     }
-    fread(*bufptr, 1, *size, f);
-    (*bufptr)[*size++] = '\0';
+    ret = fread(*bufptr, 1, *size, f);
+    if (ret < *size) {
+        av_free(*bufptr);
+        if (ferror(f)) {
+            av_log(NULL, AV_LOG_ERROR, "Error while reading file '%s': %s\n",
+                   filename, strerror(errno));
+            ret = AVERROR(errno);
+        } else
+            ret = AVERROR_EOF;
+    } else {
+        ret = 0;
+        (*bufptr)[*size++] = '\0';
+    }
 
     fclose(f);
-    return 0;
+    return ret;
 }
 
 void init_pts_correction(PtsCorrectionContext *ctx)
@@ -858,7 +883,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
 {
     if (*spec <= '9' && *spec >= '0')                                        /* opt:index */
         return strtol(spec, NULL, 0) == st->index;
-    else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd') { /* opt:[vasd] */
+    else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' || *spec == 't') { /* opt:[vasdt] */
         enum AVMediaType type;
 
         switch (*spec++) {
@@ -866,6 +891,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
         case 'a': type = AVMEDIA_TYPE_AUDIO;    break;
         case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
         case 'd': type = AVMEDIA_TYPE_DATA;     break;
+        case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
         }
         if (type != st->codec->codec_type)
             return 0;