[FFmpeg-cvslog] avfilter/f_segment: fix sending frames with zero samples out

Paul B Mahol git at videolan.org
Tue Mar 8 11:26:01 EET 2022


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Mar  8 10:20:05 2022 +0100| [3706fb8f16525d1d937a4b037205009b341b6390] | committer: Paul B Mahol

avfilter/f_segment: fix sending frames with zero samples out

Fix max_samples variable type, and check for out of range values.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3706fb8f16525d1d937a4b037205009b341b6390
---

 libavfilter/f_segment.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/libavfilter/f_segment.c b/libavfilter/f_segment.c
index 5f44634803..dd94eb9360 100644
--- a/libavfilter/f_segment.c
+++ b/libavfilter/f_segment.c
@@ -41,6 +41,7 @@ typedef struct SegmentContext {
 
     int current_point;
     int nb_points;
+    int64_t last_pts;
 
     int64_t *points;
 } SegmentContext;
@@ -186,7 +187,7 @@ static int activate(AVFilterContext *ctx)
     SegmentContext *s = ctx->priv;
     AVFrame *frame = NULL;
     int ret, status;
-    int max_samples;
+    int64_t max_samples;
     int64_t diff;
     int64_t pts;
 
@@ -200,18 +201,30 @@ static int activate(AVFilterContext *ctx)
         break;
     case AVMEDIA_TYPE_AUDIO:
         diff = s->points[s->current_point] - inlink->sample_count_out;
+        while (diff <= 0) {
+            ff_outlink_set_status(ctx->outputs[s->current_point], AVERROR_EOF, s->last_pts);
+            s->current_point++;
+            if (s->current_point >= s->nb_points)
+                return AVERROR(EINVAL);
+
+            diff = s->points[s->current_point] - inlink->sample_count_out;
+        }
         if (s->use_timestamps) {
             max_samples = av_rescale_q(diff, av_make_q(1, inlink->sample_rate), inlink->time_base);
         } else {
             max_samples = FFMAX(1, FFMIN(diff, INT_MAX));
         }
-        ret = ff_inlink_consume_samples(inlink, 1, max_samples, &frame);
+        if (max_samples <= 0 || max_samples > INT_MAX)
+            ret = ff_inlink_consume_frame(inlink, &frame);
+        else
+            ret = ff_inlink_consume_samples(inlink, 1, max_samples, &frame);
         break;
     default:
         return AVERROR_BUG;
     }
 
     if (ret > 0) {
+        s->last_pts = frame->pts;
         while (current_segment_finished(ctx, frame)) {
             ff_outlink_set_status(ctx->outputs[s->current_point], AVERROR_EOF, frame->pts);
             s->current_point++;



More information about the ffmpeg-cvslog mailing list