Files
reisen/frame.go
2021-08-27 00:53:42 +00:00

31 lines
654 B
Go

package reisen
import (
"fmt"
"time"
)
// Frame is an abstract data frame.
type Frame interface {
Data() []byte
PresentationOffset() (time.Duration, error)
}
// baseFrame contains the information
// common for all frames of any type.
type baseFrame struct {
stream Stream
pts int64
}
// PresentationOffset returns the duration offset
// since the start of the media at which the frame
// should be played.
func (frame *baseFrame) PresentationOffset() (time.Duration, error) {
tbNum, tbDen := frame.stream.TimeBase()
tb := float64(tbNum) / float64(tbDen)
tm := float64(frame.pts) * tb
return time.ParseDuration(fmt.Sprintf("%fs", tm))
}