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 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder
@ 2023-04-09 14:08 Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 02/29] fftools/ffmpeg: move OutputStream.next_pts " Anton Khirnov
                   ` (28 more replies)
  0 siblings, 29 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

It is video encoding-only and does not need to be visible outside of
ffmpeg_enc.c
---
 fftools/ffmpeg.h     |  2 --
 fftools/ffmpeg_enc.c | 11 +++++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 8193dabb57..886124d874 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -571,8 +571,6 @@ typedef struct OutputStream {
     InputStream *ist;
 
     AVStream *st;            /* stream in the output file */
-    /* number of frames emitted by the video-encoding sync code */
-    int64_t vsync_frame_number;
     /* predicted pts of the next frame to be encoded
      * audio/video encoding only */
     int64_t next_pts;
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 2f1803a74c..5266026945 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -45,6 +45,8 @@
 
 struct Encoder {
     AVFrame *last_frame;
+    /* number of frames emitted by the video-encoding sync code */
+    int64_t vsync_frame_number;
 };
 
 static uint64_t dup_warning = 1000;
@@ -832,6 +834,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost,
                                AVFrame *next_picture, double duration,
                                int64_t *nb_frames, int64_t *nb_frames_prev)
 {
+    Encoder *e = ost->enc;
     double delta0, delta;
 
     double sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture);
@@ -861,7 +864,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost,
 
     switch (ost->vsync_method) {
     case VSYNC_VSCFR:
-        if (ost->vsync_frame_number == 0 && delta0 >= 0.5) {
+        if (e->vsync_frame_number == 0 && delta0 >= 0.5) {
             av_log(ost, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0));
             delta = duration;
             delta0 = 0;
@@ -869,7 +872,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost,
         }
     case VSYNC_CFR:
         // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
-        if (frame_drop_threshold && delta < frame_drop_threshold && ost->vsync_frame_number) {
+        if (frame_drop_threshold && delta < frame_drop_threshold && e->vsync_frame_number) {
             *nb_frames = 0;
         } else if (delta < -1.1)
             *nb_frames = 0;
@@ -998,7 +1001,7 @@ static void do_video_out(OutputFile *of,
         nb_frames_drop++;
         av_log(ost, AV_LOG_VERBOSE,
                "*** dropping frame %"PRId64" at ts %"PRId64"\n",
-               ost->vsync_frame_number, e->last_frame->pts);
+               e->vsync_frame_number, e->last_frame->pts);
     }
     if (nb_frames > (nb_frames_prev && ost->last_dropped) + (nb_frames > nb_frames_prev)) {
         if (nb_frames > dts_error_threshold * 30) {
@@ -1043,7 +1046,7 @@ static void do_video_out(OutputFile *of,
             exit_program(1);
 
         ost->next_pts++;
-        ost->vsync_frame_number++;
+        e->vsync_frame_number++;
     }
 
     av_frame_unref(e->last_frame);
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 02/29] fftools/ffmpeg: move OutputStream.next_pts to Encoder
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 03/29] fftools/ffmpeg: move OutputStream.sq_frame " Anton Khirnov
                   ` (27 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

It is audio/video encoding-only and does not need to be visible outside
of ffmpeg_enc.c
---
 fftools/ffmpeg.h     |  3 ---
 fftools/ffmpeg_enc.c | 22 +++++++++++++---------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 886124d874..e7e7d88577 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -571,9 +571,6 @@ typedef struct OutputStream {
     InputStream *ist;
 
     AVStream *st;            /* stream in the output file */
-    /* predicted pts of the next frame to be encoded
-     * audio/video encoding only */
-    int64_t next_pts;
     /* dts of the last packet sent to the muxing queue, in AV_TIME_BASE_Q */
     int64_t last_mux_dts;
     /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 5266026945..bb11cdf42a 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -44,6 +44,9 @@
 #include "libavformat/avformat.h"
 
 struct Encoder {
+    /* predicted pts of the next frame to be encoded */
+    int64_t next_pts;
+
     AVFrame *last_frame;
     /* number of frames emitted by the video-encoding sync code */
     int64_t vsync_frame_number;
@@ -761,11 +764,12 @@ static int submit_encode_frame(OutputFile *of, OutputStream *ost,
 static void do_audio_out(OutputFile *of, OutputStream *ost,
                          AVFrame *frame)
 {
+    Encoder          *e = ost->enc;
     AVCodecContext *enc = ost->enc_ctx;
     int ret;
 
     if (frame->pts == AV_NOPTS_VALUE)
-        frame->pts = ost->next_pts;
+        frame->pts = e->next_pts;
     else {
         int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
         frame->pts =
@@ -777,7 +781,7 @@ static void do_audio_out(OutputFile *of, OutputStream *ost,
     if (!check_recording_time(ost, frame->pts, frame->time_base))
         return;
 
-    ost->next_pts = frame->pts + frame->nb_samples;
+    e->next_pts = frame->pts + frame->nb_samples;
 
     ret = submit_encode_frame(of, ost, frame);
     if (ret < 0 && ret != AVERROR_EOF)
@@ -840,7 +844,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost,
     double sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture);
     /* delta0 is the "drift" between the input frame (next_picture) and
      * where it would fall in the output. */
-    delta0 = sync_ipts - ost->next_pts;
+    delta0 = sync_ipts - e->next_pts;
     delta  = delta0 + duration;
 
     // tracks the number of times the PREVIOUS frame should be duplicated,
@@ -857,7 +861,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost,
             av_log(ost, AV_LOG_VERBOSE, "Past duration %f too large\n", -delta0);
         } else
             av_log(ost, AV_LOG_DEBUG, "Clipping frame in rate conversion by %f\n", -delta0);
-        sync_ipts = ost->next_pts;
+        sync_ipts = e->next_pts;
         duration += delta0;
         delta0 = 0;
     }
@@ -868,7 +872,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost,
             av_log(ost, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0));
             delta = duration;
             delta0 = 0;
-            ost->next_pts = llrint(sync_ipts);
+            e->next_pts = llrint(sync_ipts);
         }
     case VSYNC_CFR:
         // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
@@ -887,13 +891,13 @@ static void video_sync_process(OutputFile *of, OutputStream *ost,
         if (delta <= -0.6)
             *nb_frames = 0;
         else if (delta > 0.6)
-            ost->next_pts = llrint(sync_ipts);
+            e->next_pts = llrint(sync_ipts);
         next_picture->duration = duration;
         break;
     case VSYNC_DROP:
     case VSYNC_PASSTHROUGH:
         next_picture->duration = duration;
-        ost->next_pts = llrint(sync_ipts);
+        e->next_pts = llrint(sync_ipts);
         break;
     default:
         av_assert0(0);
@@ -1031,7 +1035,7 @@ static void do_video_out(OutputFile *of,
         if (!in_picture)
             return;
 
-        in_picture->pts = ost->next_pts;
+        in_picture->pts = e->next_pts;
 
         if (!check_recording_time(ost, in_picture->pts, ost->enc_ctx->time_base))
             return;
@@ -1045,7 +1049,7 @@ static void do_video_out(OutputFile *of,
         else if (ret < 0)
             exit_program(1);
 
-        ost->next_pts++;
+        e->next_pts++;
         e->vsync_frame_number++;
     }
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 03/29] fftools/ffmpeg: move OutputStream.sq_frame to Encoder
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 02/29] fftools/ffmpeg: move OutputStream.next_pts " Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 04/29] fftools/ffmpeg: move OutputStream.last_nb0_frames " Anton Khirnov
                   ` (26 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

It is audio/video encoding-only and does not need to be visible outside
of ffmpeg_enc.c
---
 fftools/ffmpeg.h          |  1 -
 fftools/ffmpeg_enc.c      | 17 ++++++++++++++---
 fftools/ffmpeg_mux.c      |  1 -
 fftools/ffmpeg_mux_init.c |  4 ----
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index e7e7d88577..84418d8da5 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -588,7 +588,6 @@ typedef struct OutputStream {
     Encoder *enc;
     AVCodecContext *enc_ctx;
     AVFrame *filtered_frame;
-    AVFrame *sq_frame;
     AVPacket *pkt;
     int64_t last_dropped;
     int64_t last_nb0_frames[3];
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index bb11cdf42a..5c56ad0325 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -50,6 +50,8 @@ struct Encoder {
     AVFrame *last_frame;
     /* number of frames emitted by the video-encoding sync code */
     int64_t vsync_frame_number;
+
+    AVFrame *sq_frame;
 };
 
 static uint64_t dup_warning = 1000;
@@ -62,6 +64,7 @@ void enc_free(Encoder **penc)
         return;
 
     av_frame_free(&enc->last_frame);
+    av_frame_free(&enc->sq_frame);
 
     av_freep(penc);
 }
@@ -139,6 +142,7 @@ static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba
 int enc_open(OutputStream *ost, AVFrame *frame)
 {
     InputStream *ist = ost->ist;
+    Encoder              *e = ost->enc;
     AVCodecContext *enc_ctx = ost->enc_ctx;
     AVCodecContext *dec_ctx = NULL;
     const AVCodec      *enc = enc_ctx->codec;
@@ -328,6 +332,12 @@ int enc_open(OutputStream *ost, AVFrame *frame)
         return ret;
     }
 
+    if (ost->sq_idx_encode >= 0) {
+        e->sq_frame = av_frame_alloc();
+        if (!e->sq_frame)
+            return AVERROR(ENOMEM);
+    }
+
     if (ost->enc_ctx->frame_size) {
         av_assert0(ost->sq_idx_encode >= 0);
         sq_frame_samples(output_files[ost->file_index]->sq_encode,
@@ -718,16 +728,17 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
 static int submit_encode_frame(OutputFile *of, OutputStream *ost,
                                AVFrame *frame)
 {
+    Encoder *e = ost->enc;
     int ret;
 
     if (ost->sq_idx_encode < 0)
         return encode_frame(of, ost, frame);
 
     if (frame) {
-        ret = av_frame_ref(ost->sq_frame, frame);
+        ret = av_frame_ref(e->sq_frame, frame);
         if (ret < 0)
             return ret;
-        frame = ost->sq_frame;
+        frame = e->sq_frame;
     }
 
     ret = sq_send(of->sq_encode, ost->sq_idx_encode,
@@ -740,7 +751,7 @@ static int submit_encode_frame(OutputFile *of, OutputStream *ost,
     }
 
     while (1) {
-        AVFrame *enc_frame = ost->sq_frame;
+        AVFrame *enc_frame = e->sq_frame;
 
         ret = sq_receive(of->sq_encode, ost->sq_idx_encode,
                                SQFRAME(enc_frame));
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 527567831f..5663b8f11d 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -663,7 +663,6 @@ static void ost_free(OutputStream **post)
     av_bsf_free(&ms->bsf_ctx);
 
     av_frame_free(&ost->filtered_frame);
-    av_frame_free(&ost->sq_frame);
     av_packet_free(&ost->pkt);
     av_dict_free(&ost->encoder_opts);
 
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6c53a8810d..ee5829c7fe 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1505,10 +1505,6 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u
             if (ost->sq_idx_encode < 0)
                 return ost->sq_idx_encode;
 
-            ost->sq_frame = av_frame_alloc();
-            if (!ost->sq_frame)
-                return AVERROR(ENOMEM);
-
             if (ms->max_frames != INT64_MAX)
                 sq_limit_frames(of->sq_encode, ost->sq_idx_encode, ms->max_frames);
         }
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 04/29] fftools/ffmpeg: move OutputStream.last_nb0_frames to Encoder
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 02/29] fftools/ffmpeg: move OutputStream.next_pts " Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 03/29] fftools/ffmpeg: move OutputStream.sq_frame " Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 05/29] fftools/ffmpeg: move OutputStream.last_filter_pts to OutputFilter Anton Khirnov
                   ` (25 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

It is video encoding-only and does not need to be visible outside of
ffmpeg_enc.c

Also, rename the variable to frames_prev_hist to be consistent with
the naming in do_video_out().
---
 fftools/ffmpeg.h     |  1 -
 fftools/ffmpeg_enc.c | 18 +++++++++++-------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 84418d8da5..b45a2039ce 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -590,7 +590,6 @@ typedef struct OutputStream {
     AVFrame *filtered_frame;
     AVPacket *pkt;
     int64_t last_dropped;
-    int64_t last_nb0_frames[3];
 
     /* video only */
     AVRational frame_rate;
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 5c56ad0325..7f6bd76f10 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -50,6 +50,10 @@ struct Encoder {
     AVFrame *last_frame;
     /* number of frames emitted by the video-encoding sync code */
     int64_t vsync_frame_number;
+    /* history of nb_frames_prev, i.e. the number of times the
+     * previous frame was duplicated by vsync code in recent
+     * do_video_out() calls */
+    int64_t frames_prev_hist[3];
 
     AVFrame *sq_frame;
 };
@@ -999,18 +1003,18 @@ static void do_video_out(OutputFile *of,
 
     if (!next_picture) {
         //end, flushing
-        nb_frames_prev = nb_frames = mid_pred(ost->last_nb0_frames[0],
-                                              ost->last_nb0_frames[1],
-                                              ost->last_nb0_frames[2]);
+        nb_frames_prev = nb_frames = mid_pred(e->frames_prev_hist[0],
+                                              e->frames_prev_hist[1],
+                                              e->frames_prev_hist[2]);
     } else {
         video_sync_process(of, ost, next_picture, duration,
                            &nb_frames, &nb_frames_prev);
     }
 
-    memmove(ost->last_nb0_frames + 1,
-            ost->last_nb0_frames,
-            sizeof(ost->last_nb0_frames[0]) * (FF_ARRAY_ELEMS(ost->last_nb0_frames) - 1));
-    ost->last_nb0_frames[0] = nb_frames_prev;
+    memmove(e->frames_prev_hist + 1,
+            e->frames_prev_hist,
+            sizeof(e->frames_prev_hist[0]) * (FF_ARRAY_ELEMS(e->frames_prev_hist) - 1));
+    e->frames_prev_hist[0] = nb_frames_prev;
 
     if (nb_frames_prev == 0 && ost->last_dropped) {
         nb_frames_drop++;
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 05/29] fftools/ffmpeg: move OutputStream.last_filter_pts to OutputFilter
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (2 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 04/29] fftools/ffmpeg: move OutputStream.last_nb0_frames " Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 06/29] fftools/ffmpeg_enc: replace abort() with av_assert0(0) Anton Khirnov
                   ` (24 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

This value is associated with the filtergraph output rather than the
output stream, so this is a more appropriate place for it.
---
 fftools/ffmpeg.c          |  8 ++++----
 fftools/ffmpeg.h          |  5 +++--
 fftools/ffmpeg_filter.c   | 21 +++++++++++++++------
 fftools/ffmpeg_mux_init.c |  1 -
 4 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 750ab76693..1f50b82794 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -697,8 +697,8 @@ static int reap_filters(int flush)
 
             if (filtered_frame->pts != AV_NOPTS_VALUE) {
                 AVRational tb = av_buffersink_get_time_base(filter);
-                ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb,
-                                                    AV_TIME_BASE_Q);
+                ost->filter->last_pts = av_rescale_q(filtered_frame->pts, tb,
+                                                     AV_TIME_BASE_Q);
                 filtered_frame->time_base = tb;
 
                 if (debug_ts)
@@ -2391,8 +2391,8 @@ static OutputStream *choose_output(void)
     for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
         int64_t opts;
 
-        if (ost->filter && ost->last_filter_pts != AV_NOPTS_VALUE) {
-            opts = ost->last_filter_pts;
+        if (ost->filter && ost->filter->last_pts != AV_NOPTS_VALUE) {
+            opts = ost->filter->last_pts;
         } else {
             opts = ost->last_mux_dts == AV_NOPTS_VALUE ?
                    INT64_MIN : ost->last_mux_dts;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b45a2039ce..84ce017320 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -314,6 +314,9 @@ typedef struct OutputFilter {
     const int *formats;
     const AVChannelLayout *ch_layouts;
     const int *sample_rates;
+
+    /* pts of the last frame received from this filter, in AV_TIME_BASE_Q */
+    int64_t last_pts;
 } OutputFilter;
 
 typedef struct FilterGraph {
@@ -573,8 +576,6 @@ typedef struct OutputStream {
     AVStream *st;            /* stream in the output file */
     /* dts of the last packet sent to the muxing queue, in AV_TIME_BASE_Q */
     int64_t last_mux_dts;
-    /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */
-    int64_t last_filter_pts;
 
     // timestamp from which the streamcopied streams should start,
     // in AV_TIME_BASE_Q;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index c9fd65e902..f48ae83a40 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -176,6 +176,18 @@ static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
     av_bprint_chars(bprint, ':', 1);
 }
 
+static OutputFilter *ofilter_alloc(FilterGraph *fg)
+{
+    OutputFilter *ofilter;
+
+    ofilter           = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
+    ofilter->graph    = fg;
+    ofilter->format   = -1;
+    ofilter->last_pts = AV_NOPTS_VALUE;
+
+    return ofilter;
+}
+
 int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
 {
     FilterGraph *fg = av_mallocz(sizeof(*fg));
@@ -186,10 +198,8 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
         report_and_exit(AVERROR(ENOMEM));
     fg->index = nb_filtergraphs;
 
-    ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
-    ofilter->ost    = ost;
-    ofilter->graph  = fg;
-    ofilter->format = -1;
+    ofilter      = ofilter_alloc(fg);
+    ofilter->ost = ost;
 
     ost->filter = ofilter;
 
@@ -502,9 +512,8 @@ int init_complex_filtergraph(FilterGraph *fg)
         init_input_filter(fg, cur);
 
     for (cur = outputs; cur;) {
-        OutputFilter *const ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
+        OutputFilter *const ofilter = ofilter_alloc(fg);
 
-        ofilter->graph   = fg;
         ofilter->out_tmp = cur;
         ofilter->type    = avfilter_pad_get_type(cur->filter_ctx->output_pads,
                                                                          cur->pad_idx);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index ee5829c7fe..3490c99c94 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -649,7 +649,6 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o,
         ost->ist->st->discard = ost->ist->user_set_discard;
     }
     ost->last_mux_dts = AV_NOPTS_VALUE;
-    ost->last_filter_pts = AV_NOPTS_VALUE;
 
     MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i,
                          ost->copy_initial_nonkeyframes, oc, st);
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 06/29] fftools/ffmpeg_enc: replace abort() with av_assert0(0)
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (3 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 05/29] fftools/ffmpeg: move OutputStream.last_filter_pts to OutputFilter Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 07/29] fftools/ffmpeg: drop a useless goto Anton Khirnov
                   ` (23 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

This is consistent with the treatment of other unreachable paths.
---
 fftools/ffmpeg_enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 7f6bd76f10..2aaef806f6 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -306,7 +306,7 @@ int enc_open(OutputStream *ost, AVFrame *frame)
 
         break;
     default:
-        abort();
+        av_assert0(0);
         break;
     }
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 07/29] fftools/ffmpeg: drop a useless goto
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (4 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 06/29] fftools/ffmpeg_enc: replace abort() with av_assert0(0) Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 08/29] fftools/ffmpeg: move the hw_device_free_all() call to ffmpeg_cleanup() Anton Khirnov
                   ` (22 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

There is no cleanup in transcode(), can return an error directly.
---
 fftools/ffmpeg.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1f50b82794..1cd9a8f29f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2905,7 +2905,7 @@ static int transcode(void)
 
     ret = transcode_init();
     if (ret < 0)
-        goto fail;
+        return ret;
 
     if (stdin_interaction) {
         av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n");
@@ -2975,11 +2975,7 @@ static int transcode(void)
 
     hw_device_free_all();
 
-    /* finished ! */
-    ret = 0;
-
- fail:
-    return ret;
+    return 0;
 }
 
 static BenchmarkTimeStamps get_benchmark_time_stamps(void)
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 08/29] fftools/ffmpeg: move the hw_device_free_all() call to ffmpeg_cleanup()
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (5 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 07/29] fftools/ffmpeg: drop a useless goto Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 09/29] fftools/ffmpeg: eliminate the main_return_code global Anton Khirnov
                   ` (21 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

Frees devices on failure as well as success.
---
 fftools/ffmpeg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1cd9a8f29f..816b6c4b08 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -551,6 +551,8 @@ static void ffmpeg_cleanup(int ret)
     av_freep(&vstats_filename);
     of_enc_stats_close();
 
+    hw_device_free_all();
+
     av_freep(&filter_nbthreads);
 
     av_freep(&input_files);
@@ -2973,8 +2975,6 @@ static int transcode(void)
         exit_program(1);
     }
 
-    hw_device_free_all();
-
     return 0;
 }
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 09/29] fftools/ffmpeg: eliminate the main_return_code global
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (6 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 08/29] fftools/ffmpeg: move the hw_device_free_all() call to ffmpeg_cleanup() Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 10/29] fftools/ffmpeg: factorize checking whether any output was written Anton Khirnov
                   ` (20 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

Properly pass muxing return codes through the call stack instead.
Slightly changes behavior in case of errors:
* the output IO stream is closed even if writing the trailer returns an
  error, which should be more correct
* all files get properly closed with -xerror, even if one of them fails
---
 fftools/ffmpeg.c     | 18 ++++++++----------
 fftools/ffmpeg.h     | 12 +++++++++++-
 fftools/ffmpeg_mux.c | 12 +++++-------
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 816b6c4b08..7431482acc 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -318,7 +318,6 @@ static volatile int received_sigterm = 0;
 static volatile int received_nb_signals = 0;
 static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0);
 static volatile int ffmpeg_exited = 0;
-int main_return_code = 0;
 static int64_t copy_ts_first_pts = AV_NOPTS_VALUE;
 
 static void
@@ -2951,9 +2950,8 @@ static int transcode(void)
 
     /* write the trailer if needed */
     for (i = 0; i < nb_output_files; i++) {
-        ret = of_write_trailer(output_files[i]);
-        if (ret < 0 && exit_on_error)
-            exit_program(1);
+        int err = of_write_trailer(output_files[i]);
+        ret = err_merge(ret, err);
     }
 
     /* dump report by using the first video and audio streams */
@@ -2975,7 +2973,7 @@ static int transcode(void)
         exit_program(1);
     }
 
-    return 0;
+    return ret;
 }
 
 static BenchmarkTimeStamps get_benchmark_time_stamps(void)
@@ -3061,9 +3059,8 @@ int main(int argc, char **argv)
     }
 
     current_time = ti = get_benchmark_time_stamps();
-    if (transcode() < 0)
-        exit_program(1);
-    if (do_benchmark) {
+    ret = transcode();
+    if (ret >= 0 && do_benchmark) {
         int64_t utime, stime, rtime;
         current_time = get_benchmark_time_stamps();
         utime = current_time.user_usec - ti.user_usec;
@@ -3078,6 +3075,7 @@ int main(int argc, char **argv)
     if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1])
         exit_program(69);
 
-    exit_program(received_nb_signals ? 255 : main_return_code);
-    return main_return_code;
+    ret = received_nb_signals ? 255 : ret;
+    exit_program(ret);
+    return ret;
 }
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 84ce017320..ddfeeabf75 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -756,7 +756,6 @@ extern const OptionDef options[];
 extern HWDevice *filter_hw_device;
 
 extern unsigned nb_output_dumped;
-extern int main_return_code;
 
 extern int ignore_unknown_streams;
 extern int copy_unknown_streams;
@@ -887,6 +886,17 @@ void close_output_stream(OutputStream *ost);
 int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt);
 void update_benchmark(const char *fmt, ...);
 
+/**
+ * Merge two return codes - return one of the error codes if at least one of
+ * them was negative, 0 otherwise.
+ * Currently just picks the first one, eventually we might want to do something
+ * more sophisticated, like sorting them by priority.
+ */
+static inline int err_merge(int err0, int err1)
+{
+    return (err0 < 0) ? err0 : FFMIN(err1, 0);
+}
+
 #define SPECIFIER_OPT_FMT_str  "%s"
 #define SPECIFIER_OPT_FMT_i    "%i"
 #define SPECIFIER_OPT_FMT_i64  "%"PRId64
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 5663b8f11d..c2b7993e66 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -602,7 +602,7 @@ int of_write_trailer(OutputFile *of)
 {
     Muxer *mux = mux_from_of(of);
     AVFormatContext *fc = mux->fc;
-    int ret;
+    int ret, mux_result = 0;
 
     if (!mux->tq) {
         av_log(mux, AV_LOG_ERROR,
@@ -611,14 +611,12 @@ int of_write_trailer(OutputFile *of)
         return AVERROR(EINVAL);
     }
 
-    ret = thread_stop(mux);
-    if (ret < 0)
-        main_return_code = ret;
+    mux_result = thread_stop(mux);
 
     ret = av_write_trailer(fc);
     if (ret < 0) {
         av_log(mux, AV_LOG_ERROR, "Error writing trailer: %s\n", av_err2str(ret));
-        return ret;
+        mux_result = err_merge(mux_result, ret);
     }
 
     mux->last_filesize = filesize(fc->pb);
@@ -627,11 +625,11 @@ int of_write_trailer(OutputFile *of)
         ret = avio_closep(&fc->pb);
         if (ret < 0) {
             av_log(mux, AV_LOG_ERROR, "Error closing file: %s\n", av_err2str(ret));
-            return ret;
+            mux_result = err_merge(mux_result, ret);
         }
     }
 
-    return 0;
+    return mux_result;
 }
 
 static void ost_free(OutputStream **post)
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 10/29] fftools/ffmpeg: factorize checking whether any output was written
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (7 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 09/29] fftools/ffmpeg: eliminate the main_return_code global Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 11/29] fftools/ffmpeg: move printing verbose muxing stats to ffmpeg_mux Anton Khirnov
                   ` (19 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

This is currently done in two places:
* at the end of print_final_stats(), which merely prints a warning if
  the total size of all written packets is zero
* at the end of transcode() (under a misleading historical 'close each
  encoder' comment), which instead checks the packet count to implement
  -abort_on empty_output[_stream]

Consolidate both of these blocks into a single function called from
of_write_trailer(), which is a more appropriate place for this. Also,
return an error code rather than exit immediately, which ensures all
output files are properly closed.
---
 fftools/ffmpeg.c     | 30 ------------------------------
 fftools/ffmpeg_mux.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 30 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 7431482acc..48e771cbc5 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -745,7 +745,6 @@ static void print_final_stats(int64_t total_size)
     uint64_t data_size = 0;
     float percent = -1.0;
     int i, j;
-    int pass1_used = 1;
 
     for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
         AVCodecParameters *par = ost->st->codecpar;
@@ -759,10 +758,6 @@ static void print_final_stats(int64_t total_size)
         }
         extra_size += par->extradata_size;
         data_size  += s;
-        if (ost->enc_ctx &&
-            (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2))
-            != AV_CODEC_FLAG_PASS1)
-            pass1_used = 0;
     }
 
     if (data_size && total_size>0 && total_size >= data_size)
@@ -848,14 +843,6 @@ static void print_final_stats(int64_t total_size)
         av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
                total_packets, total_size);
     }
-    if(video_size + data_size + audio_size + subtitle_size + extra_size == 0){
-        av_log(NULL, AV_LOG_WARNING, "Output file is empty, nothing was encoded ");
-        if (pass1_used) {
-            av_log(NULL, AV_LOG_WARNING, "\n");
-        } else {
-            av_log(NULL, AV_LOG_WARNING, "(check -ss / -t / -frames parameters if used)\n");
-        }
-    }
 }
 
 static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
@@ -2902,7 +2889,6 @@ static int transcode(void)
     int ret, i;
     InputStream *ist;
     int64_t timer_start;
-    int64_t total_packets_written = 0;
 
     ret = transcode_init();
     if (ret < 0)
@@ -2957,22 +2943,6 @@ static int transcode(void)
     /* dump report by using the first video and audio streams */
     print_report(1, timer_start, av_gettime_relative());
 
-    /* close each encoder */
-    for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
-        uint64_t packets_written;
-        packets_written = atomic_load(&ost->packets_written);
-        total_packets_written += packets_written;
-        if (!packets_written && (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM)) {
-            av_log(ost, AV_LOG_FATAL, "Empty output\n");
-            exit_program(1);
-        }
-    }
-
-    if (!total_packets_written && (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT)) {
-        av_log(NULL, AV_LOG_FATAL, "Empty output\n");
-        exit_program(1);
-    }
-
     return ret;
 }
 
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index c2b7993e66..9a91861bd4 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -598,6 +598,45 @@ int of_stream_init(OutputFile *of, OutputStream *ost)
     return mux_check_init(mux);
 }
 
+static int check_written(OutputFile *of)
+{
+    int64_t total_packets_written = 0;
+    int pass1_used = 1;
+    int ret = 0;
+
+    for (int i = 0; i < of->nb_streams; i++) {
+        OutputStream *ost = of->streams[i];
+        uint64_t packets_written = atomic_load(&ost->packets_written);
+
+        total_packets_written += packets_written;
+
+        if (ost->enc_ctx &&
+            (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2))
+             != AV_CODEC_FLAG_PASS1)
+            pass1_used = 0;
+
+        if (!packets_written &&
+            (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM)) {
+            av_log(ost, AV_LOG_FATAL, "Empty output stream\n");
+            ret = err_merge(ret, AVERROR(EINVAL));
+        }
+    }
+
+    if (!total_packets_written) {
+        int level = AV_LOG_WARNING;
+
+        if (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT) {
+            ret = err_merge(ret, AVERROR(EINVAL));
+            level = AV_LOG_FATAL;
+        }
+
+        av_log(of, level, "Output file is empty, nothing was encoded%s\n",
+               pass1_used ? "" : "(check -ss / -t / -frames parameters if used)");
+    }
+
+    return ret;
+}
+
 int of_write_trailer(OutputFile *of)
 {
     Muxer *mux = mux_from_of(of);
@@ -629,6 +668,10 @@ int of_write_trailer(OutputFile *of)
         }
     }
 
+    // check whether anything was actually written
+    ret = check_written(of);
+    mux_result = err_merge(mux_result, ret);
+
     return mux_result;
 }
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 11/29] fftools/ffmpeg: move printing verbose muxing stats to ffmpeg_mux
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (8 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 10/29] fftools/ffmpeg: factorize checking whether any output was written Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 12/29] fftools/ffmpeg_mux: reindent Anton Khirnov
                   ` (18 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

This is a more appropriate place for this.
---
 fftools/ffmpeg.c     | 34 ----------------------------------
 fftools/ffmpeg_mux.c | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 48e771cbc5..e1748114b3 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -809,40 +809,6 @@ static void print_final_stats(int64_t total_size)
         av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
                total_packets, total_size);
     }
-
-    for (i = 0; i < nb_output_files; i++) {
-        OutputFile *of = output_files[i];
-        uint64_t total_packets = 0, total_size = 0;
-
-        av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
-               i, of->url);
-
-        for (j = 0; j < of->nb_streams; j++) {
-            OutputStream *ost = of->streams[j];
-            enum AVMediaType type = ost->st->codecpar->codec_type;
-
-            total_size    += ost->data_size_mux;
-            total_packets += atomic_load(&ost->packets_written);
-
-            av_log(NULL, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
-                   i, j, av_get_media_type_string(type));
-            if (ost->enc_ctx) {
-                av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
-                       ost->frames_encoded);
-                if (type == AVMEDIA_TYPE_AUDIO)
-                    av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
-                av_log(NULL, AV_LOG_VERBOSE, "; ");
-            }
-
-            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
-                   atomic_load(&ost->packets_written), ost->data_size_mux);
-
-            av_log(NULL, AV_LOG_VERBOSE, "\n");
-        }
-
-        av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
-               total_packets, total_size);
-    }
 }
 
 static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 9a91861bd4..5acd3b9b9d 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -637,6 +637,41 @@ static int check_written(OutputFile *of)
     return ret;
 }
 
+static void mux_final_stats(Muxer *mux)
+{
+        OutputFile *of = &mux->of;
+        uint64_t total_packets = 0, total_size = 0;
+
+        av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
+               of->index, of->url);
+
+        for (int j = 0; j < of->nb_streams; j++) {
+            OutputStream *ost = of->streams[j];
+            enum AVMediaType type = ost->st->codecpar->codec_type;
+
+            total_size    += ost->data_size_mux;
+            total_packets += atomic_load(&ost->packets_written);
+
+            av_log(NULL, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
+                   of->index, j, av_get_media_type_string(type));
+            if (ost->enc_ctx) {
+                av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
+                       ost->frames_encoded);
+                if (type == AVMEDIA_TYPE_AUDIO)
+                    av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
+                av_log(NULL, AV_LOG_VERBOSE, "; ");
+            }
+
+            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
+                   atomic_load(&ost->packets_written), ost->data_size_mux);
+
+            av_log(NULL, AV_LOG_VERBOSE, "\n");
+        }
+
+        av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
+               total_packets, total_size);
+}
+
 int of_write_trailer(OutputFile *of)
 {
     Muxer *mux = mux_from_of(of);
@@ -668,6 +703,8 @@ int of_write_trailer(OutputFile *of)
         }
     }
 
+    mux_final_stats(mux);
+
     // check whether anything was actually written
     ret = check_written(of);
     mux_result = err_merge(mux_result, ret);
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 12/29] fftools/ffmpeg_mux: reindent
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (9 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 11/29] fftools/ffmpeg: move printing verbose muxing stats to ffmpeg_mux Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 13/29] fftools/ffmpeg_mux: log final stats to muxer context Anton Khirnov
                   ` (17 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_mux.c | 56 ++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 5acd3b9b9d..f3a3a9b7a2 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -639,37 +639,37 @@ static int check_written(OutputFile *of)
 
 static void mux_final_stats(Muxer *mux)
 {
-        OutputFile *of = &mux->of;
-        uint64_t total_packets = 0, total_size = 0;
-
-        av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
-               of->index, of->url);
-
-        for (int j = 0; j < of->nb_streams; j++) {
-            OutputStream *ost = of->streams[j];
-            enum AVMediaType type = ost->st->codecpar->codec_type;
-
-            total_size    += ost->data_size_mux;
-            total_packets += atomic_load(&ost->packets_written);
-
-            av_log(NULL, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
-                   of->index, j, av_get_media_type_string(type));
-            if (ost->enc_ctx) {
-                av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
-                       ost->frames_encoded);
-                if (type == AVMEDIA_TYPE_AUDIO)
-                    av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
-                av_log(NULL, AV_LOG_VERBOSE, "; ");
-            }
+    OutputFile *of = &mux->of;
+    uint64_t total_packets = 0, total_size = 0;
+
+    av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
+           of->index, of->url);
+
+    for (int j = 0; j < of->nb_streams; j++) {
+        OutputStream *ost = of->streams[j];
+        enum AVMediaType type = ost->st->codecpar->codec_type;
+
+        total_size    += ost->data_size_mux;
+        total_packets += atomic_load(&ost->packets_written);
+
+        av_log(NULL, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
+               of->index, j, av_get_media_type_string(type));
+        if (ost->enc_ctx) {
+            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
+                   ost->frames_encoded);
+            if (type == AVMEDIA_TYPE_AUDIO)
+                av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
+            av_log(NULL, AV_LOG_VERBOSE, "; ");
+        }
 
-            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
-                   atomic_load(&ost->packets_written), ost->data_size_mux);
+        av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
+               atomic_load(&ost->packets_written), ost->data_size_mux);
 
-            av_log(NULL, AV_LOG_VERBOSE, "\n");
-        }
+        av_log(NULL, AV_LOG_VERBOSE, "\n");
+    }
 
-        av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
-               total_packets, total_size);
+    av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
+           total_packets, total_size);
 }
 
 int of_write_trailer(OutputFile *of)
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 13/29] fftools/ffmpeg_mux: log final stats to muxer context
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (10 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 12/29] fftools/ffmpeg_mux: reindent Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 14/29] fftools/ffmpeg: rewrite printing the final output sizes Anton Khirnov
                   ` (16 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_mux.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index f3a3a9b7a2..441f1cd3a7 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -642,7 +642,7 @@ static void mux_final_stats(Muxer *mux)
     OutputFile *of = &mux->of;
     uint64_t total_packets = 0, total_size = 0;
 
-    av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
+    av_log(of, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
            of->index, of->url);
 
     for (int j = 0; j < of->nb_streams; j++) {
@@ -652,23 +652,23 @@ static void mux_final_stats(Muxer *mux)
         total_size    += ost->data_size_mux;
         total_packets += atomic_load(&ost->packets_written);
 
-        av_log(NULL, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
+        av_log(of, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
                of->index, j, av_get_media_type_string(type));
         if (ost->enc_ctx) {
-            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
+            av_log(of, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
                    ost->frames_encoded);
             if (type == AVMEDIA_TYPE_AUDIO)
-                av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
-            av_log(NULL, AV_LOG_VERBOSE, "; ");
+                av_log(of, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
+            av_log(of, AV_LOG_VERBOSE, "; ");
         }
 
-        av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
+        av_log(of, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
                atomic_load(&ost->packets_written), ost->data_size_mux);
 
-        av_log(NULL, AV_LOG_VERBOSE, "\n");
+        av_log(of, AV_LOG_VERBOSE, "\n");
     }
 
-    av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
+    av_log(of, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
            total_packets, total_size);
 }
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 14/29] fftools/ffmpeg: rewrite printing the final output sizes
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (11 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 13/29] fftools/ffmpeg_mux: log final stats to muxer context Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 15/29] fftools/ffmpeg_mux: make data_size_mux private to ffmpeg_mux Anton Khirnov
                   ` (15 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

Current code in print_final_stats(), printing the final summary such as
  video:8851kB audio:548kB subtitle:0kB other streams:0kB global headers:20kB muxing overhead: 0.559521%
was written with a single output file in mind and makes very little
sense otherwise.

Print this information in mux_final_stats() instead, one line per output
file. Use the correct filesize, if available.
---
 fftools/ffmpeg.c     | 37 ++-----------------------------------
 fftools/ffmpeg_mux.c | 36 +++++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index e1748114b3..0a2dc85629 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -738,43 +738,10 @@ static int reap_filters(int flush)
     return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats(void)
 {
-    uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
-    uint64_t subtitle_size = 0;
-    uint64_t data_size = 0;
-    float percent = -1.0;
     int i, j;
 
-    for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
-        AVCodecParameters *par = ost->st->codecpar;
-        const uint64_t s = ost->data_size_mux;
-
-        switch (par->codec_type) {
-            case AVMEDIA_TYPE_VIDEO:    video_size    += s; break;
-            case AVMEDIA_TYPE_AUDIO:    audio_size    += s; break;
-            case AVMEDIA_TYPE_SUBTITLE: subtitle_size += s; break;
-            default:                    other_size    += s; break;
-        }
-        extra_size += par->extradata_size;
-        data_size  += s;
-    }
-
-    if (data_size && total_size>0 && total_size >= data_size)
-        percent = 100.0 * (total_size - data_size) / data_size;
-
-    av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ",
-           video_size / 1024.0,
-           audio_size / 1024.0,
-           subtitle_size / 1024.0,
-           other_size / 1024.0,
-           extra_size / 1024.0);
-    if (percent >= 0.0)
-        av_log(NULL, AV_LOG_INFO, "%f%%", percent);
-    else
-        av_log(NULL, AV_LOG_INFO, "unknown");
-    av_log(NULL, AV_LOG_INFO, "\n");
-
     /* print verbose per-stream stats */
     for (i = 0; i < nb_input_files; i++) {
         InputFile *f = input_files[i];
@@ -1005,7 +972,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
     first_report = 0;
 
     if (is_last_report)
-        print_final_stats(total_size);
+        print_final_stats();
 }
 
 int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par)
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 441f1cd3a7..01a11117a9 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -641,15 +641,30 @@ static void mux_final_stats(Muxer *mux)
 {
     OutputFile *of = &mux->of;
     uint64_t total_packets = 0, total_size = 0;
+    uint64_t video_size = 0, audio_size = 0, subtitle_size = 0,
+             extra_size = 0, other_size = 0;
+
+    uint8_t overhead[16] = "unknown";
+    int64_t file_size = of_filesize(of);
 
     av_log(of, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
            of->index, of->url);
 
     for (int j = 0; j < of->nb_streams; j++) {
         OutputStream *ost = of->streams[j];
-        enum AVMediaType type = ost->st->codecpar->codec_type;
+        const AVCodecParameters *par = ost->st->codecpar;
+        const  enum AVMediaType type = par->codec_type;
+        const uint64_t s = ost->data_size_mux;
+
+        switch (type) {
+        case AVMEDIA_TYPE_VIDEO:    video_size    += s; break;
+        case AVMEDIA_TYPE_AUDIO:    audio_size    += s; break;
+        case AVMEDIA_TYPE_SUBTITLE: subtitle_size += s; break;
+        default:                    other_size    += s; break;
+        }
 
-        total_size    += ost->data_size_mux;
+        extra_size    += par->extradata_size;
+        total_size    += s;
         total_packets += atomic_load(&ost->packets_written);
 
         av_log(of, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
@@ -663,13 +678,28 @@ static void mux_final_stats(Muxer *mux)
         }
 
         av_log(of, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
-               atomic_load(&ost->packets_written), ost->data_size_mux);
+               atomic_load(&ost->packets_written), s);
 
         av_log(of, AV_LOG_VERBOSE, "\n");
     }
 
     av_log(of, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
            total_packets, total_size);
+
+    if (total_size && file_size > 0 && file_size >= total_size) {
+        snprintf(overhead, sizeof(overhead), "%f%%",
+                 100.0 * (file_size - total_size) / total_size);
+    }
+
+    av_log(of, AV_LOG_INFO,
+           "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB other streams:%1.0fkB "
+           "global headers:%1.0fkB muxing overhead: %s\n",
+           video_size    / 1024.0,
+           audio_size    / 1024.0,
+           subtitle_size / 1024.0,
+           other_size    / 1024.0,
+           extra_size    / 1024.0,
+           overhead);
 }
 
 int of_write_trailer(OutputFile *of)
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 15/29] fftools/ffmpeg_mux: make data_size_mux private to ffmpeg_mux
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (12 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 14/29] fftools/ffmpeg: rewrite printing the final output sizes Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 16/29] fftools/ffmpeg: move printing verbose demuxing stats to ffmpeg_demux Anton Khirnov
                   ` (14 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

It is no longer used outside of this file.
---
 fftools/ffmpeg.h     | 2 --
 fftools/ffmpeg_mux.c | 5 +++--
 fftools/ffmpeg_mux.h | 3 +++
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ddfeeabf75..bbcbf1aa80 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -649,8 +649,6 @@ typedef struct OutputStream {
     int keep_pix_fmt;
 
     /* stats */
-    // combined size of all the packets sent to the muxer
-    uint64_t data_size_mux;
     // combined size of all the packets received from the encoder
     uint64_t data_size_enc;
     // number of packets send to the muxer
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 01a11117a9..b316925115 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -128,7 +128,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
     }
     ms->last_mux_dts = pkt->dts;
 
-    ost->data_size_mux += pkt->size;
+    ms->data_size_mux += pkt->size;
     frame_num = atomic_fetch_add(&ost->packets_written, 1);
 
     pkt->stream_index = ost->index;
@@ -652,9 +652,10 @@ static void mux_final_stats(Muxer *mux)
 
     for (int j = 0; j < of->nb_streams; j++) {
         OutputStream *ost = of->streams[j];
+        MuxStream     *ms = ms_from_ost(ost);
         const AVCodecParameters *par = ost->st->codecpar;
         const  enum AVMediaType type = par->codec_type;
-        const uint64_t s = ost->data_size_mux;
+        const uint64_t s = ms->data_size_mux;
 
         switch (type) {
         case AVMEDIA_TYPE_VIDEO:    video_size    += s; break;
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index c76dc2e524..3fab74b2ed 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -63,6 +63,9 @@ typedef struct MuxStream {
     /* dts of the last packet sent to the muxer, in the stream timebase
      * used for making up missing dts values */
     int64_t last_mux_dts;
+
+    // combined size of all the packets sent to the muxer
+    uint64_t data_size_mux;
 } MuxStream;
 
 typedef struct Muxer {
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 16/29] fftools/ffmpeg: move printing verbose demuxing stats to ffmpeg_demux
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (13 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 15/29] fftools/ffmpeg_mux: make data_size_mux private to ffmpeg_mux Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 17/29] fftools/ffmpeg_demux: reindent Anton Khirnov
                   ` (13 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

This is a more appropriate place for this.
---
 fftools/ffmpeg.c       | 43 ------------------------------------------
 fftools/ffmpeg_demux.c | 38 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0a2dc85629..02a7f20554 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -738,46 +738,6 @@ static int reap_filters(int flush)
     return 0;
 }
 
-static void print_final_stats(void)
-{
-    int i, j;
-
-    /* print verbose per-stream stats */
-    for (i = 0; i < nb_input_files; i++) {
-        InputFile *f = input_files[i];
-        uint64_t total_packets = 0, total_size = 0;
-
-        av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
-               i, f->ctx->url);
-
-        for (j = 0; j < f->nb_streams; j++) {
-            InputStream *ist = f->streams[j];
-            enum AVMediaType type = ist->par->codec_type;
-
-            total_size    += ist->data_size;
-            total_packets += ist->nb_packets;
-
-            av_log(NULL, AV_LOG_VERBOSE, "  Input stream #%d:%d (%s): ",
-                   i, j, av_get_media_type_string(type));
-            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
-                   ist->nb_packets, ist->data_size);
-
-            if (ist->decoding_needed) {
-                av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
-                       ist->frames_decoded);
-                if (type == AVMEDIA_TYPE_AUDIO)
-                    av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
-                av_log(NULL, AV_LOG_VERBOSE, "; ");
-            }
-
-            av_log(NULL, AV_LOG_VERBOSE, "\n");
-        }
-
-        av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
-               total_packets, total_size);
-    }
-}
-
 static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
 {
     AVBPrint buf, buf_script;
@@ -970,9 +930,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
     }
 
     first_report = 0;
-
-    if (is_last_report)
-        print_final_stats();
 }
 
 int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par)
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 354d3165c9..8fafbc3354 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -480,6 +480,41 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
     return 0;
 }
 
+static void demux_final_stats(Demuxer *d)
+{
+        InputFile *f = &d->f;
+        uint64_t total_packets = 0, total_size = 0;
+
+        av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
+               f->index, f->ctx->url);
+
+        for (int j = 0; j < f->nb_streams; j++) {
+            InputStream *ist = f->streams[j];
+            enum AVMediaType type = ist->par->codec_type;
+
+            total_size    += ist->data_size;
+            total_packets += ist->nb_packets;
+
+            av_log(NULL, AV_LOG_VERBOSE, "  Input stream #%d:%d (%s): ",
+                   f->index, j, av_get_media_type_string(type));
+            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
+                   ist->nb_packets, ist->data_size);
+
+            if (ist->decoding_needed) {
+                av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
+                       ist->frames_decoded);
+                if (type == AVMEDIA_TYPE_AUDIO)
+                    av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
+                av_log(NULL, AV_LOG_VERBOSE, "; ");
+            }
+
+            av_log(NULL, AV_LOG_VERBOSE, "\n");
+        }
+
+        av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
+               total_packets, total_size);
+}
+
 static void ist_free(InputStream **pist)
 {
     InputStream *ist = *pist;
@@ -512,6 +547,9 @@ void ifile_close(InputFile **pf)
 
     thread_stop(d);
 
+    if (f->ctx)
+        demux_final_stats(d);
+
     for (int i = 0; i < f->nb_streams; i++)
         ist_free(&f->streams[i]);
     av_freep(&f->streams);
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 17/29] fftools/ffmpeg_demux: reindent
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (14 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 16/29] fftools/ffmpeg: move printing verbose demuxing stats to ffmpeg_demux Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 18/29] fftools/ffmpeg_demux: log final stats to demuxer context Anton Khirnov
                   ` (12 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_demux.c | 52 +++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 8fafbc3354..a2bfd0ab95 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -482,37 +482,37 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
 
 static void demux_final_stats(Demuxer *d)
 {
-        InputFile *f = &d->f;
-        uint64_t total_packets = 0, total_size = 0;
+    InputFile *f = &d->f;
+    uint64_t total_packets = 0, total_size = 0;
 
-        av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
-               f->index, f->ctx->url);
+    av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
+           f->index, f->ctx->url);
 
-        for (int j = 0; j < f->nb_streams; j++) {
-            InputStream *ist = f->streams[j];
-            enum AVMediaType type = ist->par->codec_type;
-
-            total_size    += ist->data_size;
-            total_packets += ist->nb_packets;
-
-            av_log(NULL, AV_LOG_VERBOSE, "  Input stream #%d:%d (%s): ",
-                   f->index, j, av_get_media_type_string(type));
-            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
-                   ist->nb_packets, ist->data_size);
-
-            if (ist->decoding_needed) {
-                av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
-                       ist->frames_decoded);
-                if (type == AVMEDIA_TYPE_AUDIO)
-                    av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
-                av_log(NULL, AV_LOG_VERBOSE, "; ");
-            }
+    for (int j = 0; j < f->nb_streams; j++) {
+        InputStream *ist = f->streams[j];
+        enum AVMediaType type = ist->par->codec_type;
+
+        total_size    += ist->data_size;
+        total_packets += ist->nb_packets;
 
-            av_log(NULL, AV_LOG_VERBOSE, "\n");
+        av_log(NULL, AV_LOG_VERBOSE, "  Input stream #%d:%d (%s): ",
+               f->index, j, av_get_media_type_string(type));
+        av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
+               ist->nb_packets, ist->data_size);
+
+        if (ist->decoding_needed) {
+            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
+                   ist->frames_decoded);
+            if (type == AVMEDIA_TYPE_AUDIO)
+                av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
+            av_log(NULL, AV_LOG_VERBOSE, "; ");
         }
 
-        av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
-               total_packets, total_size);
+        av_log(NULL, AV_LOG_VERBOSE, "\n");
+    }
+
+    av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
+           total_packets, total_size);
 }
 
 static void ist_free(InputStream **pist)
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 18/29] fftools/ffmpeg_demux: log final stats to demuxer context
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (15 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 17/29] fftools/ffmpeg_demux: reindent Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 19/29] fftools/ffmpeg: disable and deprecate -qphist Anton Khirnov
                   ` (11 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_demux.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index a2bfd0ab95..93eed28809 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -485,7 +485,7 @@ static void demux_final_stats(Demuxer *d)
     InputFile *f = &d->f;
     uint64_t total_packets = 0, total_size = 0;
 
-    av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
+    av_log(f, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
            f->index, f->ctx->url);
 
     for (int j = 0; j < f->nb_streams; j++) {
@@ -495,23 +495,23 @@ static void demux_final_stats(Demuxer *d)
         total_size    += ist->data_size;
         total_packets += ist->nb_packets;
 
-        av_log(NULL, AV_LOG_VERBOSE, "  Input stream #%d:%d (%s): ",
+        av_log(f, AV_LOG_VERBOSE, "  Input stream #%d:%d (%s): ",
                f->index, j, av_get_media_type_string(type));
-        av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
+        av_log(f, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
                ist->nb_packets, ist->data_size);
 
         if (ist->decoding_needed) {
-            av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
+            av_log(f, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
                    ist->frames_decoded);
             if (type == AVMEDIA_TYPE_AUDIO)
-                av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
-            av_log(NULL, AV_LOG_VERBOSE, "; ");
+                av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
+            av_log(f, AV_LOG_VERBOSE, "; ");
         }
 
-        av_log(NULL, AV_LOG_VERBOSE, "\n");
+        av_log(f, AV_LOG_VERBOSE, "\n");
     }
 
-    av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
+    av_log(f, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
            total_packets, total_size);
 }
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 19/29] fftools/ffmpeg: disable and deprecate -qphist
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (16 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 18/29] fftools/ffmpeg_demux: log final stats to demuxer context Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 20/29] fftools/ffmpeg_filter: stop setting encoder channel layout unnecessarily Anton Khirnov
                   ` (10 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

This option adds a long string of numbers to the progress line, where
i-th number contains the base-2 logarithm of the number of times a frame
with this QP value was seen by print_report().

There are multiple problems with this feature:
* despite this existing since 2005, web search shows no indication
  that it was ever useful for any meaningful purpose;
* the format of what is printed is entirely undocumented, one has to
  find it out from the source code;
* QP values above 31 are silently ignored;
* it only works with one video stream;
* as it relies on global state, it is in conflict with ongoing
  architectural changes.

It then seems that the nontrivial cost of maintaining this option is not
worth its negligible (or possibly negative - since it pollutes the
already large option space) value.
Users who really need similar functionality can also implement it
themselves using -vstats.
---
 doc/ffmpeg.texi      |  2 --
 fftools/ffmpeg.c     | 10 ----------
 fftools/ffmpeg.h     |  2 +-
 fftools/ffmpeg_opt.c | 15 ++++++++++++---
 4 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index d433d60ce9..cb8aa13df2 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1051,8 +1051,6 @@ Specify which version of the vstats format to use. Default is @code{2}. See the
 top=1/bottom=0/auto=-1 field first
 @item -vtag @var{fourcc/tag} (@emph{output})
 Force video tag/fourcc. This is an alias for @code{-tag:v}.
-@item -qphist (@emph{global})
-Show QP histogram
 @item -vbsf @var{bitstream_filter}
 Deprecated see -bsf
 
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 02a7f20554..74aba28a9b 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -748,7 +748,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
     int64_t pts = INT64_MIN + 1;
     static int64_t last_time = -1;
     static int first_report = 1;
-    static int qp_histogram[52];
     int hours, mins, secs, us;
     const char *hours_sign;
     int ret;
@@ -794,14 +793,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
                        ost->file_index, ost->index, q);
             if (is_last_report)
                 av_bprintf(&buf, "L");
-            if (qp_hist) {
-                int j;
-                int qp = lrintf(q);
-                if (qp >= 0 && qp < FF_ARRAY_ELEMS(qp_histogram))
-                    qp_histogram[qp]++;
-                for (j = 0; j < 32; j++)
-                    av_bprintf(&buf, "%X", av_log2(qp_histogram[j] + 1));
-            }
 
             if (enc && (enc->flags & AV_CODEC_FLAG_PSNR) &&
                 (ost->pict_type != AV_PICTURE_TYPE_NONE || is_last_report)) {
@@ -2321,7 +2312,6 @@ static int check_keyboard_interaction(int64_t cur_time)
     }
     if (key == '+') av_log_set_level(av_log_get_level()+10);
     if (key == '-') av_log_set_level(av_log_get_level()-10);
-    if (key == 's') qp_hist     ^= 1;
     if (key == 'c' || key == 'C'){
         char buf[4096], target[64], command[256], arg[256] = {0};
         double time;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index bbcbf1aa80..80a1192ed0 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -54,6 +54,7 @@
 #define FFMPEG_OPT_MAP_CHANNEL 1
 #define FFMPEG_OPT_MAP_SYNC 1
 #define FFMPEG_ROTATION_METADATA 1
+#define FFMPEG_OPT_QPHIST 1
 
 enum VideoSyncMethod {
     VSYNC_AUTO = -1,
@@ -738,7 +739,6 @@ extern int exit_on_error;
 extern int abort_on_flags;
 extern int print_stats;
 extern int64_t stats_period;
-extern int qp_hist;
 extern int stdin_interaction;
 extern AVIOContext *progress_avio;
 extern float max_error_rate;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 055275d813..aa9aa0e9b4 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -80,7 +80,6 @@ int debug_ts          = 0;
 int exit_on_error     = 0;
 int abort_on_flags    = 0;
 int print_stats       = -1;
-int qp_hist           = 0;
 int stdin_interaction = 1;
 float max_error_rate  = 2.0/3;
 char *filter_nbthreads;
@@ -1344,6 +1343,14 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg)
     return 0;
 }
 
+#if FFMPEG_OPT_QPHIST
+static int opt_qphist(void *optctx, const char *opt, const char *arg)
+{
+    av_log(NULL, AV_LOG_WARNING, "Option -%s is deprecated and has no effect\n", opt);
+    return 0;
+}
+#endif
+
 #define OFFSET(x) offsetof(OptionsContext, x)
 const OptionDef options[] = {
     /* main options */
@@ -1627,8 +1634,10 @@ const OptionDef options[] = {
     { "vtag",         OPT_VIDEO | HAS_ARG | OPT_EXPERT  | OPT_PERFILE |
                       OPT_INPUT | OPT_OUTPUT,                                    { .func_arg = opt_old2new },
         "force video tag/fourcc", "fourcc/tag" },
-    { "qphist",       OPT_VIDEO | OPT_BOOL | OPT_EXPERT ,                        { &qp_hist },
-        "show QP histogram" },
+#if FFMPEG_OPT_QPHIST
+    { "qphist",       OPT_VIDEO | OPT_EXPERT ,                        { .func_arg = opt_qphist },
+        "deprecated, does nothing" },
+#endif
     { "fps_mode",     OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT |
                       OPT_SPEC | OPT_OUTPUT,                                     { .off = OFFSET(fps_mode) },
         "set framerate mode for matching video streams; overrides vsync" },
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 20/29] fftools/ffmpeg_filter: stop setting encoder channel layout unnecessarily
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (17 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 19/29] fftools/ffmpeg: disable and deprecate -qphist Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 21/29] fftools/ffmpeg_mux_init: print more meaningful error messages Anton Khirnov
                   ` (9 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

The channel layout is set before opening the encoder, in enc_open().
Messing with it in configure_output_audio_filter() cannot accomplish
anything meaningful.
---
 fftools/ffmpeg_filter.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index f48ae83a40..584f51ac3f 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -699,7 +699,6 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
 {
     OutputStream *ost = ofilter->ost;
     OutputFile    *of = output_files[ost->file_index];
-    AVCodecContext *codec  = ost->enc_ctx;
     AVFilterContext *last_filter = out->filter_ctx;
     int pad_idx = out->pad_idx;
     AVBPrint args;
@@ -750,9 +749,6 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
     }
 #endif
 
-    if (codec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
-        av_channel_layout_default(&codec->ch_layout, codec->ch_layout.nb_channels);
-
     choose_sample_fmts(ofilter,     &args);
     choose_sample_rates(ofilter,    &args);
     choose_channel_layouts(ofilter, &args);
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 21/29] fftools/ffmpeg_mux_init: print more meaningful error messages
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (18 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 20/29] fftools/ffmpeg_filter: stop setting encoder channel layout unnecessarily Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 22/29] fftools/ffmpeg: track a list of non-lavfi outputs in InputStream Anton Khirnov
                   ` (8 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_mux_init.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 3490c99c94..4b6c704046 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -2247,7 +2247,8 @@ int of_open(const OptionsContext *o, const char *filename)
 
     err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
     if (!oc) {
-        print_error(filename, err);
+        av_log(mux, AV_LOG_FATAL, "Error initializing the muxer for %s: %s\n",
+               filename, av_err2str(err));
         exit_program(1);
     }
     mux->fc = oc;
@@ -2334,11 +2335,12 @@ int of_open(const OptionsContext *o, const char *filename)
     }
 
     /* check filename in case of an image number is expected */
-    if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
-        if (!av_filename_number_test(oc->url)) {
-            print_error(oc->url, AVERROR(EINVAL));
-            exit_program(1);
-        }
+    if (oc->oformat->flags & AVFMT_NEEDNUMBER && !av_filename_number_test(oc->url)) {
+        av_log(mux, AV_LOG_FATAL,
+               "Output filename '%s' does not contain a numeric pattern like "
+               "'%%d', which is required by output format '%s'.\n",
+               oc->url, oc->oformat->name);
+        exit_program(1);
     }
 
     if (!(oc->oformat->flags & AVFMT_NOFILE)) {
@@ -2349,7 +2351,8 @@ int of_open(const OptionsContext *o, const char *filename)
         if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
                               &oc->interrupt_callback,
                               &mux->opts)) < 0) {
-            print_error(filename, err);
+            av_log(mux, AV_LOG_FATAL, "Error opening output %s: %s\n",
+                   filename, av_err2str(err));
             exit_program(1);
         }
     } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 22/29] fftools/ffmpeg: track a list of non-lavfi outputs in InputStream
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (19 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 21/29] fftools/ffmpeg_mux_init: print more meaningful error messages Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 23/29] fftools/ffmpeg: stop calling check_output_constraints() for streamcopy Anton Khirnov
                   ` (7 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

Currently, output streams where an input stream is sent directly (i.e.
not through lavfi) are determined by iterating over ALL the output
streams and skipping the irrelevant ones. This is awkward and
inefficient.
---
 fftools/ffmpeg.c          | 21 +++++++++------------
 fftools/ffmpeg.h          | 10 ++++++++++
 fftools/ffmpeg_demux.c    |  7 +++++++
 fftools/ffmpeg_mux_init.c |  3 +++
 4 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 74aba28a9b..f65ff879c7 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -948,9 +948,6 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost)
 {
     OutputFile *of = output_files[ost->file_index];
 
-    if (ost->ist != ist)
-        return 0;
-
     if (ost->finished & MUXER_FINISHED)
         return 0;
 
@@ -1468,7 +1465,8 @@ static int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_out
     if (!subtitle->num_rects)
         goto out;
 
-    for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
+    for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
+        OutputStream *ost = ist->outputs[oidx];
         if (!check_output_constraints(ist, ost) || !ost->enc_ctx
             || ost->enc_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE)
             continue;
@@ -1830,7 +1828,8 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
     } else if (!ist->decoding_needed)
         eof_reached = 1;
 
-    for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
+    for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
+        OutputStream *ost = ist->outputs[oidx];
         if (!check_output_constraints(ist, ost) || ost->enc_ctx ||
             (!pkt && no_eof))
             continue;
@@ -2577,13 +2576,11 @@ static int process_input(int file_index)
             }
 
             /* mark all outputs that don't go through lavfi as finished */
-            for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) {
-                if (ost->ist == ist &&
-                    (!ost->enc_ctx || ost->enc_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE)) {
-                    OutputFile *of = output_files[ost->file_index];
-                    close_output_stream(ost);
-                    of_output_packet(of, ost->pkt, ost, 1);
-                }
+            for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
+                OutputStream *ost = ist->outputs[oidx];
+                OutputFile    *of = output_files[ost->file_index];
+                close_output_stream(ost);
+                of_output_packet(of, ost->pkt, ost, 1);
             }
         }
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 80a1192ed0..aef2bbc0df 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -416,6 +416,14 @@ typedef struct InputStream {
     InputFilter **filters;
     int        nb_filters;
 
+    /*
+     * Output targets that do not go through lavfi, i.e. subtitles or
+     * streamcopy. Those two cases are distinguished by the OutputStream
+     * having an encoder or not.
+     */
+    struct OutputStream **outputs;
+    int                nb_outputs;
+
     int reinit_filters;
 
     /* hwaccel options */
@@ -867,6 +875,8 @@ void ifile_close(InputFile **f);
  */
 int ifile_get_packet(InputFile *f, AVPacket **pkt);
 
+void ist_output_add(InputStream *ist, OutputStream *ost);
+
 /* iterate over all input streams in all input files;
  * pass NULL to start iteration */
 InputStream *ist_iter(InputStream *prev);
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 93eed28809..f2da0826ad 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -528,6 +528,7 @@ static void ist_free(InputStream **pist)
     avsubtitle_free(&ist->prev_sub.subtitle);
     av_frame_free(&ist->sub2video.frame);
     av_freep(&ist->filters);
+    av_freep(&ist->outputs);
     av_freep(&ist->hwaccel_device);
     av_freep(&ist->dts_buffer);
 
@@ -559,6 +560,12 @@ void ifile_close(InputFile **pf)
     av_freep(pf);
 }
 
+void ist_output_add(InputStream *ist, OutputStream *ost)
+{
+    GROW_ARRAY(ist->outputs, ist->nb_outputs);
+    ist->outputs[ist->nb_outputs - 1] = ost;
+}
+
 static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
                                      enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
 
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 4b6c704046..62e5643a04 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -647,6 +647,9 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o,
     if (ost->ist) {
         ost->ist->discard = 0;
         ost->ist->st->discard = ost->ist->user_set_discard;
+
+        if (!(ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)))
+            ist_output_add(ost->ist, ost);
     }
     ost->last_mux_dts = AV_NOPTS_VALUE;
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 23/29] fftools/ffmpeg: stop calling check_output_constraints() for streamcopy
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (20 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 22/29] fftools/ffmpeg: track a list of non-lavfi outputs in InputStream Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 24/29] fftools/ffmpeg: inline check_output_constraints() into its only caller Anton Khirnov
                   ` (6 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

That function only contains two checks now - whether the muxer returned
EOF and whether the packet timestamp is before requested output start
time.

The first check is unnecessary, since the packet will just be rejected
by the muxer. The second check is better combined with a related check
directly in do_streamcopy().
---
 fftools/ffmpeg.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index f65ff879c7..44ead4e3bc 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -976,10 +976,14 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
         !ost->copy_initial_nonkeyframes)
         return;
 
-    if (!ost->streamcopy_started && !ost->copy_prior_start) {
-        if (pkt->pts == AV_NOPTS_VALUE ?
-            ist->pts < ost->ts_copy_start :
-            pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, ist->st->time_base))
+    if (!ost->streamcopy_started) {
+        if (!ost->copy_prior_start &&
+            (pkt->pts == AV_NOPTS_VALUE ?
+             ist->pts < ost->ts_copy_start :
+             pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, ist->st->time_base)))
+            return;
+
+        if (of->start_time != AV_NOPTS_VALUE && ist->pts < of->start_time)
             return;
     }
 
@@ -1830,8 +1834,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
 
     for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
         OutputStream *ost = ist->outputs[oidx];
-        if (!check_output_constraints(ist, ost) || ost->enc_ctx ||
-            (!pkt && no_eof))
+        if (ost->enc_ctx || (!pkt && no_eof))
             continue;
 
         do_streamcopy(ist, ost, pkt);
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 24/29] fftools/ffmpeg: inline check_output_constraints() into its only caller
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (21 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 23/29] fftools/ffmpeg: stop calling check_output_constraints() for streamcopy Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 25/29] fftools/ffmpeg_demux: set the timebase on demuxed packets Anton Khirnov
                   ` (5 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

Which is subtitle encoding. Also, check for AVSubtitle.pts rather than
InputStream.pts, since that is the more authoritative value and is
guaranteed to be valid.
---
 fftools/ffmpeg.c     | 19 +------------------
 fftools/ffmpeg_enc.c |  3 +++
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 44ead4e3bc..95e4044dc6 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -941,22 +941,6 @@ int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *pa
     return 0;
 }
 
-/*
- * Check whether a packet from ist should be written into ost at this time
- */
-static int check_output_constraints(InputStream *ist, OutputStream *ost)
-{
-    OutputFile *of = output_files[ost->file_index];
-
-    if (ost->finished & MUXER_FINISHED)
-        return 0;
-
-    if (of->start_time != AV_NOPTS_VALUE && ist->pts < of->start_time)
-        return 0;
-
-    return 1;
-}
-
 static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
 {
     OutputFile *of = output_files[ost->file_index];
@@ -1471,8 +1455,7 @@ static int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_out
 
     for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
         OutputStream *ost = ist->outputs[oidx];
-        if (!check_output_constraints(ist, ost) || !ost->enc_ctx
-            || ost->enc_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE)
+        if (!ost->enc_ctx || ost->enc_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE)
             continue;
 
         enc_subtitle(output_files[ost->file_index], ost, subtitle);
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 2aaef806f6..a0779c45ae 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -440,6 +440,9 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
             exit_program(1);
         return;
     }
+    if (ost->finished ||
+        (of->start_time != AV_NOPTS_VALUE && sub->pts < of->start_time))
+        return;
 
     enc = ost->enc_ctx;
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 25/29] fftools/ffmpeg_demux: set the timebase on demuxed packets
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (22 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 24/29] fftools/ffmpeg: inline check_output_constraints() into its only caller Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-12  2:49   ` James Almer
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 26/29] fftools/ffmpeg: use AVPacket.time_base to simplify do_streamcopy() Anton Khirnov
                   ` (4 subsequent siblings)
  28 siblings, 1 reply; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

Simplifies tracking what timebase are the timestamps in. Will be useful
in following commits.
---
 fftools/ffmpeg_demux.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index f2da0826ad..7ff57273c9 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -194,15 +194,17 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
     const int64_t start_time = ifile->start_time_effective;
     int64_t duration;
 
+    pkt->time_base = ist->st->time_base;
+
 #define SHOW_TS_DEBUG(tag_)                                             \
     if (debug_ts) {                                                     \
         av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s "       \
                "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
                tag_, ifile->index, pkt->stream_index,                   \
                av_get_media_type_string(ist->st->codecpar->codec_type), \
-               av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), \
-               av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), \
-               av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->st->time_base)); \
+               av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
+               av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
+               av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
     }
 
     SHOW_TS_DEBUG("demuxer");
@@ -211,7 +213,7 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
         ist->st->pts_wrap_bits < 64) {
         int64_t stime, stime2;
 
-        stime = av_rescale_q(start_time, AV_TIME_BASE_Q, ist->st->time_base);
+        stime = av_rescale_q(start_time, AV_TIME_BASE_Q, pkt->time_base);
         stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
         ist->wrap_correction_done = 1;
 
@@ -226,16 +228,16 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
     }
 
     if (pkt->dts != AV_NOPTS_VALUE)
-        pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
+        pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, pkt->time_base);
     if (pkt->pts != AV_NOPTS_VALUE)
-        pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
+        pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, pkt->time_base);
 
     if (pkt->pts != AV_NOPTS_VALUE)
         pkt->pts *= ds->ts_scale;
     if (pkt->dts != AV_NOPTS_VALUE)
         pkt->dts *= ds->ts_scale;
 
-    duration = av_rescale_q(d->duration, d->time_base, ist->st->time_base);
+    duration = av_rescale_q(d->duration, d->time_base, pkt->time_base);
     if (pkt->pts != AV_NOPTS_VALUE) {
         pkt->pts += duration;
         ds->max_pts = FFMAX(pkt->pts, ds->max_pts);
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 26/29] fftools/ffmpeg: use AVPacket.time_base to simplify do_streamcopy()
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (23 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 25/29] fftools/ffmpeg_demux: set the timebase on demuxed packets Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 27/29] fftools/ffmpeg: only set InputStream.next_pts for decoding Anton Khirnov
                   ` (3 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

Besides making the code shorter, this also reduces the use of
InputStream in this function and will allow not accessing it at all in
the future.
---
 fftools/ffmpeg.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 95e4044dc6..f905836af6 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -964,7 +964,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
         if (!ost->copy_prior_start &&
             (pkt->pts == AV_NOPTS_VALUE ?
              ist->pts < ost->ts_copy_start :
-             pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, ist->st->time_base)))
+             pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, pkt->time_base)))
             return;
 
         if (of->start_time != AV_NOPTS_VALUE && ist->pts < of->start_time)
@@ -995,7 +995,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
     opkt->time_base = ost->mux_timebase;
 
     if (pkt->pts != AV_NOPTS_VALUE)
-        opkt->pts = av_rescale_q(pkt->pts, ist->st->time_base, opkt->time_base) - ost_tb_start_time;
+        opkt->pts = av_rescale_q(pkt->pts, pkt->time_base, opkt->time_base) - ost_tb_start_time;
 
     if (pkt->dts == AV_NOPTS_VALUE) {
         opkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, opkt->time_base);
@@ -1003,16 +1003,16 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
         int duration = av_get_audio_frame_duration2(ist->par, pkt->size);
         if(!duration)
             duration = ist->par->frame_size;
-        opkt->dts = av_rescale_delta(ist->st->time_base, pkt->dts,
+        opkt->dts = av_rescale_delta(pkt->time_base, pkt->dts,
                                     (AVRational){1, ist->par->sample_rate}, duration,
                                     &ist->filter_in_rescale_delta_last, opkt->time_base);
         /* dts will be set immediately afterwards to what pts is now */
         opkt->pts = opkt->dts - ost_tb_start_time;
     } else
-        opkt->dts = av_rescale_q(pkt->dts, ist->st->time_base, opkt->time_base);
+        opkt->dts = av_rescale_q(pkt->dts, pkt->time_base, opkt->time_base);
     opkt->dts -= ost_tb_start_time;
 
-    opkt->duration = av_rescale_q(pkt->duration, ist->st->time_base, opkt->time_base);
+    opkt->duration = av_rescale_q(pkt->duration, pkt->time_base, opkt->time_base);
 
     {
         int ret = trigger_fix_sub_duration_heartbeat(ost, pkt);
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 27/29] fftools/ffmpeg: only set InputStream.next_pts for decoding
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (24 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 26/29] fftools/ffmpeg: use AVPacket.time_base to simplify do_streamcopy() Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 28/29] fftools/ffmpeg: move checking for input -t out of do_streamcopy() Anton Khirnov
                   ` (2 subsequent siblings)
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

It is write-only for streamcopy.
---
 fftools/ffmpeg.c | 3 +--
 fftools/ffmpeg.h | 3 ++-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index f905836af6..4d4083d474 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1670,7 +1670,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
     if (pkt && pkt->dts != AV_NOPTS_VALUE) {
         ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
         if (par->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed)
-            ist->next_pts = ist->pts = ist->dts;
+            ist->pts = ist->dts;
     }
 
     // while we have more to decode or while the decoder did output something on EOF
@@ -1811,7 +1811,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
             break;
         }
         ist->pts = ist->dts;
-        ist->next_pts = ist->next_dts;
     } else if (!ist->decoding_needed)
         eof_reached = 1;
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index aef2bbc0df..50e5858385 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -370,7 +370,8 @@ typedef struct InputStream {
     int64_t first_dts;       ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
     int64_t       dts;       ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
 
-    int64_t       next_pts;  ///< synthetic pts for the next decode frame (in AV_TIME_BASE units)
+    /* predicted pts of the next decoded frame, in AV_TIME_BASE */
+    int64_t       next_pts;
     int64_t       pts;       ///< current pts of the decoded frame  (in AV_TIME_BASE units)
     int           wrap_correction_done;
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 28/29] fftools/ffmpeg: move checking for input -t out of do_streamcopy()
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (25 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 27/29] fftools/ffmpeg: only set InputStream.next_pts for decoding Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 29/29] fftools/ffmpeg: stop using InputStream.pts for streamcopy Anton Khirnov
  2023-04-11  6:35 ` [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

This check is entirely about the properties of the input stream, while
do_streamcopy() should contain code specific to a given output stream.
---
 fftools/ffmpeg.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 4d4083d474..5c80f3b65f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -944,7 +944,6 @@ int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *pa
 static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
 {
     OutputFile *of = output_files[ost->file_index];
-    InputFile   *f = input_files [ist->file_index];
     int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
     int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase);
     AVPacket *opkt = ost->pkt;
@@ -977,18 +976,6 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
         return;
     }
 
-    if (f->recording_time != INT64_MAX) {
-        start_time = 0;
-        if (copy_ts) {
-            start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
-            start_time += start_at_zero ? 0 : f->start_time_effective;
-        }
-        if (ist->pts >= f->recording_time + start_time) {
-            close_output_stream(ost);
-            return;
-        }
-    }
-
     if (av_packet_ref(opkt, pkt) < 0)
         exit_program(1);
 
@@ -1636,10 +1623,12 @@ static int send_filter_eof(InputStream *ist)
 /* pkt = NULL means EOF (needed to flush decoder buffers) */
 static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
 {
+    InputFile *f = input_files[ist->file_index];
     const AVCodecParameters *par = ist->par;
     int ret = 0;
     int repeating = 0;
     int eof_reached = 0;
+    int duration_exceeded;
 
     AVPacket *avpkt = ist->pkt;
 
@@ -1814,11 +1803,27 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
     } else if (!ist->decoding_needed)
         eof_reached = 1;
 
+    duration_exceeded = 0;
+    if (f->recording_time != INT64_MAX) {
+        int64_t start_time = 0;
+        if (copy_ts) {
+            start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
+            start_time += start_at_zero ? 0 : f->start_time_effective;
+        }
+        if (ist->pts >= f->recording_time + start_time)
+            duration_exceeded = 1;
+    }
+
     for (int oidx = 0; oidx < ist->nb_outputs; oidx++) {
         OutputStream *ost = ist->outputs[oidx];
         if (ost->enc_ctx || (!pkt && no_eof))
             continue;
 
+        if (duration_exceeded) {
+            close_output_stream(ost);
+            continue;
+        }
+
         do_streamcopy(ist, ost, pkt);
     }
 
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* [FFmpeg-devel] [PATCH 29/29] fftools/ffmpeg: stop using InputStream.pts for streamcopy
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (26 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 28/29] fftools/ffmpeg: move checking for input -t out of do_streamcopy() Anton Khirnov
@ 2023-04-09 14:08 ` Anton Khirnov
  2023-04-11  6:35 ` [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-09 14:08 UTC (permalink / raw)
  To: ffmpeg-devel

This field contains different value depending on whether the stream is
being decoded or not. When it is, InputStream.pts is set to the
timestamp of the last decoded frame. Otherwise, it is made equal to
InputStream.dts.

Since a given InputStream can be at the same time decoded and
streamcopied to any number of output streams, this use is incorrect, as
decoded frame timestamps can be delayed with respect to input packets by
an arbitrary amount (e.g. depending on the thread count when frame
threading is used).

Replace all uses of InputStream.pts for streamcopy with InputStream.dts,
which is its value when decoding is not performed. Stop setting
InputStream.pts for pure streamcopy.
Also, pass InputStream.dts as a parameter to do_streamcopy(), which
will allow that function to be decoupled from InputStream completely in
the future.
---
 fftools/ffmpeg.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5c80f3b65f..d14ae62e86 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -941,7 +941,11 @@ int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *pa
     return 0;
 }
 
-static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
+/**
+ * @param dts predicted packet dts in AV_TIME_BASE_Q
+ */
+static void do_streamcopy(InputStream *ist, OutputStream *ost,
+                          const AVPacket *pkt, int64_t dts)
 {
     OutputFile *of = output_files[ost->file_index];
     int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
@@ -962,16 +966,16 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
     if (!ost->streamcopy_started) {
         if (!ost->copy_prior_start &&
             (pkt->pts == AV_NOPTS_VALUE ?
-             ist->pts < ost->ts_copy_start :
+             dts < ost->ts_copy_start :
              pkt->pts < av_rescale_q(ost->ts_copy_start, AV_TIME_BASE_Q, pkt->time_base)))
             return;
 
-        if (of->start_time != AV_NOPTS_VALUE && ist->pts < of->start_time)
+        if (of->start_time != AV_NOPTS_VALUE && dts < of->start_time)
             return;
     }
 
     if (of->recording_time != INT64_MAX &&
-        ist->pts >= of->recording_time + start_time) {
+        dts >= of->recording_time + start_time) {
         close_output_stream(ost);
         return;
     }
@@ -985,7 +989,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
         opkt->pts = av_rescale_q(pkt->pts, pkt->time_base, opkt->time_base) - ost_tb_start_time;
 
     if (pkt->dts == AV_NOPTS_VALUE) {
-        opkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, opkt->time_base);
+        opkt->dts = av_rescale_q(dts, AV_TIME_BASE_Q, opkt->time_base);
     } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
         int duration = av_get_audio_frame_duration2(ist->par, pkt->size);
         if(!duration)
@@ -1639,7 +1643,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
         if (pkt && pkt->pts != AV_NOPTS_VALUE && !ist->decoding_needed) {
             ist->first_dts =
             ist->dts += av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q);
-            ist->pts = ist->dts; //unused but better to set it to a value thats not totally wrong
         }
         ist->saw_first_ts = 1;
     }
@@ -1658,7 +1661,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
 
     if (pkt && pkt->dts != AV_NOPTS_VALUE) {
         ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
-        if (par->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed)
+        if (par->codec_type != AVMEDIA_TYPE_VIDEO)
             ist->pts = ist->dts;
     }
 
@@ -1810,7 +1813,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
             start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0;
             start_time += start_at_zero ? 0 : f->start_time_effective;
         }
-        if (ist->pts >= f->recording_time + start_time)
+        if (ist->dts >= f->recording_time + start_time)
             duration_exceeded = 1;
     }
 
@@ -1824,7 +1827,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
             continue;
         }
 
-        do_streamcopy(ist, ost, pkt);
+        do_streamcopy(ist, ost, pkt, ist->dts);
     }
 
     return !eof_reached;
-- 
2.39.1

_______________________________________________
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] 32+ messages in thread

* Re: [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder
  2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
                   ` (27 preceding siblings ...)
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 29/29] fftools/ffmpeg: stop using InputStream.pts for streamcopy Anton Khirnov
@ 2023-04-11  6:35 ` Anton Khirnov
  28 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-11  6:35 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

If anyone wants to have a closer look, the set can also be obtained from
https://git.khirnov.net/libav.git/log/?h=ffmpeg_enc_cleanup

I believe it is rather straightforward and uncontroversial, maybe except
for 19/29. If nobody has any comments, I intend to push this in two
days.

-- 
Anton Khirnov
_______________________________________________
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] 32+ messages in thread

* Re: [FFmpeg-devel] [PATCH 25/29] fftools/ffmpeg_demux: set the timebase on demuxed packets
  2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 25/29] fftools/ffmpeg_demux: set the timebase on demuxed packets Anton Khirnov
@ 2023-04-12  2:49   ` James Almer
  2023-04-12  5:59     ` Anton Khirnov
  0 siblings, 1 reply; 32+ messages in thread
From: James Almer @ 2023-04-12  2:49 UTC (permalink / raw)
  To: ffmpeg-devel

On 4/9/2023 11:08 AM, Anton Khirnov wrote:
> Simplifies tracking what timebase are the timestamps in. Will be useful
> in following commits.
> ---
>   fftools/ffmpeg_demux.c | 16 +++++++++-------
>   1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> index f2da0826ad..7ff57273c9 100644
> --- a/fftools/ffmpeg_demux.c
> +++ b/fftools/ffmpeg_demux.c
> @@ -194,15 +194,17 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
>       const int64_t start_time = ifile->start_time_effective;
>       int64_t duration;
>   
> +    pkt->time_base = ist->st->time_base;

Might be a good future-proof idea to check first if pkt->time_base is 
already set or not. The doxy says demuxers themselves may start doing so 
at some point.

> +
>   #define SHOW_TS_DEBUG(tag_)                                             \
>       if (debug_ts) {                                                     \
>           av_log(ist, AV_LOG_INFO, "%s -> ist_index:%d:%d type:%s "       \
>                  "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s\n", \
>                  tag_, ifile->index, pkt->stream_index,                   \
>                  av_get_media_type_string(ist->st->codecpar->codec_type), \
> -               av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), \
> -               av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), \
> -               av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ist->st->time_base)); \
> +               av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base), \
> +               av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base), \
> +               av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base)); \
>       }
>   
>       SHOW_TS_DEBUG("demuxer");
> @@ -211,7 +213,7 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
>           ist->st->pts_wrap_bits < 64) {
>           int64_t stime, stime2;
>   
> -        stime = av_rescale_q(start_time, AV_TIME_BASE_Q, ist->st->time_base);
> +        stime = av_rescale_q(start_time, AV_TIME_BASE_Q, pkt->time_base);
>           stime2= stime + (1ULL<<ist->st->pts_wrap_bits);
>           ist->wrap_correction_done = 1;
>   
> @@ -226,16 +228,16 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
>       }
>   
>       if (pkt->dts != AV_NOPTS_VALUE)
> -        pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
> +        pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, pkt->time_base);
>       if (pkt->pts != AV_NOPTS_VALUE)
> -        pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
> +        pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, pkt->time_base);
>   
>       if (pkt->pts != AV_NOPTS_VALUE)
>           pkt->pts *= ds->ts_scale;
>       if (pkt->dts != AV_NOPTS_VALUE)
>           pkt->dts *= ds->ts_scale;
>   
> -    duration = av_rescale_q(d->duration, d->time_base, ist->st->time_base);
> +    duration = av_rescale_q(d->duration, d->time_base, pkt->time_base);
>       if (pkt->pts != AV_NOPTS_VALUE) {
>           pkt->pts += duration;
>           ds->max_pts = FFMAX(pkt->pts, ds->max_pts);
_______________________________________________
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] 32+ messages in thread

* Re: [FFmpeg-devel] [PATCH 25/29] fftools/ffmpeg_demux: set the timebase on demuxed packets
  2023-04-12  2:49   ` James Almer
@ 2023-04-12  5:59     ` Anton Khirnov
  0 siblings, 0 replies; 32+ messages in thread
From: Anton Khirnov @ 2023-04-12  5:59 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2023-04-12 04:49:00)
> On 4/9/2023 11:08 AM, Anton Khirnov wrote:
> > Simplifies tracking what timebase are the timestamps in. Will be useful
> > in following commits.
> > ---
> >   fftools/ffmpeg_demux.c | 16 +++++++++-------
> >   1 file changed, 9 insertions(+), 7 deletions(-)
> > 
> > diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> > index f2da0826ad..7ff57273c9 100644
> > --- a/fftools/ffmpeg_demux.c
> > +++ b/fftools/ffmpeg_demux.c
> > @@ -194,15 +194,17 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
> >       const int64_t start_time = ifile->start_time_effective;
> >       int64_t duration;
> >   
> > +    pkt->time_base = ist->st->time_base;
> 
> Might be a good future-proof idea to check first if pkt->time_base is 
> already set or not. The doxy says demuxers themselves may start doing so 
> at some point.

Why would that make any difference? The timestamps have to be in the
stream timebase, anything else would be an API break. So whatever value
is or is not written there by the demuxer, we can always overwrite it by
what we know has to be the corect timebase.

-- 
Anton Khirnov
_______________________________________________
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] 32+ messages in thread

end of thread, other threads:[~2023-04-12  5:59 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 02/29] fftools/ffmpeg: move OutputStream.next_pts " Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 03/29] fftools/ffmpeg: move OutputStream.sq_frame " Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 04/29] fftools/ffmpeg: move OutputStream.last_nb0_frames " Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 05/29] fftools/ffmpeg: move OutputStream.last_filter_pts to OutputFilter Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 06/29] fftools/ffmpeg_enc: replace abort() with av_assert0(0) Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 07/29] fftools/ffmpeg: drop a useless goto Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 08/29] fftools/ffmpeg: move the hw_device_free_all() call to ffmpeg_cleanup() Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 09/29] fftools/ffmpeg: eliminate the main_return_code global Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 10/29] fftools/ffmpeg: factorize checking whether any output was written Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 11/29] fftools/ffmpeg: move printing verbose muxing stats to ffmpeg_mux Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 12/29] fftools/ffmpeg_mux: reindent Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 13/29] fftools/ffmpeg_mux: log final stats to muxer context Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 14/29] fftools/ffmpeg: rewrite printing the final output sizes Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 15/29] fftools/ffmpeg_mux: make data_size_mux private to ffmpeg_mux Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 16/29] fftools/ffmpeg: move printing verbose demuxing stats to ffmpeg_demux Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 17/29] fftools/ffmpeg_demux: reindent Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 18/29] fftools/ffmpeg_demux: log final stats to demuxer context Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 19/29] fftools/ffmpeg: disable and deprecate -qphist Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 20/29] fftools/ffmpeg_filter: stop setting encoder channel layout unnecessarily Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 21/29] fftools/ffmpeg_mux_init: print more meaningful error messages Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 22/29] fftools/ffmpeg: track a list of non-lavfi outputs in InputStream Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 23/29] fftools/ffmpeg: stop calling check_output_constraints() for streamcopy Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 24/29] fftools/ffmpeg: inline check_output_constraints() into its only caller Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 25/29] fftools/ffmpeg_demux: set the timebase on demuxed packets Anton Khirnov
2023-04-12  2:49   ` James Almer
2023-04-12  5:59     ` Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 26/29] fftools/ffmpeg: use AVPacket.time_base to simplify do_streamcopy() Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 27/29] fftools/ffmpeg: only set InputStream.next_pts for decoding Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 28/29] fftools/ffmpeg: move checking for input -t out of do_streamcopy() Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 29/29] fftools/ffmpeg: stop using InputStream.pts for streamcopy Anton Khirnov
2023-04-11  6:35 ` [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder 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