-
Notifications
You must be signed in to change notification settings - Fork 45
/
display_matrix.go
50 lines (42 loc) · 1.22 KB
/
display_matrix.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
47
48
49
50
package astiav
//#include <libavutil/display.h>
import "C"
import (
"encoding/binary"
"fmt"
"unsafe"
)
// https://ffmpeg.org/doxygen/7.0/group__lavu__video__display.html
type DisplayMatrix [9]uint32
func NewDisplayMatrixFromBytes(b []byte) (m *DisplayMatrix, err error) {
// Check length
if len(b) < 36 {
err = fmt.Errorf("astiav: invalid length %d < 36", len(b))
return
}
// Create display matrix
m = &DisplayMatrix{}
// Loop
for idx := 0; idx < 9; idx++ {
m[idx] = binary.LittleEndian.Uint32(b[idx*4 : (idx+1)*4])
}
return
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__video__display.html#ga5964303bfe085ad33683bc2454768d4a
func NewDisplayMatrixFromRotation(angle float64) *DisplayMatrix {
m := &DisplayMatrix{}
C.av_display_rotation_set((*C.int32_t)(unsafe.Pointer(&m[0])), C.double(angle))
return m
}
func (m DisplayMatrix) Bytes() []byte {
b := make([]byte, 0, 36)
for _, v := range m {
b = binary.LittleEndian.AppendUint32(b, v)
}
return b
}
// Rotation is a clockwise angle
// https://ffmpeg.org/doxygen/7.0/group__lavu__video__display.html#gaac2ea94d3f66496c758349450b5b0217
func (m DisplayMatrix) Rotation() float64 {
return -float64(C.av_display_rotation_get((*C.int32_t)(unsafe.Pointer(&m[0]))))
}