You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avfilter/trim: consume all available frames and avoid activate reschedule
There is no benefit in delaying processing all available frames. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
@ -90,10 +90,8 @@ static int trim_filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
|||||||
int drop;
|
int drop;
|
||||||
|
|
||||||
/* drop everything if EOF has already been returned */
|
/* drop everything if EOF has already been returned */
|
||||||
if (s->eof) {
|
if (s->eof)
|
||||||
av_frame_free(&frame);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (s->start_frame >= 0 || s->start_pts != AV_NOPTS_VALUE) {
|
if (s->start_frame >= 0 || s->start_pts != AV_NOPTS_VALUE) {
|
||||||
drop = 1;
|
drop = 1;
|
||||||
@ -131,13 +129,10 @@ static int trim_filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
|||||||
|
|
||||||
s->nb_frames++;
|
s->nb_frames++;
|
||||||
|
|
||||||
return ff_filter_frame(ctx->outputs[0], frame);
|
return 1;
|
||||||
|
|
||||||
drop:
|
drop:
|
||||||
if (!s->eof)
|
|
||||||
ff_filter_set_ready(ctx, 100);
|
|
||||||
s->nb_frames++;
|
s->nb_frames++;
|
||||||
av_frame_free(&frame);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_TRIM_FILTER
|
#endif // CONFIG_TRIM_FILTER
|
||||||
@ -152,10 +147,8 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
|||||||
int drop;
|
int drop;
|
||||||
|
|
||||||
/* drop everything if EOF has already been returned */
|
/* drop everything if EOF has already been returned */
|
||||||
if (s->eof) {
|
if (s->eof)
|
||||||
av_frame_free(&frame);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (frame->pts != AV_NOPTS_VALUE)
|
if (frame->pts != AV_NOPTS_VALUE)
|
||||||
pts = av_rescale_q(frame->pts, inlink->time_base,
|
pts = av_rescale_q(frame->pts, inlink->time_base,
|
||||||
@ -230,10 +223,8 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
|||||||
|
|
||||||
if (start_sample) {
|
if (start_sample) {
|
||||||
AVFrame *out = ff_get_audio_buffer(ctx->outputs[0], end_sample - start_sample);
|
AVFrame *out = ff_get_audio_buffer(ctx->outputs[0], end_sample - start_sample);
|
||||||
if (!out) {
|
if (!out)
|
||||||
av_frame_free(&frame);
|
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
|
||||||
|
|
||||||
av_frame_copy_props(out, frame);
|
av_frame_copy_props(out, frame);
|
||||||
av_samples_copy(out->extended_data, frame->extended_data, 0, start_sample,
|
av_samples_copy(out->extended_data, frame->extended_data, 0, start_sample,
|
||||||
@ -243,18 +234,16 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
|||||||
out->pts += av_rescale_q(start_sample, (AVRational){ 1, out->sample_rate },
|
out->pts += av_rescale_q(start_sample, (AVRational){ 1, out->sample_rate },
|
||||||
inlink->time_base);
|
inlink->time_base);
|
||||||
|
|
||||||
av_frame_free(&frame);
|
av_frame_unref(frame);
|
||||||
frame = out;
|
av_frame_move_ref(frame, out);
|
||||||
|
av_frame_free(&out);
|
||||||
} else
|
} else
|
||||||
frame->nb_samples = end_sample;
|
frame->nb_samples = end_sample;
|
||||||
|
|
||||||
return ff_filter_frame(ctx->outputs[0], frame);
|
return 1;
|
||||||
|
|
||||||
drop:
|
drop:
|
||||||
if (!s->eof)
|
|
||||||
ff_filter_set_ready(ctx, 100);
|
|
||||||
s->nb_samples += frame->nb_samples;
|
s->nb_samples += frame->nb_samples;
|
||||||
av_frame_free(&frame);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_ATRIM_FILTER
|
#endif // CONFIG_ATRIM_FILTER
|
||||||
@ -295,18 +284,21 @@ static int activate(AVFilterContext *ctx)
|
|||||||
TrimContext *s = ctx->priv;
|
TrimContext *s = ctx->priv;
|
||||||
AVFilterLink *inlink = ctx->inputs[0];
|
AVFilterLink *inlink = ctx->inputs[0];
|
||||||
AVFilterLink *outlink = ctx->outputs[0];
|
AVFilterLink *outlink = ctx->outputs[0];
|
||||||
|
AVFrame *frame = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
|
FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
|
||||||
|
|
||||||
if (!s->eof && ff_inlink_queued_frames(inlink)) {
|
while ((ret = ff_inlink_consume_frame(inlink, &frame))) {
|
||||||
AVFrame *frame = NULL;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = ff_inlink_consume_frame(inlink, &frame);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
ret = s->filter_frame(inlink, frame);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
return s->filter_frame(inlink, frame);
|
return ff_filter_frame(outlink, frame);
|
||||||
|
av_frame_free(&frame);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
FF_FILTER_FORWARD_STATUS(inlink, outlink);
|
FF_FILTER_FORWARD_STATUS(inlink, outlink);
|
||||||
|
Reference in New Issue
Block a user