-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
93 lines (54 loc) · 2.8 KB
/
doc.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Package fourcc is a Go implementation of FOURCC (four character code) (4CC) identifiers for a video codecs, compression formats, colors, and pixel format used in media files.
Introduction
FOURCC, also sometimes written as FourCC and 4CC, are all short for “four character code”.
FOURCC, is a sequence of 4 8-bit bytes packed into an unsigned 32-bit integer which, uniquely identifies a data format.
(A character in this context is a 1 byte (i.e., 8 bit) value. Thus a FOURCC always takes up exatly 32 bits (i.e., 4 bytes).)
These data formats tend to be video codecs, compression formats, colors, and pixel format used in media files.
Samples
Here are some sample FOURCC.
┏━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Label ┃ Hexadecimal (unsigned integer) ┃
┡━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ PAL8 │ 0x384C4150 │
┼───────┼────────────────────────────────┤
│ VP80 │ 0x30385056 │
┼───────┼────────────────────────────────┤
│ H264 │ 0x34363248 │
┼───────┼────────────────────────────────┤
│ MJPG │ 0x47504A4D │
└───────┴────────────────────────────────┘
The way you can understand how these labels get turned in unsigned integers is, if we consider the FOURCC “PAL8”, then:
ASCII ‘P’ = hexadecimal 0x50
ASCII ‘A’ = hexadecimal 0x41
ASCII ‘L’ = hexadecimal 0x4C
ASCII ‘8’ = hexadecimal 0x38
And then these 8-bit bytes as packed into an unsigned integer in reverse order.
I.e.,:
var value uint32 = (uint32('P') | (uint32('A') << 8) | (uint32('L') << 16) | (uint32('8') << 24))
Examples
Here is an example usage:
var colorspace fourcc.Type = fourcc.FOURCC('P','A','L','8')
Here is a constant:
const (
VP8 = fourcc.Const("VP80")
)
A fourcc.Const needs to be turned into a fourcc.Type before using it. So:
var datum fourcc.Type
var err error
datum, err = VP8.FOURCC()
Some uses of Scan:
var colorspace fourcc.Type
err := colorspace.Scan("PAL8")
And:
var p [4]byte = [4]byte{'P','A','L','8'}
var colorspace fourcc.Type
err := colorspace.Scan(p)
And:
var p []byte = []byte{'P','A','L','8'}
var colorspace fourcc.Type
err := colorspace.Scan(p)
See Also
More information about FOURCC can be found at: https://www.fourcc.org/
*/
package fourcc