forked from zergon321/reisen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe.go
39 lines (33 loc) · 931 Bytes
/
frame.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package reisen
// #cgo pkg-config: libavutil libavformat libavcodec libswscale
// #include <libavcodec/avcodec.h>
// #include <libavformat/avformat.h>
// #include <libavutil/avutil.h>
// #include <libavutil/imgutils.h>
// #include <libswscale/swscale.h>
// #include <inttypes.h>
import "C"
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))
}