]> git.sesse.net Git - ffmpeg/blobdiff - ffprobe.c
Support decoding of 2bpp and 4bpp TIFF images.
[ffmpeg] / ffprobe.c
index 44252e59daf80b521a938e3c53b8f1b39791090a..be7b2bf24f42c8c379c7a5e683489220eac415da 100644 (file)
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -25,6 +25,7 @@
 #include "libavcodec/avcodec.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/dict.h"
 #include "libavdevice/avdevice.h"
 #include "cmdutils.h"
 
@@ -82,9 +83,11 @@ static char *value_string(char *buf, int buf_size, double val, const char *unit)
             prefix_string = decimal_unit_prefixes[index];
         }
 
-        snprintf(buf, buf_size, "%.3f %s%s", val, prefix_string, show_value_unit ? unit : "");
+        snprintf(buf, buf_size, "%.3f%s%s%s", val, prefix_string || show_value_unit ? " " : "",
+                 prefix_string, show_value_unit ? unit : "");
     } else {
-        snprintf(buf, buf_size, "%f %s", val, show_value_unit ? unit : "");
+        snprintf(buf, buf_size, "%f%s%s", val, show_value_unit ? " " : "",
+                 show_value_unit ? unit : "");
     }
 
     return buf;
@@ -114,14 +117,8 @@ static char *ts_value_string (char *buf, int buf_size, int64_t ts)
 
 static const char *media_type_string(enum AVMediaType media_type)
 {
-    switch (media_type) {
-    case AVMEDIA_TYPE_VIDEO:      return "video";
-    case AVMEDIA_TYPE_AUDIO:      return "audio";
-    case AVMEDIA_TYPE_DATA:       return "data";
-    case AVMEDIA_TYPE_SUBTITLE:   return "subtitle";
-    case AVMEDIA_TYPE_ATTACHMENT: return "attachment";
-    default:                      return "unknown";
-    }
+    const char *s = av_get_media_type_string(media_type);
+    return s ? s : "unknown";
 }
 
 static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
@@ -142,6 +139,7 @@ static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
     printf("pos=%"PRId64"\n"   , pkt->pos);
     printf("flags=%c\n"        , pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
     printf("[/PACKET]\n");
+    fflush(stdout);
 }
 
 static void show_packets(AVFormatContext *fmt_ctx)
@@ -160,7 +158,7 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
     AVCodecContext *dec_ctx;
     AVCodec *dec;
     char val_str[128];
-    AVMetadataTag *tag = NULL;
+    AVDictionaryEntry *tag = NULL;
     AVRational display_aspect_ratio;
 
     printf("[STREAM]\n");
@@ -200,6 +198,7 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
             }
             printf("pix_fmt=%s\n",                 dec_ctx->pix_fmt != PIX_FMT_NONE ?
                    av_pix_fmt_descriptors[dec_ctx->pix_fmt].name : "unknown");
+            printf("level=%d\n",                   dec_ctx->level);
             break;
 
         case AVMEDIA_TYPE_AUDIO:
@@ -226,15 +225,16 @@ static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
     if (stream->nb_frames)
         printf("nb_frames=%"PRId64"\n",    stream->nb_frames);
 
-    while ((tag = av_metadata_get(stream->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX)))
+    while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
         printf("TAG:%s=%s\n", tag->key, tag->value);
 
     printf("[/STREAM]\n");
+    fflush(stdout);
 }
 
 static void show_format(AVFormatContext *fmt_ctx)
 {
-    AVMetadataTag *tag = NULL;
+    AVDictionaryEntry *tag = NULL;
     char val_str[128];
 
     printf("[FORMAT]\n");
@@ -252,27 +252,28 @@ static void show_format(AVFormatContext *fmt_ctx)
     printf("bit_rate=%s\n",         value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate,
                                                  unit_bit_per_second_str));
 
-    while ((tag = av_metadata_get(fmt_ctx->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX)))
+    while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
         printf("TAG:%s=%s\n", tag->key, tag->value);
 
     printf("[/FORMAT]\n");
+    fflush(stdout);
 }
 
 static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
 {
     int err, i;
-    AVFormatParameters fmt_params;
-    AVFormatContext *fmt_ctx;
+    AVFormatContext *fmt_ctx = NULL;
+    AVDictionaryEntry *t;
 
-    memset(&fmt_params, 0, sizeof(fmt_params));
-    fmt_params.prealloced_context = 1;
-    fmt_ctx = avformat_alloc_context();
-    set_context_opts(fmt_ctx, avformat_opts, AV_OPT_FLAG_DECODING_PARAM, NULL);
-
-    if ((err = av_open_input_file(&fmt_ctx, filename, iformat, 0, &fmt_params)) < 0) {
+    if ((err = avformat_open_input(&fmt_ctx, filename, iformat, &format_opts)) < 0) {
         print_error(filename, err);
         return err;
     }
+    if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
+        av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
+        return AVERROR_OPTION_NOT_FOUND;
+    }
+
 
     /* fill the streams in the format context */
     if ((err = av_find_stream_info(fmt_ctx)) < 0) {
@@ -290,7 +291,7 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
         if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
             fprintf(stderr, "Unsupported codec with id %d for input stream %d\n",
                     stream->codec->codec_id, stream->index);
-        } else if (avcodec_open(stream->codec, codec) < 0) {
+        } else if (avcodec_open2(stream->codec, codec, NULL) < 0) {
             fprintf(stderr, "Error while opening codec for input stream %d\n",
                     stream->index);
         }
@@ -325,7 +326,7 @@ static int probe_file(const char *filename)
 static void show_usage(void)
 {
     printf("Simple multimedia streams analyzer\n");
-    printf("usage: ffprobe [OPTIONS] [INPUT_FILE]\n");
+    printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name);
     printf("\n");
 }
 
@@ -352,7 +353,7 @@ static int opt_input_file(const char *opt, const char *arg)
     return 0;
 }
 
-static void show_help(void)
+static int opt_help(const char *opt, const char *arg)
 {
     av_log_set_callback(log_callback_help);
     show_usage();
@@ -360,14 +361,16 @@ static void show_help(void)
     printf("\n");
     av_opt_show2(avformat_opts, NULL,
                  AV_OPT_FLAG_DECODING_PARAM, 0);
+    return 0;
 }
 
-static void opt_pretty(void)
+static int opt_pretty(const char *opt, const char *arg)
 {
     show_value_unit              = 1;
     use_value_prefix             = 1;
     use_byte_value_binary_prefix = 1;
     use_value_sexagesimal_format = 1;
+    return 0;
 }
 
 static const OptionDef options[] = {
@@ -385,6 +388,7 @@ static const OptionDef options[] = {
     { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" },
     { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },
     { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
+    { "i", HAS_ARG, {(void *)opt_input_file}, "read specified file", "input_file"},
     { NULL, },
 };
 
@@ -393,19 +397,18 @@ int main(int argc, char **argv)
     int ret;
 
     av_register_all();
+    init_opts();
 #if CONFIG_AVDEVICE
     avdevice_register_all();
 #endif
 
-    avformat_opts = avformat_alloc_context();
-
     show_banner();
     parse_options(argc, argv, options, opt_input_file);
 
     if (!input_filename) {
         show_usage();
         fprintf(stderr, "You have to specify one input file.\n");
-        fprintf(stderr, "Use -h to get full help or, even better, run 'man ffprobe'.\n");
+        fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
         exit(1);
     }