diff mbox series

[FFmpeg-devel,6/9] fftools/ffmpeg: print keyframe information with -stats_*

Message ID 20231214193138.2503-6-anton@khirnov.net
State Accepted
Commit 02a43936476ad69f4957c8444a740bdb394bde37
Headers show
Series [FFmpeg-devel,1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Dec. 14, 2023, 7:31 p.m. UTC
---
 doc/ffmpeg.texi           | 3 +++
 fftools/ffmpeg.h          | 1 +
 fftools/ffmpeg_enc.c      | 2 ++
 fftools/ffmpeg_mux_init.c | 1 +
 4 files changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index f157c06e12..059102b75a 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -2207,6 +2207,9 @@  Current bitrate in bits per second. Post-encoding only.
 @item abr (@emph{packet})
 Average bitrate for the whole stream so far, in bits per second, -1 if it cannot
 be determined at this point. Post-encoding only.
+
+@item key (@emph{packet})
+Character 'K' if the packet contains a keyframe, character 'N' otherwise.
 @end table
 
 Directives tagged with @emph{packet} may only be used with
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 96f4e757e1..03dbb528c0 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -465,6 +465,7 @@  enum EncStatsType {
     ENC_STATS_PKT_SIZE,
     ENC_STATS_BITRATE,
     ENC_STATS_AVG_BITRATE,
+    ENC_STATS_KEYFRAME,
 };
 
 typedef struct EncStatsComponent {
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 9141dab6a4..d774a7e008 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -520,6 +520,8 @@  void enc_stats_write(OutputStream *ost, EncStats *es,
             case ENC_STATS_DTS:         avio_printf(io, "%"PRId64,  pkt->dts);                      continue;
             case ENC_STATS_DTS_TIME:    avio_printf(io, "%g",       pkt->dts * av_q2d(tb));         continue;
             case ENC_STATS_PKT_SIZE:    avio_printf(io, "%d",       pkt->size);                     continue;
+            case ENC_STATS_KEYFRAME:    avio_write(io, (pkt->flags & AV_PKT_FLAG_KEY) ?
+                                                       "K" : "N", 1);                               continue;
             case ENC_STATS_BITRATE: {
                 double duration = FFMAX(pkt->duration, 1) * av_q2d(tb);
                 avio_printf(io, "%g",  8.0 * pkt->size / duration);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index f870d48136..0203701d78 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -309,6 +309,7 @@  static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
         { ENC_STATS_PKT_SIZE,       "size",     0, 1            },
         { ENC_STATS_BITRATE,        "br",       0, 1            },
         { ENC_STATS_AVG_BITRATE,    "abr",      0, 1            },
+        { ENC_STATS_KEYFRAME,       "key",      0, 1            },
     };
     const char *next = fmt_spec;