[FFmpeg-devel] [PATCH] ffprobe: add -framecount option.
Clément Bœsch
ubitux at gmail.com
Mon Oct 3 18:01:04 CEST 2011
Hi,
Some information might not be available until we loop over all the
packets, and the number of frames is among them. This patch add the
possibility to run a slow analysis in order to get that value.
This really is a "violent" method, slow, and not really sexy (I don't like
the seek I have to do for instance), but it might be useful for various
reasons.
Any better idea is welcome,
Regards,
--
Clément B.
-------------- next part --------------
From 8cd400bd3d56139fc78b2ebd1e6b0d98a3952858 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <clement.boesch at smartjog.com>
Date: Mon, 3 Oct 2011 17:54:40 +0200
Subject: [PATCH] ffprobe: add -framecount option.
---
doc/ffprobe.texi | 17 +++++++++++++++++
ffprobe.c | 25 +++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
index a5d5df8..1504652 100644
--- a/doc/ffprobe.texi
+++ b/doc/ffprobe.texi
@@ -112,6 +112,23 @@ multimedia stream.
Each media stream information is printed within a dedicated section
with name "STREAM".
+ at item -framecount @var{mode}
+Advanced frame count.
+Available modes are:
+
+ at table @option
+ at item default
+Only print nb_frames if available.
+
+ at item soft
+Count each video frame if nb_frames is not available, and print them under the
+key exact_nb_frames. Also print exact_nb_key_frames. This operation is slow.
+
+ at item hard
+Whatever the value of nb_frames, exact_nb_frames and exact_nb_key_frames will
+be computed and printed. Just like soft, this operation is slow.
+ at end table
+
@item -i @var{input_file}
Read @var{input_file}.
diff --git a/ffprobe.c b/ffprobe.c
index 2c354ad..135e204 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -41,6 +41,7 @@ static int use_value_prefix = 0;
static int use_byte_value_binary_prefix = 0;
static int use_value_sexagesimal_format = 0;
+static char *framecount;
static char *print_format;
static const OptionDef options[];
@@ -439,6 +440,29 @@ static void show_stream(struct writer *w, AVFormatContext *fmt_ctx, int stream_i
if (stream->nb_frames)
print_fmt("nb_frames", "%"PRId64, stream->nb_frames);
+ if (fmt_ctx->pb->seekable &&
+ stream->codec && stream->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
+ (strcmp(framecount, "hard") == 0 ||
+ (strcmp(framecount, "soft") == 0 && stream->nb_frames == 0))) {
+ AVPacket pkt;
+ int64_t nb_frames = 0, nb_key_frames = 0;
+
+ av_init_packet(&pkt);
+ while (av_read_frame(fmt_ctx, &pkt) >= 0) {
+ if (pkt.stream_index == stream_idx) {
+ nb_frames++;
+ nb_key_frames += pkt.flags & AV_PKT_FLAG_KEY;
+ }
+ av_free_packet(&pkt);
+ }
+ print_fmt("exact_nb_frames", "%"PRId64, nb_frames);
+ print_fmt("exact_nb_key_frames", "%"PRId64, nb_key_frames);
+
+ if (av_seek_frame(fmt_ctx, stream_idx, 0, AVSEEK_FLAG_BYTE) < 0)
+ av_seek_frame(fmt_ctx, stream_idx, 0, AVSEEK_FLAG_BACKWARD);
+ }
+
+
w->show_tags(w, stream->metadata);
w->print_footer("STREAM");
@@ -660,6 +684,7 @@ static const OptionDef options[] = {
{ "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" },
+ { "framecount", OPT_STRING | HAS_ARG, {(void*)&framecount}, "advanced frame count (available modes are: default, soft, hard)", "mode" },
{ "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, },
--
1.7.5.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111003/e94ca964/attachment.asc>
More information about the ffmpeg-devel
mailing list