2012-05-09 15:08:21 +03:00
|
|
|
/*
|
2012-05-22 22:29:24 +03:00
|
|
|
* Copyright 2007 Bobby Bingham
|
|
|
|
* Copyright 2012 Robert Nagy <ronag89 gmail com>
|
|
|
|
* Copyright 2012 Anton Khirnov <anton khirnov net>
|
2018-02-22 21:10:03 +02:00
|
|
|
* Copyright 2018 Calvin Walton <calvin.walton@kepstin.ca>
|
2012-05-22 22:29:24 +03:00
|
|
|
*
|
2012-05-22 22:27:54 +03:00
|
|
|
* This file is part of FFmpeg.
|
2012-05-09 15:08:21 +03:00
|
|
|
*
|
2012-05-22 22:27:54 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2012-05-09 15:08:21 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-05-22 22:27:54 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2012-05-09 15:08:21 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-05-22 22:27:54 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2012-05-09 15:08:21 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* a filter enforcing given constant framerate
|
|
|
|
*/
|
|
|
|
|
2013-08-27 23:44:14 +03:00
|
|
|
#include <float.h>
|
2013-11-23 23:32:55 +03:00
|
|
|
#include <stdint.h>
|
2013-08-27 23:44:14 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
#include "libavutil/avassert.h"
|
2021-02-24 19:40:04 +02:00
|
|
|
#include "libavutil/eval.h"
|
2012-05-09 15:08:21 +03:00
|
|
|
#include "libavutil/mathematics.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "avfilter.h"
|
2018-02-22 21:10:03 +02:00
|
|
|
#include "filters.h"
|
2012-05-30 12:20:32 +03:00
|
|
|
#include "internal.h"
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2017-09-21 13:40:36 +02:00
|
|
|
enum EOFAction {
|
|
|
|
EOF_ACTION_ROUND,
|
|
|
|
EOF_ACTION_PASS,
|
|
|
|
EOF_ACTION_NB
|
|
|
|
};
|
|
|
|
|
2021-02-24 19:40:04 +02:00
|
|
|
static const char *const var_names[] = {
|
|
|
|
"source_fps",
|
|
|
|
"ntsc",
|
|
|
|
"pal",
|
|
|
|
"film",
|
|
|
|
"ntsc_film",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum var_name {
|
|
|
|
VAR_SOURCE_FPS,
|
|
|
|
VAR_FPS_NTSC,
|
|
|
|
VAR_FPS_PAL,
|
|
|
|
VAR_FPS_FILM,
|
|
|
|
VAR_FPS_NTSC_FILM,
|
|
|
|
VARS_NB
|
|
|
|
};
|
|
|
|
|
|
|
|
static const double ntsc_fps = 30000.0 / 1001.0;
|
|
|
|
static const double pal_fps = 25.0;
|
|
|
|
static const double film_fps = 24.0;
|
|
|
|
static const double ntsc_film_fps = 24000.0 / 1001.0;
|
|
|
|
|
2012-05-09 15:08:21 +03:00
|
|
|
typedef struct FPSContext {
|
|
|
|
const AVClass *class;
|
|
|
|
|
2013-08-15 23:14:57 +03:00
|
|
|
double start_time; ///< pts, in seconds, of the expected first frame
|
|
|
|
|
2021-02-24 19:40:04 +02:00
|
|
|
char *framerate; ///< expression that defines the target framerate
|
lavfi/vf_fps: allow to set the rounding method.
By default, fps selects frames near PTS 0, 0.5, 1.5, 2.5, etc.
With round=down, it selects the frames near PTS 0, 1, 2, 3, etc.
2012-10-25 18:58:08 +03:00
|
|
|
int rounding; ///< AVRounding method for timestamps
|
2017-09-21 13:40:36 +02:00
|
|
|
int eof_action; ///< action performed for last frame in FIFO
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Set during outlink configuration */
|
|
|
|
int64_t in_pts_off; ///< input frame pts offset for start_time handling
|
|
|
|
int64_t out_pts_off; ///< output frame pts offset for start_time handling
|
|
|
|
|
|
|
|
/* Runtime state */
|
|
|
|
int status; ///< buffered input status
|
|
|
|
int64_t status_pts; ///< buffered input status timestamp
|
|
|
|
|
|
|
|
AVFrame *frames[2]; ///< buffered frames
|
|
|
|
int frames_count; ///< number of buffered frames
|
|
|
|
|
|
|
|
int64_t next_pts; ///< pts of the next frame to output
|
|
|
|
|
2012-05-09 15:08:21 +03:00
|
|
|
/* statistics */
|
2018-02-22 21:10:03 +02:00
|
|
|
int cur_frame_out; ///< number of times current frame has been output
|
2012-05-09 15:08:21 +03:00
|
|
|
int frames_in; ///< number of frames on input
|
|
|
|
int frames_out; ///< number of frames on output
|
|
|
|
int dup; ///< number of frames duplicated
|
|
|
|
int drop; ///< number of framed dropped
|
|
|
|
} FPSContext;
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(FPSContext, x)
|
|
|
|
#define V AV_OPT_FLAG_VIDEO_PARAM
|
2012-08-13 14:40:01 +03:00
|
|
|
#define F AV_OPT_FLAG_FILTERING_PARAM
|
2012-06-22 15:33:09 +03:00
|
|
|
static const AVOption fps_options[] = {
|
2021-02-24 19:40:04 +02:00
|
|
|
{ "fps", "A string describing desired output framerate", OFFSET(framerate), AV_OPT_TYPE_STRING, { .str = "25" }, 0, 0, V|F },
|
2017-10-05 10:18:57 +02:00
|
|
|
{ "start_time", "Assume the first PTS should be this value.", OFFSET(start_time), AV_OPT_TYPE_DOUBLE, { .dbl = DBL_MAX}, -DBL_MAX, DBL_MAX, V|F },
|
lavfi/vf_fps: allow to set the rounding method.
By default, fps selects frames near PTS 0, 0.5, 1.5, 2.5, etc.
With round=down, it selects the frames near PTS 0, 1, 2, 3, etc.
2012-10-25 18:58:08 +03:00
|
|
|
{ "round", "set rounding method for timestamps", OFFSET(rounding), AV_OPT_TYPE_INT, { .i64 = AV_ROUND_NEAR_INF }, 0, 5, V|F, "round" },
|
2017-10-05 10:18:57 +02:00
|
|
|
{ "zero", "round towards 0", 0, AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_ZERO }, 0, 0, V|F, "round" },
|
|
|
|
{ "inf", "round away from 0", 0, AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_INF }, 0, 0, V|F, "round" },
|
|
|
|
{ "down", "round towards -infty", 0, AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_DOWN }, 0, 0, V|F, "round" },
|
|
|
|
{ "up", "round towards +infty", 0, AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_UP }, 0, 0, V|F, "round" },
|
|
|
|
{ "near", "round to nearest", 0, AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_NEAR_INF }, 0, 0, V|F, "round" },
|
2017-09-21 13:40:36 +02:00
|
|
|
{ "eof_action", "action performed for last frame", OFFSET(eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_ROUND }, 0, EOF_ACTION_NB-1, V|F, "eof_action" },
|
|
|
|
{ "round", "round similar to other frames", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_ROUND }, 0, 0, V|F, "eof_action" },
|
|
|
|
{ "pass", "pass through last frame", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_PASS }, 0, 0, V|F, "eof_action" },
|
2013-09-07 15:13:50 +03:00
|
|
|
{ NULL }
|
2012-05-09 15:08:21 +03:00
|
|
|
};
|
|
|
|
|
2012-06-22 15:33:09 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(fps);
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2013-03-13 10:26:39 +03:00
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
2012-05-09 15:08:21 +03:00
|
|
|
{
|
|
|
|
FPSContext *s = ctx->priv;
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
s->status_pts = AV_NOPTS_VALUE;
|
|
|
|
s->next_pts = AV_NOPTS_VALUE;
|
2013-03-19 00:32:39 +03:00
|
|
|
|
2012-05-09 15:08:21 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Remove the first frame from the buffer, returning it */
|
|
|
|
static AVFrame *shift_frame(AVFilterContext *ctx, FPSContext *s)
|
2012-05-09 15:08:21 +03:00
|
|
|
{
|
2018-02-22 21:10:03 +02:00
|
|
|
AVFrame *frame;
|
|
|
|
|
|
|
|
/* Must only be called when there are frames in the buffer */
|
|
|
|
av_assert1(s->frames_count > 0);
|
|
|
|
|
|
|
|
frame = s->frames[0];
|
|
|
|
s->frames[0] = s->frames[1];
|
|
|
|
s->frames[1] = NULL;
|
|
|
|
s->frames_count--;
|
|
|
|
|
|
|
|
/* Update statistics counters */
|
|
|
|
s->frames_out += s->cur_frame_out;
|
|
|
|
if (s->cur_frame_out > 1) {
|
|
|
|
av_log(ctx, AV_LOG_DEBUG, "Duplicated frame with pts %"PRId64" %d times\n",
|
|
|
|
frame->pts, s->cur_frame_out - 1);
|
|
|
|
s->dup += s->cur_frame_out - 1;
|
|
|
|
} else if (s->cur_frame_out == 0) {
|
|
|
|
av_log(ctx, AV_LOG_DEBUG, "Dropping frame with pts %"PRId64"\n",
|
|
|
|
frame->pts);
|
|
|
|
s->drop++;
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
2018-02-22 21:10:03 +02:00
|
|
|
s->cur_frame_out = 0;
|
|
|
|
|
|
|
|
return frame;
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
FPSContext *s = ctx->priv;
|
2018-02-22 21:10:03 +02:00
|
|
|
|
|
|
|
AVFrame *frame;
|
|
|
|
|
|
|
|
while (s->frames_count > 0) {
|
|
|
|
frame = shift_frame(ctx, s);
|
|
|
|
av_frame_free(&frame);
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "%d frames in, %d frames out; %d frames dropped, "
|
|
|
|
"%d frames duplicated.\n", s->frames_in, s->frames_out, s->drop, s->dup);
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:10:04 +02:00
|
|
|
static int config_props(AVFilterLink* outlink)
|
2012-05-09 15:08:21 +03:00
|
|
|
{
|
2018-02-22 21:10:04 +02:00
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
FPSContext *s = ctx->priv;
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2021-02-24 19:40:04 +02:00
|
|
|
double var_values[VARS_NB], res;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
var_values[VAR_SOURCE_FPS] = av_q2d(inlink->frame_rate);
|
|
|
|
var_values[VAR_FPS_NTSC] = ntsc_fps;
|
|
|
|
var_values[VAR_FPS_PAL] = pal_fps;
|
|
|
|
var_values[VAR_FPS_FILM] = film_fps;
|
|
|
|
var_values[VAR_FPS_NTSC_FILM] = ntsc_film_fps;
|
|
|
|
ret = av_expr_parse_and_eval(&res, s->framerate,
|
|
|
|
var_names, var_values,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, 0, ctx);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
outlink->frame_rate = av_d2q(res, INT_MAX);
|
|
|
|
outlink->time_base = av_inv_q(outlink->frame_rate);
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Calculate the input and output pts offsets for start_time */
|
|
|
|
if (s->start_time != DBL_MAX && s->start_time != AV_NOPTS_VALUE) {
|
|
|
|
double first_pts = s->start_time * AV_TIME_BASE;
|
|
|
|
if (first_pts < INT64_MIN || first_pts > INT64_MAX) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Start time %f cannot be represented in internal time base\n",
|
|
|
|
s->start_time);
|
|
|
|
return AVERROR(EINVAL);
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
2018-02-22 21:10:03 +02:00
|
|
|
s->in_pts_off = av_rescale_q_rnd(first_pts, AV_TIME_BASE_Q, inlink->time_base,
|
|
|
|
s->rounding | AV_ROUND_PASS_MINMAX);
|
2018-02-22 21:10:04 +02:00
|
|
|
s->out_pts_off = av_rescale_q_rnd(first_pts, AV_TIME_BASE_Q, outlink->time_base,
|
2018-02-22 21:10:03 +02:00
|
|
|
s->rounding | AV_ROUND_PASS_MINMAX);
|
|
|
|
s->next_pts = s->out_pts_off;
|
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "Set first pts to (in:%"PRId64" out:%"PRId64") from start time %f\n",
|
|
|
|
s->in_pts_off, s->out_pts_off, s->start_time);
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:40:04 +02:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "fps=%d/%d\n", outlink->frame_rate.num, outlink->frame_rate.den);
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
return 0;
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Read a frame from the input and save it in the buffer */
|
|
|
|
static int read_frame(AVFilterContext *ctx, FPSContext *s, AVFilterLink *inlink, AVFilterLink *outlink)
|
2012-05-09 15:08:21 +03:00
|
|
|
{
|
2018-02-22 21:10:03 +02:00
|
|
|
AVFrame *frame;
|
2012-05-09 15:08:21 +03:00
|
|
|
int ret;
|
2018-02-22 21:10:03 +02:00
|
|
|
int64_t in_pts;
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Must only be called when we have buffer room available */
|
|
|
|
av_assert1(s->frames_count < 2);
|
|
|
|
|
|
|
|
ret = ff_inlink_consume_frame(inlink, &frame);
|
|
|
|
/* Caller must have run ff_inlink_check_available_frame first */
|
|
|
|
av_assert1(ret);
|
|
|
|
if (ret < 0)
|
2012-05-09 15:08:21 +03:00
|
|
|
return ret;
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Convert frame pts to output timebase.
|
|
|
|
* The dance with offsets is required to match the rounding behaviour of the
|
|
|
|
* previous version of the fps filter when using the start_time option. */
|
|
|
|
in_pts = frame->pts;
|
|
|
|
frame->pts = s->out_pts_off + av_rescale_q_rnd(in_pts - s->in_pts_off,
|
|
|
|
inlink->time_base, outlink->time_base,
|
|
|
|
s->rounding | AV_ROUND_PASS_MINMAX);
|
|
|
|
|
|
|
|
av_log(ctx, AV_LOG_DEBUG, "Read frame with in pts %"PRId64", out pts %"PRId64"\n",
|
|
|
|
in_pts, frame->pts);
|
|
|
|
|
|
|
|
s->frames[s->frames_count++] = frame;
|
|
|
|
s->frames_in++;
|
|
|
|
|
|
|
|
return 1;
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Write a frame to the output */
|
|
|
|
static int write_frame(AVFilterContext *ctx, FPSContext *s, AVFilterLink *outlink, int *again)
|
2012-05-09 15:08:21 +03:00
|
|
|
{
|
2018-02-22 21:10:03 +02:00
|
|
|
AVFrame *frame;
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
av_assert1(s->frames_count == 2 || (s->status && s->frames_count == 1));
|
2012-07-15 11:07:59 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* We haven't yet determined the pts of the first frame */
|
|
|
|
if (s->next_pts == AV_NOPTS_VALUE) {
|
|
|
|
if (s->frames[0]->pts != AV_NOPTS_VALUE) {
|
|
|
|
s->next_pts = s->frames[0]->pts;
|
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "Set first pts to %"PRId64"\n", s->next_pts);
|
2012-05-09 15:08:21 +03:00
|
|
|
} else {
|
|
|
|
av_log(ctx, AV_LOG_WARNING, "Discarding initial frame(s) with no "
|
|
|
|
"timestamp.\n");
|
2018-02-22 21:10:03 +02:00
|
|
|
frame = shift_frame(ctx, s);
|
|
|
|
av_frame_free(&frame);
|
|
|
|
*again = 1;
|
|
|
|
return 0;
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* There are two conditions where we want to drop a frame:
|
|
|
|
* - If we have two buffered frames and the second frame is acceptable
|
|
|
|
* as the next output frame, then drop the first buffered frame.
|
|
|
|
* - If we have status (EOF) set, drop frames when we hit the
|
|
|
|
* status timestamp. */
|
|
|
|
if ((s->frames_count == 2 && s->frames[1]->pts <= s->next_pts) ||
|
|
|
|
(s->status && s->status_pts <= s->next_pts)) {
|
|
|
|
|
|
|
|
frame = shift_frame(ctx, s);
|
|
|
|
av_frame_free(&frame);
|
|
|
|
*again = 1;
|
|
|
|
return 0;
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Output a copy of the first buffered frame */
|
|
|
|
} else {
|
|
|
|
frame = av_frame_clone(s->frames[0]);
|
|
|
|
if (!frame)
|
|
|
|
return AVERROR(ENOMEM);
|
2018-11-23 19:48:50 +02:00
|
|
|
// Make sure Closed Captions will not be duplicated
|
|
|
|
av_frame_remove_side_data(s->frames[0], AV_FRAME_DATA_A53_CC);
|
2018-02-22 21:10:03 +02:00
|
|
|
frame->pts = s->next_pts++;
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "Writing frame with pts %"PRId64" to pts %"PRId64"\n",
|
|
|
|
s->frames[0]->pts, frame->pts);
|
|
|
|
s->cur_frame_out++;
|
2019-08-29 04:13:20 +02:00
|
|
|
*again = 1;
|
2018-02-22 21:10:03 +02:00
|
|
|
return ff_filter_frame(outlink, frame);
|
|
|
|
}
|
|
|
|
}
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Convert status_pts to outlink timebase */
|
|
|
|
static void update_eof_pts(AVFilterContext *ctx, FPSContext *s, AVFilterLink *inlink, AVFilterLink *outlink, int64_t status_pts)
|
|
|
|
{
|
|
|
|
int eof_rounding = (s->eof_action == EOF_ACTION_PASS) ? AV_ROUND_UP : s->rounding;
|
|
|
|
s->status_pts = av_rescale_q_rnd(status_pts, inlink->time_base, outlink->time_base,
|
|
|
|
eof_rounding | AV_ROUND_PASS_MINMAX);
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "EOF is at pts %"PRId64"\n", s->status_pts);
|
|
|
|
}
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
static int activate(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
FPSContext *s = ctx->priv;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
2012-05-09 15:08:21 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
int ret;
|
|
|
|
int again = 0;
|
|
|
|
int64_t status_pts;
|
2012-07-15 11:07:59 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
|
2012-07-15 11:07:59 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* No buffered status: normal operation */
|
|
|
|
if (!s->status) {
|
2012-07-15 11:07:59 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Read available input frames if we have room */
|
|
|
|
while (s->frames_count < 2 && ff_inlink_check_available_frame(inlink)) {
|
|
|
|
ret = read_frame(ctx, s, inlink, outlink);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* We do not yet have enough frames to produce output */
|
|
|
|
if (s->frames_count < 2) {
|
|
|
|
/* Check if we've hit EOF (or otherwise that an error status is set) */
|
|
|
|
ret = ff_inlink_acknowledge_status(inlink, &s->status, &status_pts);
|
|
|
|
if (ret > 0)
|
|
|
|
update_eof_pts(ctx, s, inlink, outlink, status_pts);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
/* If someone wants us to output, we'd better ask for more input */
|
|
|
|
FF_FILTER_FORWARD_WANTED(outlink, inlink);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-15 10:47:01 +03:00
|
|
|
}
|
2018-02-22 21:10:03 +02:00
|
|
|
}
|
2012-07-15 10:47:01 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* Buffered frames are available, so generate an output frame */
|
|
|
|
if (s->frames_count > 0) {
|
|
|
|
ret = write_frame(ctx, s, outlink, &again);
|
|
|
|
/* Couldn't generate a frame, so schedule us to perform another step */
|
|
|
|
if (again)
|
|
|
|
ff_filter_set_ready(ctx, 100);
|
|
|
|
return ret;
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
/* No frames left, so forward the status */
|
|
|
|
if (s->status && s->frames_count == 0) {
|
|
|
|
ff_outlink_set_status(outlink, s->status, s->next_pts);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-14 10:25:33 +03:00
|
|
|
|
2018-02-22 21:10:03 +02:00
|
|
|
return FFERROR_NOT_READY;
|
2012-05-09 15:08:21 +03:00
|
|
|
}
|
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
static const AVFilterPad avfilter_vf_fps_inputs[] = {
|
|
|
|
{
|
2013-09-07 15:13:50 +03:00
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-07-24 16:14:01 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad avfilter_vf_fps_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2018-02-22 21:10:03 +02:00
|
|
|
.config_props = config_props,
|
2012-07-24 16:14:01 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_vf_fps = {
|
2012-05-09 15:08:21 +03:00
|
|
|
.name = "fps",
|
2013-04-14 21:58:31 +03:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Force constant framerate."),
|
2013-09-07 15:13:50 +03:00
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.priv_size = sizeof(FPSContext),
|
|
|
|
.priv_class = &fps_class,
|
2018-02-22 21:10:03 +02:00
|
|
|
.activate = activate,
|
2021-11-22 15:39:11 +02:00
|
|
|
.flags = AVFILTER_FLAG_METADATA_ONLY,
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_INPUTS(avfilter_vf_fps_inputs),
|
|
|
|
FILTER_OUTPUTS(avfilter_vf_fps_outputs),
|
2012-05-09 15:08:21 +03:00
|
|
|
};
|