]> git.sesse.net Git - ffmpeg/blobdiff - ffprobe.c
libswresample.v: add swresample* for cmdutils.c
[ffmpeg] / ffprobe.c
index c15cf7bd2b18f0bda5e16b39718801188d39a1c3..71f7ded6e70f8a67614b43f0bb6a721c26d706e8 100644 (file)
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -141,7 +141,7 @@ typedef struct Writer {
     void (*print_chapter_footer)(WriterContext *wctx, const char *);
     void (*print_section_header)(WriterContext *wctx, const char *);
     void (*print_section_footer)(WriterContext *wctx, const char *);
-    void (*print_integer)       (WriterContext *wctx, const char *, int);
+    void (*print_integer)       (WriterContext *wctx, const char *, long long int);
     void (*print_string)        (WriterContext *wctx, const char *, const char *);
     void (*show_tags)           (WriterContext *wctx, AVDictionary *dict);
     int flags;                  ///< a combination or WRITER_FLAG_*
@@ -254,7 +254,7 @@ static inline void writer_print_section_footer(WriterContext *wctx,
 }
 
 static inline void writer_print_integer(WriterContext *wctx,
-                                        const char *key, int val)
+                                        const char *key, long long int val)
 {
     wctx->writer->print_integer(wctx, key, val);
     wctx->nb_item++;
@@ -285,13 +285,10 @@ static void writer_print_time(WriterContext *wctx, const char *key,
 
 static void writer_print_ts(WriterContext *wctx, const char *key, int64_t ts)
 {
-    char buf[128];
-
     if (ts == AV_NOPTS_VALUE) {
         writer_print_string(wctx, key, "N/A", 1);
     } else {
-        snprintf(buf, sizeof(buf), "%"PRId64, ts);
-        writer_print_string(wctx, key, buf, 0);
+        writer_print_integer(wctx, key, ts);
     }
 }
 
@@ -302,9 +299,9 @@ static inline void writer_show_tags(WriterContext *wctx, AVDictionary *dict)
 
 #define MAX_REGISTERED_WRITERS_NB 64
 
-static Writer *registered_writers[MAX_REGISTERED_WRITERS_NB + 1];
+static const Writer *registered_writers[MAX_REGISTERED_WRITERS_NB + 1];
 
-static int writer_register(Writer *writer)
+static int writer_register(const Writer *writer)
 {
     static int next_registered_writer_idx = 0;
 
@@ -315,7 +312,7 @@ static int writer_register(Writer *writer)
     return 0;
 }
 
-static Writer *writer_get_by_name(const char *name)
+static const Writer *writer_get_by_name(const char *name)
 {
     int i;
 
@@ -436,9 +433,9 @@ static void default_print_str(WriterContext *wctx, const char *key, const char *
     printf("%s=%s\n", key, value);
 }
 
-static void default_print_int(WriterContext *wctx, const char *key, int value)
+static void default_print_int(WriterContext *wctx, const char *key, long long int value)
 {
-    printf("%s=%d\n", key, value);
+    printf("%s=%lld\n", key, value);
 }
 
 static void default_show_tags(WriterContext *wctx, AVDictionary *dict)
@@ -450,7 +447,7 @@ static void default_show_tags(WriterContext *wctx, AVDictionary *dict)
     }
 }
 
-static Writer default_writer = {
+static const Writer default_writer = {
     .name                  = "default",
     .print_footer          = default_print_footer,
     .print_chapter_header  = default_print_chapter_header,
@@ -649,14 +646,14 @@ static void compact_print_str(WriterContext *wctx, const char *key, const char *
                                      value, compact->item_sep, wctx));
 }
 
-static void compact_print_int(WriterContext *wctx, const char *key, int value)
+static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
 {
     CompactContext *compact = wctx->priv;
 
     if (wctx->nb_item) printf("%c", compact->item_sep);
     if (!compact->nokey)
         printf("%s=", key);
-    printf("%d", value);
+    printf("%lld", value);
 }
 
 static void compact_show_tags(WriterContext *wctx, AVDictionary *dict)
@@ -674,18 +671,37 @@ static void compact_show_tags(WriterContext *wctx, AVDictionary *dict)
     }
 }
 
-static Writer compact_writer = {
-    .name          = "compact",
-    .priv_size     = sizeof(CompactContext),
+static const Writer compact_writer = {
+    .name                 = "compact",
+    .priv_size            = sizeof(CompactContext),
+    .init                 = compact_init,
+    .uninit               = compact_uninit,
+    .print_section_header = compact_print_section_header,
+    .print_section_footer = compact_print_section_footer,
+    .print_integer        = compact_print_int,
+    .print_string         = compact_print_str,
+    .show_tags            = compact_show_tags,
+    .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
+};
+
+/* CSV output */
 
-    .init                  = compact_init,
-    .uninit                = compact_uninit,
-    .print_section_header  = compact_print_section_header,
-    .print_section_footer  = compact_print_section_footer,
-    .print_integer         = compact_print_int,
-    .print_string          = compact_print_str,
-    .show_tags             = compact_show_tags,
-    .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS
+static av_cold int csv_init(WriterContext *wctx, const char *args, void *opaque)
+{
+    return compact_init(wctx, "item_sep=,:nokey=1:escape=csv", opaque);
+}
+
+static const Writer csv_writer = {
+    .name                 = "csv",
+    .priv_size            = sizeof(CompactContext),
+    .init                 = csv_init,
+    .uninit               = compact_uninit,
+    .print_section_header = compact_print_section_header,
+    .print_section_footer = compact_print_section_footer,
+    .print_integer        = compact_print_int,
+    .print_string         = compact_print_str,
+    .show_tags            = compact_show_tags,
+    .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
 };
 
 /* JSON output */
@@ -806,12 +822,12 @@ static void json_print_str(WriterContext *wctx, const char *key, const char *val
     json_print_item_str(wctx, key, value, INDENT);
 }
 
-static void json_print_int(WriterContext *wctx, const char *key, int value)
+static void json_print_int(WriterContext *wctx, const char *key, long long int value)
 {
     JSONContext *json = wctx->priv;
 
     if (wctx->nb_item) printf(",\n");
-    printf(INDENT "\"%s\": %d",
+    printf(INDENT "\"%s\": %lld",
            json_escape_str(&json->buf, &json->buf_size, key, wctx), value);
 }
 
@@ -830,10 +846,9 @@ static void json_show_tags(WriterContext *wctx, AVDictionary *dict)
     printf("\n    }");
 }
 
-static Writer json_writer = {
-    .name         = "json",
-    .priv_size    = sizeof(JSONContext),
-
+static const Writer json_writer = {
+    .name                 = "json",
+    .priv_size            = sizeof(JSONContext),
     .init                 = json_init,
     .uninit               = json_uninit,
     .print_header         = json_print_header,
@@ -857,6 +872,7 @@ static void writer_register_all(void)
 
     writer_register(&default_writer);
     writer_register(&compact_writer);
+    writer_register(&csv_writer);
     writer_register(&json_writer);
 }
 
@@ -876,7 +892,7 @@ static void writer_register_all(void)
 #define print_time(k, v, tb)    writer_print_time(w, k, v, tb)
 #define print_ts(k, v)          writer_print_ts(w, k, v)
 #define print_val(k, v, u)      writer_print_string(w, k, \
-    value_string(val_str, sizeof(val_str), (struct unit_value){.val.i = v, .unit=u}), 1)
+    value_string(val_str, sizeof(val_str), (struct unit_value){.val.i = v, .unit=u}), 0)
 #define print_section_header(s) writer_print_section_header(w, s)
 #define print_section_footer(s) writer_print_section_footer(w, s)
 #define show_tags(metadata)     writer_show_tags(w, metadata)
@@ -977,6 +993,17 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
             if (s) print_str    ("pix_fmt", s);
             else   print_str_opt("pix_fmt", "unknown");
             print_int("level",   dec_ctx->level);
+            if (dec_ctx->timecode_frame_start >= 0) {
+                uint32_t tc = dec_ctx->timecode_frame_start;
+                print_fmt("timecode", "%02d:%02d:%02d%c%02d",
+                          tc>>19 & 0x1f,              // hours
+                          tc>>13 & 0x3f,              // minutes
+                          tc>>6  & 0x3f,              // seconds
+                          tc     & 1<<24 ? ';' : ':', // drop
+                          tc     & 0x3f);             // frames
+            } else {
+                print_str_opt("timecode", "N/A");
+            }
             break;
 
         case AVMEDIA_TYPE_AUDIO:
@@ -1103,7 +1130,7 @@ static int probe_file(const char *filename)
 {
     AVFormatContext *fmt_ctx;
     int ret;
-    Writer *w;
+    const Writer *w;
     char *buf;
     char *w_name = NULL, *w_args = NULL;
     WriterContext *wctx;
@@ -1133,7 +1160,7 @@ static int probe_file(const char *filename)
     PRINT_CHAPTER(format);
     writer_print_footer(wctx);
 
-    av_close_input_file(fmt_ctx);
+    avformat_close_input(&fmt_ctx);
     writer_close(&wctx);
 
 end:
@@ -1203,7 +1230,8 @@ static const OptionDef options[] = {
       "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" },
     { "pretty", 0, {(void*)&opt_pretty},
       "prettify the format of displayed values, make it more human readable" },
-    { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format}, "set the output printing format (available formats are: default, compact, json)", "format" },
+    { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format},
+      "set the output printing format (available formats are: default, compact, csv, json)", "format" },
     { "show_format",  OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
     { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" },
     { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },
@@ -1224,7 +1252,7 @@ int main(int argc, char **argv)
     avdevice_register_all();
 #endif
 
-    show_banner();
+    show_banner(argc, argv, options);
     parse_options(NULL, argc, argv, options, opt_input_file);
 
     if (!input_filename) {