aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2022-03-08 10:20:05 +0100
committerPaul B Mahol <onemda@gmail.com>2022-03-08 10:26:46 +0100
commit3706fb8f16525d1d937a4b037205009b341b6390 (patch)
tree16517e72718a9d09d2bf5d99cd2c4c238971d0fb
parenta0fc6c4a8ed5097499732ad1b9f39a2914ed109e (diff)
downloadffmpeg-3706fb8f16525d1d937a4b037205009b341b6390.tar.gz
avfilter/f_segment: fix sending frames with zero samples out
Fix max_samples variable type, and check for out of range values.
-rw-r--r--libavfilter/f_segment.c17
1 files 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++;