[FFmpeg-devel] [PATCH] libavfilter/af_atempo: offset output frames' pts by first_frame_pts / tempo
Paweł Wegner
pawel.wegner95 at gmail.com
Thu Jan 24 14:42:03 EET 2019
Signed-off-by: Paweł Wegner <pawel.wegner95 at gmail.com>
---
libavfilter/af_atempo.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
index bfdad7d76b..1245eae8c1 100644
--- a/libavfilter/af_atempo.c
+++ b/libavfilter/af_atempo.c
@@ -147,6 +147,8 @@ typedef struct ATempoContext {
uint8_t *dst_end;
uint64_t nsamples_in;
uint64_t nsamples_out;
+
+ int64_t first_frame_pts;
} ATempoContext;
#define YAE_ATEMPO_MIN 0.5
@@ -994,6 +996,7 @@ static av_cold int init(AVFilterContext *ctx)
ATempoContext *atempo = ctx->priv;
atempo->format = AV_SAMPLE_FMT_NONE;
atempo->state = YAE_LOAD_FRAGMENT;
+ atempo->first_frame_pts = AV_NOPTS_VALUE;
return 0;
}
@@ -1069,6 +1072,7 @@ static int push_samples(ATempoContext *atempo,
// adjust the PTS:
atempo->dst_buffer->pts =
+ (atempo->first_frame_pts == AV_NOPTS_VALUE ? 0 : atempo->first_frame_pts / atempo->tempo) +
av_rescale_q(atempo->nsamples_out,
(AVRational){ 1, outlink->sample_rate },
outlink->time_base);
@@ -1108,6 +1112,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *src_buffer)
atempo->dst = atempo->dst_buffer->data[0];
atempo->dst_end = atempo->dst + n_out * atempo->stride;
+
+ if (atempo->first_frame_pts == AV_NOPTS_VALUE)
+ atempo->first_frame_pts = av_rescale_q(atempo->dst_buffer->pts,
+ inlink->time_base,
+ outlink->time_base);
}
yae_apply(atempo, &src, src_end, &atempo->dst, atempo->dst_end);
--
2.17.1
More information about the ffmpeg-devel
mailing list