102
102
#define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
103
103
#define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
105
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
105
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
107
107
SetPTSContext *setpts = inlink->dst->priv;
108
int64_t in_pts = frame->pts;
109
AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
112
return AVERROR(ENOMEM);
114
111
if (isnan(setpts->var_values[VAR_STARTPTS]))
115
setpts->var_values[VAR_STARTPTS] = TS2D(inpicref->pts);
112
setpts->var_values[VAR_STARTPTS] = TS2D(frame->pts);
117
setpts->var_values[VAR_INTERLACED] = inpicref->video->interlaced;
118
setpts->var_values[VAR_PTS ] = TS2D(inpicref->pts);
119
setpts->var_values[VAR_POS ] = inpicref->pos == -1 ? NAN : inpicref->pos;
114
setpts->var_values[VAR_INTERLACED] = frame->video->interlaced;
115
setpts->var_values[VAR_PTS ] = TS2D(frame->pts);
116
setpts->var_values[VAR_POS ] = frame->pos == -1 ? NAN : frame->pos;
121
118
d = av_expr_eval(setpts->expr, setpts->var_values, NULL);
122
outpicref->pts = D2TS(d);
119
frame->pts = D2TS(d);
125
122
av_log(inlink->dst, AV_LOG_DEBUG,
126
123
"n:%"PRId64" interlaced:%d pos:%"PRId64" pts:%"PRId64" t:%f -> pts:%"PRId64" t:%f\n",
127
124
(int64_t)setpts->var_values[VAR_N],
128
125
(int)setpts->var_values[VAR_INTERLACED],
130
inpicref ->pts, inpicref ->pts * av_q2d(inlink->time_base),
131
outpicref->pts, outpicref->pts * av_q2d(inlink->time_base));
126
frame->pos, in_pts, in_pts * av_q2d(inlink->time_base),
127
frame->pts, frame->pts * av_q2d(inlink->time_base));
134
131
setpts->var_values[VAR_N] += 1.0;
135
setpts->var_values[VAR_PREV_INPTS ] = TS2D(inpicref ->pts);
136
setpts->var_values[VAR_PREV_OUTPTS] = TS2D(outpicref->pts);
137
return ff_start_frame(inlink->dst->outputs[0], outpicref);
132
setpts->var_values[VAR_PREV_INPTS ] = TS2D(in_pts);
133
setpts->var_values[VAR_PREV_OUTPTS] = TS2D(frame->pts);
134
return ff_filter_frame(inlink->dst->outputs[0], frame);
140
137
static av_cold void uninit(AVFilterContext *ctx)
150
147
.type = AVMEDIA_TYPE_VIDEO,
151
148
.get_video_buffer = ff_null_get_video_buffer,
152
149
.config_props = config_input,
153
.start_frame = start_frame,
150
.filter_frame = filter_frame,