Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext
@ 2023-12-14 19:31 Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 2/9] fftools/ffmpeg: deprecate -fps_mode/vsync drop Anton Khirnov
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

Only the muxer itself is supposed to do that. Log to OutputStream
instead.

Drop now-redundant information from the logged string.
---
 fftools/ffmpeg_mux.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 8e523dd49d..74df6dcb64 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -176,9 +176,8 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
         if (pkt->dts != AV_NOPTS_VALUE &&
             pkt->pts != AV_NOPTS_VALUE &&
             pkt->dts > pkt->pts) {
-            av_log(s, AV_LOG_WARNING, "Invalid DTS: %"PRId64" PTS: %"PRId64" in output stream %d:%d, replacing by guess\n",
-                   pkt->dts, pkt->pts,
-                   mux->of.index, ost->st->index);
+            av_log(ost, AV_LOG_WARNING, "Invalid DTS: %"PRId64" PTS: %"PRId64", replacing by guess\n",
+                   pkt->dts, pkt->pts);
             pkt->pts =
             pkt->dts = pkt->pts + pkt->dts + ms->last_mux_dts + 1
                      - FFMIN3(pkt->pts, pkt->dts, ms->last_mux_dts + 1)
@@ -192,15 +191,15 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
                 int loglevel = max - pkt->dts > 2 || ost->type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
                 if (exit_on_error)
                     loglevel = AV_LOG_ERROR;
-                av_log(s, loglevel, "Non-monotonic DTS in output stream "
-                       "%d:%d; previous: %"PRId64", current: %"PRId64"; ",
-                       mux->of.index, ost->st->index, ms->last_mux_dts, pkt->dts);
+                av_log(ost, loglevel, "Non-monotonic DTS; "
+                       "previous: %"PRId64", current: %"PRId64"; ",
+                       ms->last_mux_dts, pkt->dts);
                 if (exit_on_error) {
                     ret = AVERROR(EINVAL);
                     goto fail;
                 }
 
-                av_log(s, loglevel, "changing to %"PRId64". This may result "
+                av_log(ost, loglevel, "changing to %"PRId64". This may result "
                        "in incorrect timestamps in the output file.\n",
                        max);
                 if (pkt->pts >= pkt->dts)
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH 2/9] fftools/ffmpeg: deprecate -fps_mode/vsync drop
  2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
@ 2023-12-14 19:31 ` Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 3/9] fftools/ffmpeg_mux: factor timestamps processing out of write_packet() Anton Khirnov
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

It depends on the ability of muxers to generate timestamps, which is
itself deprecated.
---
 doc/ffmpeg.texi         | 3 ---
 fftools/ffmpeg.h        | 3 +++
 fftools/ffmpeg_filter.c | 9 +++++++--
 fftools/ffmpeg_mux.c    | 2 ++
 fftools/ffmpeg_opt.c    | 7 ++++++-
 5 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index c503963941..f157c06e12 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1742,9 +1742,6 @@ constant frame rate.
 @item vfr (2)
 Frames are passed through with their timestamp or dropped so as to
 prevent 2 frames from having the same timestamp.
-@item drop
-As passthrough but destroys all timestamps, making the muxer generate
-fresh timestamps based on frame-rate.
 @item auto (-1)
 Chooses between cfr and vfr depending on muxer capabilities. This is the
 default method.
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index affa80856a..96f4e757e1 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -60,6 +60,7 @@
 #define FFMPEG_OPT_ENC_TIME_BASE_NUM 1
 #define FFMPEG_OPT_TOP 1
 #define FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP 1
+#define FFMPEG_OPT_VSYNC_DROP 1
 
 #define FFMPEG_ERROR_RATE_EXCEEDED FFERRTAG('E', 'R', 'E', 'D')
 
@@ -69,7 +70,9 @@ enum VideoSyncMethod {
     VSYNC_CFR,
     VSYNC_VFR,
     VSYNC_VSCFR,
+#if FFMPEG_OPT_VSYNC_DROP
     VSYNC_DROP,
+#endif
 };
 
 enum EncTimeBase {
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index bb755d7bb4..9fc877b437 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -2104,8 +2104,11 @@ static void video_sync_process(OutputFilterPriv *ofp, AVFrame *frame,
 
     if (delta0 < 0 &&
         delta > 0 &&
-        ost->vsync_method != VSYNC_PASSTHROUGH &&
-        ost->vsync_method != VSYNC_DROP) {
+        ost->vsync_method != VSYNC_PASSTHROUGH
+#if FFMPEG_OPT_VSYNC_DROP
+        && ost->vsync_method != VSYNC_DROP
+#endif
+        ) {
         if (delta0 < -0.6) {
             av_log(ost, AV_LOG_VERBOSE, "Past duration %f too large\n", -delta0);
         } else
@@ -2143,7 +2146,9 @@ static void video_sync_process(OutputFilterPriv *ofp, AVFrame *frame,
             ofp->next_pts = llrint(sync_ipts);
         frame->duration = llrint(duration);
         break;
+#if FFMPEG_OPT_VSYNC_DROP
     case VSYNC_DROP:
+#endif
     case VSYNC_PASSTHROUGH:
         ofp->next_pts = llrint(sync_ipts);
         frame->duration = llrint(duration);
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 74df6dcb64..3ce4ef131e 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -150,8 +150,10 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
         goto fail;
     }
 
+#if FFMPEG_OPT_VSYNC_DROP
     if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP)
         pkt->pts = pkt->dts = AV_NOPTS_VALUE;
+#endif
 
     // rescale timestamps to the stream timebase
     if (ost->type == AVMEDIA_TYPE_AUDIO && !ost->enc) {
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 6177a96a4e..96d3c56fd7 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -188,7 +188,12 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id
     if      (!av_strcasecmp(arg, "cfr"))         *vsync_var = VSYNC_CFR;
     else if (!av_strcasecmp(arg, "vfr"))         *vsync_var = VSYNC_VFR;
     else if (!av_strcasecmp(arg, "passthrough")) *vsync_var = VSYNC_PASSTHROUGH;
-    else if (!av_strcasecmp(arg, "drop"))        *vsync_var = VSYNC_DROP;
+#if FFMPEG_OPT_VSYNC_DROP
+    else if (!av_strcasecmp(arg, "drop")) {
+        av_log(NULL, AV_LOG_WARNING, "-vsync/fps_mode drop is deprecated\n");
+        *vsync_var = VSYNC_DROP;
+    }
+#endif
     else if (!is_global && !av_strcasecmp(arg, "auto"))  *vsync_var = VSYNC_AUTO;
     else if (!is_global) {
         av_log(NULL, AV_LOG_FATAL, "Invalid value %s specified for fps_mode of #%d:%d.\n", arg, file_idx, st_idx);
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH 3/9] fftools/ffmpeg_mux: factor timestamps processing out of write_packet()
  2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 2/9] fftools/ffmpeg: deprecate -fps_mode/vsync drop Anton Khirnov
@ 2023-12-14 19:31 ` Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 4/9] fftools/cmdutils: change option flags to (1 << N) style Anton Khirnov
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_mux.c | 50 ++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 3ce4ef131e..88ce3cd60c 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -135,20 +135,9 @@ static void mux_log_debug_ts(OutputStream *ost, const AVPacket *pkt)
            pkt->size, *latency ? latency : "N/A");
 }
 
-static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
+static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket *pkt)
 {
-    MuxStream *ms = ms_from_ost(ost);
-    AVFormatContext *s = mux->fc;
-    int64_t fs;
-    uint64_t frame_num;
-    int ret;
-
-    fs = filesize(s->pb);
-    atomic_store(&mux->last_filesize, fs);
-    if (fs >= mux->limit_filesize) {
-        ret = AVERROR_EOF;
-        goto fail;
-    }
+    OutputStream *ost = &ms->ost;
 
 #if FFMPEG_OPT_VSYNC_DROP
     if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP)
@@ -174,7 +163,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
         av_packet_rescale_ts(pkt, pkt->time_base, ost->st->time_base);
     pkt->time_base = ost->st->time_base;
 
-    if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
+    if (!(mux->fc->oformat->flags & AVFMT_NOTIMESTAMPS)) {
         if (pkt->dts != AV_NOPTS_VALUE &&
             pkt->pts != AV_NOPTS_VALUE &&
             pkt->dts > pkt->pts) {
@@ -188,7 +177,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
         if ((ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO || ost->type == AVMEDIA_TYPE_SUBTITLE) &&
             pkt->dts != AV_NOPTS_VALUE &&
             ms->last_mux_dts != AV_NOPTS_VALUE) {
-            int64_t max = ms->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT);
+            int64_t max = ms->last_mux_dts + !(mux->fc->oformat->flags & AVFMT_TS_NONSTRICT);
             if (pkt->dts < max) {
                 int loglevel = max - pkt->dts > 2 || ost->type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG;
                 if (exit_on_error)
@@ -197,8 +186,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
                        "previous: %"PRId64", current: %"PRId64"; ",
                        ms->last_mux_dts, pkt->dts);
                 if (exit_on_error) {
-                    ret = AVERROR(EINVAL);
-                    goto fail;
+                    return AVERROR(EINVAL);
                 }
 
                 av_log(ost, loglevel, "changing to %"PRId64". This may result "
@@ -212,14 +200,36 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
     }
     ms->last_mux_dts = pkt->dts;
 
+    if (debug_ts)
+        mux_log_debug_ts(ost, pkt);
+
+    return 0;
+}
+
+static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
+{
+    MuxStream *ms = ms_from_ost(ost);
+    AVFormatContext *s = mux->fc;
+    int64_t fs;
+    uint64_t frame_num;
+    int ret;
+
+    fs = filesize(s->pb);
+    atomic_store(&mux->last_filesize, fs);
+    if (fs >= mux->limit_filesize) {
+        ret = AVERROR_EOF;
+        goto fail;
+    }
+
+    ret = mux_fixup_ts(mux, ms, pkt);
+    if (ret < 0)
+        goto fail;
+
     ms->data_size_mux += pkt->size;
     frame_num = atomic_fetch_add(&ost->packets_written, 1);
 
     pkt->stream_index = ost->index;
 
-    if (debug_ts)
-        mux_log_debug_ts(ost, pkt);
-
     if (ms->stats.io)
         enc_stats_write(ost, &ms->stats, NULL, pkt, frame_num);
 
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH 4/9] fftools/cmdutils: change option flags to (1 << N) style
  2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 2/9] fftools/ffmpeg: deprecate -fps_mode/vsync drop Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 3/9] fftools/ffmpeg_mux: factor timestamps processing out of write_packet() Anton Khirnov
@ 2023-12-14 19:31 ` Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 5/9] fftools/ffmpeg_mux_init: change 1-bit bitfields from int to unsigned Anton Khirnov
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

It is easier to read.
---
 fftools/cmdutils.h | 47 ++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 8b67d827cc..85479f90e4 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -106,28 +106,31 @@ typedef struct SpecifierOpt {
 typedef struct OptionDef {
     const char *name;
     int flags;
-#define HAS_ARG    0x0001
-#define OPT_BOOL   0x0002
-#define OPT_EXPERT 0x0004
-#define OPT_STRING 0x0008
-#define OPT_VIDEO  0x0010
-#define OPT_AUDIO  0x0020
-#define OPT_INT    0x0080
-#define OPT_FLOAT  0x0100
-#define OPT_SUBTITLE 0x0200
-#define OPT_INT64  0x0400
-#define OPT_EXIT   0x0800
-#define OPT_DATA   0x1000
-#define OPT_PERFILE  0x2000     /* the option is per-file (currently ffmpeg-only).
-                                   implied by OPT_OFFSET or OPT_SPEC */
-#define OPT_OFFSET 0x4000       /* option is specified as an offset in a passed optctx */
-#define OPT_SPEC   0x8000       /* option is to be stored in an array of SpecifierOpt.
-                                   Implies OPT_OFFSET. Next element after the offset is
-                                   an int containing element count in the array. */
-#define OPT_TIME  0x10000
-#define OPT_DOUBLE 0x20000
-#define OPT_INPUT  0x40000
-#define OPT_OUTPUT 0x80000
+#define HAS_ARG         (1 << 0)
+#define OPT_BOOL        (1 << 1)
+#define OPT_EXPERT      (1 << 2)
+#define OPT_STRING      (1 << 3)
+#define OPT_VIDEO       (1 << 4)
+#define OPT_AUDIO       (1 << 5)
+#define OPT_INT         (1 << 6)
+#define OPT_FLOAT       (1 << 7)
+#define OPT_SUBTITLE    (1 << 8)
+#define OPT_INT64       (1 << 9)
+#define OPT_EXIT        (1 << 10)
+#define OPT_DATA        (1 << 11)
+/* The option is per-file (currently ffmpeg-only).
+   implied by OPT_OFFSET or OPT_SPEC */
+#define OPT_PERFILE     (1 << 12)
+/* Option is specified as an offset in a passed optctx */
+#define OPT_OFFSET      (1 << 13)
+/* Option is to be stored in an array of SpecifierOpt. Implies OPT_OFFSET.
+   Next element after the offset is an int containing element count in the
+   array. */
+#define OPT_SPEC        (1 << 14)
+#define OPT_TIME        (1 << 15)
+#define OPT_DOUBLE      (1 << 16)
+#define OPT_INPUT       (1 << 17)
+#define OPT_OUTPUT      (1 << 18)
      union {
         void *dst_ptr;
         int (*func_arg)(void *, const char *, const char *);
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH 5/9] fftools/ffmpeg_mux_init: change 1-bit bitfields from int to unsigned
  2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
                   ` (2 preceding siblings ...)
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 4/9] fftools/cmdutils: change option flags to (1 << N) style Anton Khirnov
@ 2023-12-14 19:31 ` Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 6/9] fftools/ffmpeg: print keyframe information with -stats_* Anton Khirnov
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

They cannot store 1 as signed, only 0 and -1.

Avoids warnings such as:
  implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
---
 fftools/ffmpeg_mux_init.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index f527a083db..f870d48136 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -288,9 +288,9 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
     static const struct {
         enum EncStatsType  type;
         const char        *str;
-        int                pre_only:1;
-        int                post_only:1;
-        int                need_input_data:1;
+        unsigned           pre_only:1;
+        unsigned           post_only:1;
+        unsigned           need_input_data:1;
     } fmt_specs[] = {
         { ENC_STATS_FILE_IDX,       "fidx"                      },
         { ENC_STATS_STREAM_IDX,     "sidx"                      },
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH 6/9] fftools/ffmpeg: print keyframe information with -stats_*
  2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
                   ` (3 preceding siblings ...)
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 5/9] fftools/ffmpeg_mux_init: change 1-bit bitfields from int to unsigned Anton Khirnov
@ 2023-12-14 19:31 ` Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 7/9] doc/ffmpeg: drop misleading claims from -stats_*_fmt Anton Khirnov
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

---
 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 --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;
 
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH 7/9] doc/ffmpeg: drop misleading claims from -stats_*_fmt
  2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
                   ` (4 preceding siblings ...)
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 6/9] fftools/ffmpeg: print keyframe information with -stats_* Anton Khirnov
@ 2023-12-14 19:31 ` Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 8/9] fftools/ffmpeg_mux: deduplicate uniniting EncStats Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: use a mutex for enc_stats_write() Anton Khirnov
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

The {br}/{abr} directives are not limited to post-encoding, they can
also be used pre-muxing. The already-present {packet} tag describes this
more accurately, so just drop the assertions.
---
 doc/ffmpeg.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 059102b75a..6ecd5f3cfe 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -2202,11 +2202,11 @@ Number of audio samples in the frame.
 Size of the encoded packet in bytes.
 
 @item br (@emph{packet})
-Current bitrate in bits per second. Post-encoding only.
+Current bitrate in bits per second.
 
 @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.
+be determined at this point.
 
 @item key (@emph{packet})
 Character 'K' if the packet contains a keyframe, character 'N' otherwise.
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH 8/9] fftools/ffmpeg_mux: deduplicate uniniting EncStats
  2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
                   ` (5 preceding siblings ...)
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 7/9] doc/ffmpeg: drop misleading claims from -stats_*_fmt Anton Khirnov
@ 2023-12-14 19:31 ` Anton Khirnov
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: use a mutex for enc_stats_write() Anton Khirnov
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_mux.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 88ce3cd60c..357f34172f 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -773,6 +773,13 @@ int of_write_trailer(OutputFile *of)
     return mux_result;
 }
 
+static void enc_stats_uninit(EncStats *es)
+{
+    for (int i = 0; i < es->nb_components; i++)
+        av_freep(&es->components[i].str);
+    av_freep(&es->components);
+}
+
 static void ost_free(OutputStream **post)
 {
     OutputStream *ost = *post;
@@ -818,17 +825,9 @@ static void ost_free(OutputStream **post)
         av_freep(&ost->enc_ctx->stats_in);
     avcodec_free_context(&ost->enc_ctx);
 
-    for (int i = 0; i < ost->enc_stats_pre.nb_components; i++)
-        av_freep(&ost->enc_stats_pre.components[i].str);
-    av_freep(&ost->enc_stats_pre.components);
-
-    for (int i = 0; i < ost->enc_stats_post.nb_components; i++)
-        av_freep(&ost->enc_stats_post.components[i].str);
-    av_freep(&ost->enc_stats_post.components);
-
-    for (int i = 0; i < ms->stats.nb_components; i++)
-        av_freep(&ms->stats.components[i].str);
-    av_freep(&ms->stats.components);
+    enc_stats_uninit(&ost->enc_stats_pre);
+    enc_stats_uninit(&ost->enc_stats_post);
+    enc_stats_uninit(&ms->stats);
 
     av_freep(post);
 }
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: use a mutex for enc_stats_write()
  2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
                   ` (6 preceding siblings ...)
  2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 8/9] fftools/ffmpeg_mux: deduplicate uniniting EncStats Anton Khirnov
@ 2023-12-14 19:31 ` Anton Khirnov
  7 siblings, 0 replies; 9+ messages in thread
From: Anton Khirnov @ 2023-12-14 19:31 UTC (permalink / raw)
  To: ffmpeg-devel

It may be called concurrently from different threads to write into the
same file.
---
 fftools/ffmpeg.h          | 3 +++
 fftools/ffmpeg_enc.c      | 4 ++++
 fftools/ffmpeg_mux.c      | 4 ++++
 fftools/ffmpeg_mux_init.c | 5 +++++
 4 files changed, 16 insertions(+)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 03dbb528c0..33a29b316f 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -480,6 +480,9 @@ typedef struct EncStats {
     int              nb_components;
 
     AVIOContext        *io;
+
+    pthread_mutex_t     lock;
+    int                 lock_initialized;
 } EncStats;
 
 extern const char *const forced_keyframes_const_names[];
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index d774a7e008..57590a43a3 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -491,6 +491,8 @@ void enc_stats_write(OutputStream *ost, EncStats *es,
         ptsi = fd->dec.pts;
     }
 
+    pthread_mutex_lock(&es->lock);
+
     for (size_t i = 0; i < es->nb_components; i++) {
         const EncStatsComponent *c = &es->components[i];
 
@@ -538,6 +540,8 @@ void enc_stats_write(OutputStream *ost, EncStats *es,
     }
     avio_w8(io, '\n');
     avio_flush(io);
+
+    pthread_mutex_unlock(&es->lock);
 }
 
 static inline double psnr(double d)
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 357f34172f..ab86abee14 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -778,6 +778,10 @@ static void enc_stats_uninit(EncStats *es)
     for (int i = 0; i < es->nb_components; i++)
         av_freep(&es->components[i].str);
     av_freep(&es->components);
+
+    if (es->lock_initialized)
+        pthread_mutex_destroy(&es->lock);
+    es->lock_initialized = 0;
 }
 
 static void ost_free(OutputStream **post)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 0203701d78..52eca9f9d5 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -402,6 +402,11 @@ fail:
             return ret;
     }
 
+    ret = pthread_mutex_init(&es->lock, NULL);
+    if (ret)
+        return AVERROR(ret);
+    es->lock_initialized = 1;
+
     ret = enc_stats_get_file(&es->io, path);
     if (ret < 0)
         return ret;
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-14 19:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-14 19:31 [FFmpeg-devel] [PATCH 1/9] fftools/ffmpeg_mux: stop logging to AVFormatContext Anton Khirnov
2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 2/9] fftools/ffmpeg: deprecate -fps_mode/vsync drop Anton Khirnov
2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 3/9] fftools/ffmpeg_mux: factor timestamps processing out of write_packet() Anton Khirnov
2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 4/9] fftools/cmdutils: change option flags to (1 << N) style Anton Khirnov
2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 5/9] fftools/ffmpeg_mux_init: change 1-bit bitfields from int to unsigned Anton Khirnov
2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 6/9] fftools/ffmpeg: print keyframe information with -stats_* Anton Khirnov
2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 7/9] doc/ffmpeg: drop misleading claims from -stats_*_fmt Anton Khirnov
2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 8/9] fftools/ffmpeg_mux: deduplicate uniniting EncStats Anton Khirnov
2023-12-14 19:31 ` [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: use a mutex for enc_stats_write() Anton Khirnov

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git