On Thu, Jan 24, 2019 at 3:43 PM Pavel Koshevoy <pkoshe...@gmail.com> wrote:
> On Thu, Jan 24, 2019 at 5:49 AM Paweł Wegner <pawel.wegne...@gmail.com> > wrote: > > > > Signed-off-by: Paweł Wegner <pawel.wegne...@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 > > > > > Probably okay. The reason I didn't do this to begin with is because > this is an audio stream filter... and how the timeline of the stream > was transformed up to the 1st frame is unknown. You are making the > assumption that it should have been transformed using the same tempo > parameter as current tempo, but (video) tempo can be varied at runtime > prior to 1st audio frame, so pts_0' = pts_0 / tempo could be wrong. > > Anyway, I don't have a use case where this change would break > something, so if this fixes something for you then it's fine. This fixes seeking when I have video playback sped up in ffplay like this: ffplay -vf "setpts=0.5 * PTS" -af "atempo=2" input > > Pavel. > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel