[FFmpeg-devel] [PATCH] ffprobe: report read nb_packets and nb_frames by stream, add count_frames and count_packets options

Matthieu Bouron matthieu.bouron at gmail.com
Mon Feb 6 11:51:41 CET 2012


2012/2/6 Stefano Sabatini <stefasab at gmail.com>:
> On date Wednesday 2012-02-01 17:59:28 +0100, Matthieu Bouron encoded:
>> Hi there,
>>
>> First patch make ffprobe report the number of packets and frames
>> (demuxed/decoded) in streams description when -show_packets and/or
>> -show_frames are used.
>> read_nb_frames is only shown in video stream description.
>>
>> Second patch add two new options to ffprobe: -count_frames, -count_packets.
>> These options will enable frame/packet counting without displaying per
>> frame/packet information.
>> Feel free to comment.
>>
>> Matthieu
>
>> From 977024538e8d0d19d5489623ebd330cedb966fa2 Mon Sep 17 00:00:00 2001
>> From: Matthieu Bouron <matthieu.bouron at smartjog.com>
>> Date: Wed, 1 Feb 2012 16:23:53 +0100
>> Subject: [PATCH 1/2] ffprobe: report read nb_frames and nb_packets per stream
>>
>> ---
>>  doc/ffprobe.xsd |    3 +++
>>  ffprobe.c       |   40 +++++++++++++++++++++++++++++++---------
>>  2 files changed, 34 insertions(+), 9 deletions(-)
>>
>> diff --git a/doc/ffprobe.xsd b/doc/ffprobe.xsd
>> index 9ac80bb..13bbd7e 100644
>> --- a/doc/ffprobe.xsd
>> +++ b/doc/ffprobe.xsd
>> @@ -97,6 +97,7 @@
>>        <xsd:attribute name="pix_fmt"              type="xsd:string"/>
>>        <xsd:attribute name="level"                type="xsd:int"/>
>>        <xsd:attribute name="timecode"             type="xsd:string"/>
>> +      <xsd:attribute name="read_nb_frames"       type="xsd:int"/>
>>
>>        <!-- audio attributes -->
>>        <xsd:attribute name="sample_fmt"       type="xsd:string"/>
>> @@ -111,6 +112,8 @@
>>        <xsd:attribute name="start_time"       type="xsd:float"/>
>>        <xsd:attribute name="duration"         type="xsd:float"/>
>>        <xsd:attribute name="nb_frames"        type="xsd:int"/>
>> +      <xsd:attribute name="read_nb_packets"  type="xsd:int"/>
>> +
>>      </xsd:complexType>
>>
>>      <xsd:complexType name="formatType">
>> diff --git a/ffprobe.c b/ffprobe.c
>> index ca6133e..620ce53 100644
>> --- a/ffprobe.c
>> +++ b/ffprobe.c
>> @@ -133,6 +133,11 @@ static char *value_string(char *buf, int buf_size, struct unit_value uv)
>>      return buf;
>>  }
>>
>
>> +typedef struct ProbeContext {
>> +    uint64_t *streams_nb_packets;
>> +    uint64_t *streams_nb_frames;
>> +} ProbeContext;
>
> Having a ProbeContext may be a good idea, but since we're using
> globals right now I think it would be less confusing to make these
> fields global as well.

Sorry I didn't pay attention, the "ffprobe global context" so I
removed the ProbeContext structure.

>> +
>>  /* WRITERS API */
>>
>>  typedef struct WriterContext WriterContext;
>> @@ -1359,7 +1364,7 @@ static av_always_inline int get_decoded_frame(AVFormatContext *fmt_ctx,
>>      return ret;
>>  }
>>
>> -static void show_packets(WriterContext *w, AVFormatContext *fmt_ctx)
>> +static void show_packets(WriterContext *w, AVFormatContext *fmt_ctx, ProbeContext *probe_ctx)
>>  {
>>      AVPacket pkt, pkt1;
>>      AVFrame frame;
>> @@ -1368,8 +1373,10 @@ static void show_packets(WriterContext *w, AVFormatContext *fmt_ctx)
>>      av_init_packet(&pkt);
>>
>>      while (!av_read_frame(fmt_ctx, &pkt)) {
>> -        if (do_show_packets)
>> +        if (do_show_packets) {
>>              show_packet(w, fmt_ctx, &pkt, i++);
>> +            probe_ctx->streams_nb_packets[pkt.stream_index]++;
>> +        }
>>          if (do_show_frames) {
>>              pkt1 = pkt;
>>              while (1) {
>> @@ -1380,6 +1387,7 @@ static void show_packets(WriterContext *w, AVFormatContext *fmt_ctx)
>>                  show_frame(w, &frame, fmt_ctx->streams[pkt.stream_index]);
>>                  pkt1.data += ret;
>>                  pkt1.size -= ret;
>> +                probe_ctx->streams_nb_frames[pkt.stream_index]++;
>>              }
>>          }
>>          av_free_packet(&pkt);
>> @@ -1390,12 +1398,14 @@ static void show_packets(WriterContext *w, AVFormatContext *fmt_ctx)
>>      //Flush remaining frames that are cached in the decoder
>>      for (i = 0; i < fmt_ctx->nb_streams; i++) {
>>          pkt.stream_index = i;
>> -        while (get_decoded_frame(fmt_ctx, &frame, &got_frame, &pkt) >= 0 && got_frame)
>> +        while (get_decoded_frame(fmt_ctx, &frame, &got_frame, &pkt) >= 0 && got_frame) {
>>              show_frame(w, &frame, fmt_ctx->streams[pkt.stream_index]);
>> +            probe_ctx->streams_nb_frames[pkt.stream_index]++;
>> +        }
>>      }
>>  }
>>
>> -static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx)
>> +static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_idx, ProbeContext *probe_ctx)
>>  {
>>      AVStream *stream = fmt_ctx->streams[stream_idx];
>>      AVCodecContext *dec_ctx;
>> @@ -1498,6 +1508,10 @@ static void show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_i
>>      print_time("duration",      stream->duration,   &stream->time_base);
>>      if (stream->nb_frames) print_fmt    ("nb_frames", "%"PRId64, stream->nb_frames);
>>      else                   print_str_opt("nb_frames", "N/A");
>
>> +    if (probe_ctx->streams_nb_frames[stream_idx] && dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
>> +        print_fmt("read_nb_frames", "%"PRIu64, probe_ctx->streams_nb_frames[stream_idx]);
>> +    if (probe_ctx->streams_nb_packets[stream_idx])
>> +        print_fmt("read_nb_packets", "%"PRIu64, probe_ctx->streams_nb_packets[stream_idx]);
>
> nit: "nb_read_frames", "nb_read_packets" look more readable/consistent to me

I looks better. Patches updated.

> [...]
>
>> From 91d96c37ae223f4a19d9c176d5e618c34f3088cd Mon Sep 17 00:00:00 2001
>> From: Matthieu Bouron <matthieu.bouron at smartjog.com>
>> Date: Wed, 1 Feb 2012 17:37:29 +0100
>> Subject: [PATCH 2/2] ffprobe: add count_frames and count_packets options
>>
>> ---
>>  doc/ffprobe.texi |    8 ++++++++
>>  ffprobe.c        |   19 +++++++++++++------
>>  2 files changed, 21 insertions(+), 6 deletions(-)
> [...]
>
> Looks fine.
> --
> FFmpeg = Frightening and Free Meaningful Powerful Extended Geek
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ffprobe-report-read-nb_frames-and-nb_packets-per-str.patch
Type: text/x-diff
Size: 4453 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120206/9ba4b2f4/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-ffprobe-add-count_frames-and-count_packets-options.patch
Type: text/x-diff
Size: 4406 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120206/9ba4b2f4/attachment-0001.bin>


More information about the ffmpeg-devel mailing list