X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cmdutils.c;h=62c87cb6b62911524fe19d8d2599826bb5f5a3fe;hb=74d9b2134081da5ad5d8320b5fb5ff1d871df61f;hp=9542bbf091a5dd756f7e9d9a3702dd6294012493;hpb=f9a2d0c3feccab94a86c92396f3e36110dc2227b;p=ffmpeg diff --git a/cmdutils.c b/cmdutils.c index 9542bbf091a..62c87cb6b62 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -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); @@ -336,11 +347,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) ((o)->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0 +#define FLAGS(o) ((o)->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0 int opt_default(const char *opt, const char *arg) { const AVOption *oc, *of, *os; @@ -362,7 +375,7 @@ int opt_default(const char *opt, const char *arg) sc = sws_get_class(); if ((os = 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; @@ -411,6 +424,12 @@ int opt_loglevel(const char *opt, const char *arg) return 0; } +int opt_codec_debug(const char *opt, const char *arg) +{ + av_log_set_level(AV_LOG_DEBUG); + return opt_default(opt, arg); +} + int opt_timelimit(const char *opt, const char *arg) { #if HAVE_SETRLIMIT @@ -484,9 +503,9 @@ void show_banner(void) program_name, program_birth_year, this_year); av_log(NULL, AV_LOG_INFO, " built on %s %s with %s %s\n", __DATE__, __TIME__, CC_TYPE, CC_VERSION); - av_log(NULL, AV_LOG_VERBOSE, " configuration: " FFMPEG_CONFIGURATION "\n"); - print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_VERBOSE); - print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_VERBOSE); + av_log(NULL, AV_LOG_INFO, " configuration: " FFMPEG_CONFIGURATION "\n"); + print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_INFO); + print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_INFO); } int opt_version(const char *opt, const char *arg) { @@ -756,6 +775,8 @@ int opt_pix_fmts(const char *opt, const char *arg) for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) { const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt]; + if(!pix_desc->name) + continue; printf("%c%c%c%c%c %-16s %d %2d\n", sws_isSupportedInput (pix_fmt) ? 'I' : '.', sws_isSupportedOutput(pix_fmt) ? 'O' : '.', @@ -789,8 +810,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) { @@ -806,11 +828,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; } FILE *get_preset_file(char *filename, size_t filename_size, @@ -912,11 +945,10 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) return AVERROR(EINVAL); } -AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFormatContext *s, AVStream *st) +AVDictionary *filter_codec_opts(AVDictionary *opts, AVCodec *codec, AVFormatContext *s, AVStream *st) { AVDictionary *ret = NULL; AVDictionaryEntry *t = NULL; - AVCodec *codec = s->oformat ? avcodec_find_encoder(codec_id) : avcodec_find_decoder(codec_id); int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM : AV_OPT_FLAG_DECODING_PARAM; char prefix = 0; const AVClass *cc = avcodec_get_class(); @@ -966,7 +998,7 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *cod return NULL; } for (i = 0; i < s->nb_streams; i++) - opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codec->codec_id, s, s->streams[i]); + opts[i] = filter_codec_opts(codec_opts, avcodec_find_decoder(s->streams[i]->codec->codec_id), s, s->streams[i]); return opts; }