Browse code

Implement ffprobe -show_packets.

Originally committed as revision 24577 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini authored on 2010/07/29 08:17:59
Showing 3 changed files
... ...
@@ -26,6 +26,7 @@ version <next>:
26 26
 - libavcore added
27 27
 - SubRip subtitle file muxer and demuxer
28 28
 - Chinese AVS encoding via libxavs
29
+- ffprobe -show_packets option added
29 30
 
30 31
 
31 32
 
... ...
@@ -95,6 +95,13 @@ stream.
95 95
 All the container format information is printed within a section with
96 96
 name ``FORMAT''.
97 97
 
98
+@item -show_packets
99
+Show information about each packet contained in the input multimedia
100
+stream.
101
+
102
+The information for each single packet is printed within a dedicated
103
+section with name ``PACKET''.
104
+
98 105
 @item -show_streams
99 106
 Show information about each media stream contained in the input
100 107
 multimedia stream.
... ...
@@ -32,6 +32,7 @@ const char program_name[] = "FFprobe";
32 32
 const int program_birth_year = 2007;
33 33
 
34 34
 static int do_show_format  = 0;
35
+static int do_show_packets = 0;
35 36
 static int do_show_streams = 0;
36 37
 
37 38
 static int convert_tags                 = 0;
... ...
@@ -101,6 +102,17 @@ static char *time_value_string(char *buf, int buf_size, int64_t val, const AVRat
101 101
     return buf;
102 102
 }
103 103
 
104
+static char *ts_value_string (char *buf, int buf_size, int64_t ts)
105
+{
106
+    if (ts == AV_NOPTS_VALUE) {
107
+        snprintf(buf, buf_size, "N/A");
108
+    } else {
109
+        snprintf(buf, buf_size, "%"PRId64, ts);
110
+    }
111
+
112
+    return buf;
113
+}
114
+
104 115
 static const char *media_type_string(enum AVMediaType media_type)
105 116
 {
106 117
     switch (media_type) {
... ...
@@ -113,6 +125,36 @@ static const char *media_type_string(enum AVMediaType media_type)
113 113
     }
114 114
 }
115 115
 
116
+static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
117
+{
118
+    char val_str[128];
119
+    AVStream *st = fmt_ctx->streams[pkt->stream_index];
120
+
121
+    printf("[PACKET]\n");
122
+    printf("codec_type=%s\n"   , media_type_string(st->codec->codec_type));
123
+    printf("stream_index=%d\n" , pkt->stream_index);
124
+    printf("pts=%s\n"          , ts_value_string  (val_str, sizeof(val_str), pkt->pts));
125
+    printf("pts_time=%s\n"     , time_value_string(val_str, sizeof(val_str), pkt->pts, &st->time_base));
126
+    printf("dts=%s\n"          , ts_value_string  (val_str, sizeof(val_str), pkt->dts));
127
+    printf("dts_time=%s\n"     , time_value_string(val_str, sizeof(val_str), pkt->dts, &st->time_base));
128
+    printf("duration=%s\n"     , ts_value_string  (val_str, sizeof(val_str), pkt->duration));
129
+    printf("duration_time=%s\n", time_value_string(val_str, sizeof(val_str), pkt->duration, &st->time_base));
130
+    printf("size=%s\n"         , value_string     (val_str, sizeof(val_str), pkt->size, unit_byte_str));
131
+    printf("pos=%"PRId64"\n"   , pkt->pos);
132
+    printf("flags=%c\n"        , pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
133
+    printf("[/PACKET]\n");
134
+}
135
+
136
+static void show_packets(AVFormatContext *fmt_ctx)
137
+{
138
+    AVPacket pkt;
139
+
140
+    av_init_packet(&pkt);
141
+
142
+    while (!av_read_frame(fmt_ctx, &pkt))
143
+        show_packet(fmt_ctx, &pkt);
144
+}
145
+
116 146
 static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
117 147
 {
118 148
     AVStream *stream = fmt_ctx->streams[stream_idx];
... ...
@@ -267,6 +309,9 @@ static int probe_file(const char *filename)
267 267
     if ((ret = open_input_file(&fmt_ctx, filename)))
268 268
         return ret;
269 269
 
270
+    if (do_show_packets)
271
+        show_packets(fmt_ctx);
272
+
270 273
     if (do_show_streams)
271 274
         for (i = 0; i < fmt_ctx->nb_streams; i++)
272 275
             show_stream(fmt_ctx, i);
... ...
@@ -334,6 +379,7 @@ static const OptionDef options[] = {
334 334
     { "pretty", 0, {(void*)&opt_pretty},
335 335
       "prettify the format of displayed values, make it more human readable" },
336 336
     { "show_format",  OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
337
+    { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" },
337 338
     { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },
338 339
     { NULL, },
339 340
 };