* video presentation timestamp (PTS) modification filter
*/
+#include <inttypes.h>
+
#include "libavutil/eval.h"
#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
static const char *const var_names[] = {
"E", ///< Euler number
+ "FRAME_RATE", ///< defined only for constant frame-rate video
"INTERLACED", ///< tell if the current frame is interlaced
"N", ///< frame / sample number (starting at zero)
"PHI", ///< golden ratio
- "PI", ///< greek pi
+ "PI", ///< Greek pi
"PREV_INPTS", ///< previous input PTS
"PREV_OUTPTS", ///< previous output PTS
"PTS", ///< original pts in the file of the frame
enum var_name {
VAR_E,
+ VAR_FRAME_RATE,
VAR_INTERLACED,
VAR_N,
VAR_PHI,
VAR_VARS_NB
};
-typedef struct {
+typedef struct SetPTSContext {
const AVClass *class;
char *expr_str;
AVExpr *expr;
setpts->var_values[VAR_SR] = inlink->sample_rate;
}
+ setpts->var_values[VAR_FRAME_RATE] = inlink->frame_rate.num &&
+ inlink->frame_rate.den ?
+ av_q2d(inlink->frame_rate) : NAN;
+
+ // Indicate the output can be variable framerate.
+ inlink->frame_rate = (AVRational){1, 0};
+
av_log(inlink->src, AV_LOG_VERBOSE, "TB:%f\n", setpts->var_values[VAR_TB]);
return 0;
}
d = av_expr_eval(setpts->expr, setpts->var_values, NULL);
frame->pts = D2TS(d);
-#ifdef DEBUG
- av_log(inlink->dst, AV_LOG_DEBUG,
- "n:%"PRId64" interlaced:%d pts:%"PRId64" t:%f -> pts:%"PRId64" t:%f\n",
- (int64_t)setpts->var_values[VAR_N],
- (int)setpts->var_values[VAR_INTERLACED],
- in_pts, in_pts * av_q2d(inlink->time_base),
- frame->pts, frame->pts * av_q2d(inlink->time_base));
-#endif
-
+ av_log(inlink->dst, AV_LOG_TRACE,
+ "n:%"PRId64" interlaced:%d pts:%"PRId64" t:%f -> pts:%"PRId64" t:%f\n",
+ (int64_t)setpts->var_values[VAR_N],
+ (int)setpts->var_values[VAR_INTERLACED],
+ in_pts, in_pts * av_q2d(inlink->time_base),
+ frame->pts, frame->pts * av_q2d(inlink->time_base));
if (inlink->type == AVMEDIA_TYPE_VIDEO) {
setpts->var_values[VAR_N] += 1.0;
{ NULL }
};
-AVFilter avfilter_vf_setpts = {
+AVFilter ff_vf_setpts = {
.name = "setpts",
.description = NULL_IF_CONFIG_SMALL("Set PTS for the output video frame."),
.init = init,
{ NULL }
};
-AVFilter avfilter_af_asetpts = {
+AVFilter ff_af_asetpts = {
.name = "asetpts",
.description = NULL_IF_CONFIG_SMALL("Set PTS for the output audio frame."),
.init = init,