Seems to only happen when the video time doesn't perfectly match the mpeg time. For example, the following program works fine if the seek position is 3000*time.Milliseconds, but breaks at 3001 (requires passing the path to the mpeg file as an argument):
package main
import ( "os" ; "log" ; "time" )
import "github.com/gen2brain/mpeg"
func main() {
// open file and initialize mpeg
file, err := os.Open(os.Args[1])
if err != nil { log.Fatal(err) }
mpg, err := mpeg.New(file)
if err != nil { log.Fatal(err) }
mpg.SetAudioCallback(func(_ *mpeg.MPEG, _ *mpeg.Samples) {})
mpg.SetVideoCallback(func(_ *mpeg.MPEG, _ *mpeg.Frame) {})
// seek and print times
ok := mpg.Seek(3001*time.Millisecond, true)
if !ok { log.Fatal("seek not ok") }
log.Printf("mpeg.Time() = %v", mpg.Time())
log.Printf("video.Time() = %v", mpg.Video().Time())
log.Printf("audio.Time() = %v", mpg.Audio().Time())
}
Example output with test.mpg:
2022/11/10 16:53:17 mpeg.Time() = 3.033333333s
2022/11/10 16:53:17 video.Time() = 3.066666666666667
2022/11/10 16:53:17 audio.Time() = 5.758644444444444
Seems to only happen when the video time doesn't perfectly match the mpeg time. For example, the following program works fine if the seek position is
3000*time.Milliseconds, but breaks at 3001 (requires passing the path to the mpeg file as an argument):Example output with
test.mpg: