From fe92e79efc76a625b83516b0b60ec7ad8e7ab574 Mon Sep 17 00:00:00 2001 From: Adrian Shum Date: Sat, 22 Oct 2022 09:53:42 +0800 Subject: [PATCH] feat(ffmpeg): select frame by duration and float position --- ffmpeg/ffmpeg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index 006008e..b3cec57 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -106,6 +106,7 @@ func (av *AVContext) SelectPosition(f float64) (err error) { func (av *AVContext) SelectDuration(ts time.Duration) (err error) { if ts > 0 { + av.selectedDuration = ts if err = seekDuration(av, ts); err != nil { return } @@ -227,7 +228,6 @@ func createDecoder(av *AVContext) error { } func seekDuration(av *AVContext, ts time.Duration) error { - av.selectedDuration = ts tts := C.int64_t(ts.Milliseconds()) * C.AV_TIME_BASE / 1000 err := C.av_seek_frame(av.formatContext, C.int(-1), tts, C.AVSEEK_FLAG_BACKWARD) C.avcodec_flush_buffers(av.codecContext)