Skip to content

Commit 0e5f82e

Browse files
committed
Correct NOPT timestamps
1 parent a53e20a commit 0e5f82e

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

ffmpeg/filter.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,26 @@ int filtergraph_write(AVFrame *inf, struct input_ctx *ictx, struct output_ctx *o
334334
// Timestamp handling code
335335
AVStream *vst = ictx->ic->streams[ictx->vi];
336336
if (inf) { // Non-Flush Frame
337-
inf->opaque = (void *) inf->pts; // Store original PTS for calc later
337+
if (is_video) {
338+
int64_t pts = inf->pts;
339+
if (pts == AV_NOPTS_VALUE) pts = inf->best_effort_timestamp;
340+
if (pts == AV_NOPTS_VALUE && ictx->segment_pts_samples > 0) {
341+
int64_t step = inf->duration;
342+
if (!step && vst->r_frame_rate.den){
343+
step = av_rescale_q(1, av_inv_q(vst->r_frame_rate), vst->time_base);
344+
}
345+
if (step){
346+
pts = ictx->segment_last_pts + step;
347+
}
348+
}
349+
inf->opaque = (void *)pts;
350+
inf->pts = pts;
351+
} else {
352+
inf->opaque = (void *) inf->pts;
353+
}
354+
if (inf->pts == AV_NOPTS_VALUE) {
355+
av_log(NULL, AV_LOG_WARNING, "Filter frame pts is AV_NOPTS_VALUE\n");
356+
}
338357
if (is_video && octx->fps.den) {
339358
// Custom PTS set when FPS filter is used
340359
int64_t ts_step = inf->pts - filter->prev_frame_pts;
@@ -366,7 +385,7 @@ int filtergraph_write(AVFrame *inf, struct input_ctx *ictx, struct output_ctx *o
366385

367386
if (inf) {
368387
// Apply the custom pts, then reset for the next output
369-
int64_t old_pts = inf->pts;
388+
int64_t old_pts = inf->pts;ts;
370389
inf->pts = filter->custom_pts;
371390
ret = av_buffersrc_write_frame(filter->src_ctx, inf);
372391
inf->pts = old_pts;

0 commit comments

Comments
 (0)