X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cmdutils.c;h=f696700142cfe113b4a4ea30756616be24087117;hb=7b378c2fb76387cb91793ed18f546a3a19bdd615;hp=a8200012e54f9a462e9b62d0e27f8e2ce43270b8;hpb=eadba3e94daac2f48fd9ce7c9fdf5a562d3274ed;p=ffmpeg diff --git a/cmdutils.c b/cmdutils.c index a8200012e54..f696700142c 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -54,6 +54,7 @@ #include "libavformat/network.h" #endif #if HAVE_SYS_RESOURCE_H +#include #include #endif @@ -380,7 +381,7 @@ int locate_option(int argc, char **argv, const OptionDef *options, (po->name && !strcmp(optname, po->name))) return i; - if (!po || po->flags & HAS_ARG) + if (po->flags & HAS_ARG) i++; } return 0; @@ -436,9 +437,11 @@ void parse_loglevel(int argc, char **argv, const OptionDef *options) int opt_default(void *optctx, const char *opt, const char *arg) { const AVOption *o; + int consumed = 0; char opt_stripped[128]; const char *p; - const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(), *sc, *swr_class; + const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(); + const AVClass *sc, *swr_class; if (!(p = strchr(opt, ':'))) p = opt + strlen(opt); @@ -447,36 +450,44 @@ int opt_default(void *optctx, const char *opt, const char *arg) if ((o = av_opt_find(&cc, opt_stripped, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) || ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') && - (o = av_opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) + (o = av_opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) { av_dict_set(&codec_opts, opt, arg, FLAGS); - else if ((o = av_opt_find(&fc, opt, NULL, 0, - AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) + consumed = 1; + } + if ((o = av_opt_find(&fc, opt, NULL, 0, + AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { av_dict_set(&format_opts, opt, arg, FLAGS); + if(consumed) + av_log(NULL, AV_LOG_VERBOSE, "Routing %s to codec and muxer layer\n", opt); + consumed = 1; + } #if CONFIG_SWSCALE sc = sws_get_class(); - if (!o && (o = av_opt_find(&sc, opt, NULL, 0, - AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { + if (!consumed && 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_opt_set(sws_opts, opt, arg, 0); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt); return ret; } + consumed = 1; } #endif #if CONFIG_SWRESAMPLE swr_class = swr_get_class(); - if (!o && (o = av_opt_find(&swr_class, opt, NULL, 0, - AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { + if (!consumed && av_opt_find(&swr_class, opt, NULL, 0, + AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) { int ret = av_opt_set(swr_opts, opt, arg, 0); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt); return ret; } + consumed = 1; } #endif - if (o) + if (consumed) return 0; av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt); return AVERROR_OPTION_NOT_FOUND; @@ -691,12 +702,13 @@ int show_version(void *optctx, const char *opt, const char *arg) int show_license(void *optctx, const char *opt, const char *arg) { - printf( #if CONFIG_NONFREE + printf( "This version of %s has nonfree parts compiled in.\n" "Therefore it is not legally redistributable.\n", - program_name + program_name ); #elif CONFIG_GPLV3 + printf( "%s is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" "the Free Software Foundation; either version 3 of the License, or\n" @@ -709,8 +721,9 @@ int show_license(void *optctx, const char *opt, const char *arg) "\n" "You should have received a copy of the GNU General Public License\n" "along with %s. If not, see .\n", - program_name, program_name, program_name + program_name, program_name, program_name ); #elif CONFIG_GPL + printf( "%s is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" "the Free Software Foundation; either version 2 of the License, or\n" @@ -724,8 +737,9 @@ int show_license(void *optctx, const char *opt, const char *arg) "You should have received a copy of the GNU General Public License\n" "along with %s; if not, write to the Free Software\n" "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n", - program_name, program_name, program_name + program_name, program_name, program_name ); #elif CONFIG_LGPLV3 + printf( "%s is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU Lesser General Public License as published by\n" "the Free Software Foundation; either version 3 of the License, or\n" @@ -738,8 +752,9 @@ int show_license(void *optctx, const char *opt, const char *arg) "\n" "You should have received a copy of the GNU Lesser General Public License\n" "along with %s. If not, see .\n", - program_name, program_name, program_name + program_name, program_name, program_name ); #else + printf( "%s is free software; you can redistribute it and/or\n" "modify it under the terms of the GNU Lesser General Public\n" "License as published by the Free Software Foundation; either\n" @@ -753,9 +768,8 @@ int show_license(void *optctx, const char *opt, const char *arg) "You should have received a copy of the GNU Lesser General Public\n" "License along with %s; if not, write to the Free Software\n" "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n", - program_name, program_name, program_name + program_name, program_name, program_name ); #endif - ); return 0; } @@ -1094,7 +1108,7 @@ int show_filters(void *optctx, const char *opt, const char *arg) int show_pix_fmts(void *optctx, const char *opt, const char *arg) { - enum AVPixelFormat pix_fmt; + const AVPixFmtDescriptor *pix_desc = NULL; printf("Pixel formats:\n" "I.... = Supported Input format for conversion\n" @@ -1110,8 +1124,8 @@ int show_pix_fmts(void *optctx, const char *opt, const char *arg) # define sws_isSupportedOutput(x) 0 #endif - for (pix_fmt = 0; pix_fmt < AV_PIX_FMT_NB; pix_fmt++) { - const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt]; + while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) { + enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(pix_desc); if(!pix_desc->name) continue; printf("%c%c%c%c%c %-16s %d %2d\n", @@ -1303,6 +1317,11 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size) fseek(f, 0, SEEK_END); *size = ftell(f); fseek(f, 0, SEEK_SET); + if (*size == (size_t)-1) { + av_log(NULL, AV_LOG_ERROR, "IO error: %s\n", strerror(errno)); + fclose(f); + return AVERROR(errno); + } *bufptr = av_malloc(*size + 1); if (!*bufptr) { av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n"); @@ -1320,7 +1339,7 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size) ret = AVERROR_EOF; } else { ret = 0; - (*bufptr)[*size++] = '\0'; + (*bufptr)[(*size)++] = '\0'; } fclose(f); @@ -1484,13 +1503,19 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) static int alloc_buffer(FrameBuffer **pool, AVCodecContext *s, FrameBuffer **pbuf) { - FrameBuffer *buf = av_mallocz(sizeof(*buf)); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt); + FrameBuffer *buf; int i, ret; - const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1; + int pixel_size; int h_chroma_shift, v_chroma_shift; int edge = 32; // XXX should be avcodec_get_edge_width(), but that fails on svq1 int w = s->width, h = s->height; + if (!desc) + return AVERROR(EINVAL); + pixel_size = desc->comp[0].step_minus1 + 1; + + buf = av_mallocz(sizeof(*buf)); if (!buf) return AVERROR(ENOMEM);