forked from zergon321/reisen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoframe.go
46 lines (39 loc) · 1.11 KB
/
videoframe.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
40
41
42
43
44
45
46
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 "image"
// VideoFrame is a single frame
// of a video stream.
type VideoFrame struct {
baseFrame
img *image.RGBA
}
// Data returns a byte slice of RGBA
// pixels of the frame image.
func (frame *VideoFrame) Data() []byte {
return frame.img.Pix
}
// Image returns the RGBA image of the frame.
func (frame *VideoFrame) Image() *image.RGBA {
return frame.img
}
// newVideoFrame returns a newly created video frame.
func newVideoFrame(stream Stream, pts int64, indCoded, indDisplay, width, height int, pix []byte) *VideoFrame {
upLeft := image.Point{0, 0}
lowRight := image.Point{width, height}
img := image.NewRGBA(image.Rectangle{upLeft, lowRight})
frame := new(VideoFrame)
img.Pix = pix
frame.stream = stream
frame.pts = pts
frame.img = img
frame.indexCoded = indCoded
frame.indexDisplay = indDisplay
return frame
}