Skip to content

Commit 8390713

Browse files
committed
Update about packed and planar YUV formats
1 parent 7dc9beb commit 8390713

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

pkg/v4l2/device/device.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (d *Device) StreamOff() (err error) {
196196
return ioctl(d.fd, VIDIOC_REQBUFS, unsafe.Pointer(&rb))
197197
}
198198

199-
func (d *Device) Capture(cositedYUV bool) ([]byte, error) {
199+
func (d *Device) Capture(planarYUV bool) ([]byte, error) {
200200
dec := v4l2_buffer{
201201
typ: V4L2_BUF_TYPE_VIDEO_CAPTURE,
202202
memory: V4L2_MEMORY_MMAP,
@@ -206,7 +206,7 @@ func (d *Device) Capture(cositedYUV bool) ([]byte, error) {
206206
}
207207

208208
buf := make([]byte, dec.bytesused)
209-
if cositedYUV {
209+
if planarYUV {
210210
YUYV2YUV(buf, d.bufs[dec.index][:dec.bytesused])
211211
} else {
212212
copy(buf, d.bufs[dec.index][:dec.bytesused])

pkg/v4l2/device/formats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var Formats = []Format{
1616
{V4L2_PIX_FMT_MJPEG, "Motion-JPEG", "mjpeg"},
1717
}
1818

19-
// YUYV2YUV convert [Y0 Cb Y1 Cr] to cosited [Y0Y1... Cb... Cr...]
19+
// YUYV2YUV convert packed YUV to planar YUV
2020
func YUYV2YUV(dst, src []byte) {
2121
n := len(src)
2222
i0 := 0

pkg/v4l2/producer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ func (c *Producer) Start() error {
9393
return err
9494
}
9595

96-
cositedYUV := c.Medias[0].Codecs[0].Name == core.CodecRAW
96+
planarYUV := c.Medias[0].Codecs[0].Name == core.CodecRAW
9797

9898
for {
99-
buf, err := c.dev.Capture(cositedYUV)
99+
buf, err := c.dev.Capture(planarYUV)
100100
if err != nil {
101101
return err
102102
}

pkg/y4m/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
## Planar YUV formats
2+
3+
Packed YUV - yuyv422 - YUYV 4:2:2
4+
Semi-Planar - nv12 - Y/CbCr 4:2:0
5+
Planar YUV - yuv420p - Planar YUV 4:2:0 - aka. [cosited](https://manned.org/yuv4mpeg.5)
6+
7+
```
8+
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : yuyv422 : YUYV 4:2:2 : 1920x1080
9+
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : nv12 : Y/CbCr 4:2:0 : 1920x1080
10+
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : yuv420p : Planar YUV 4:2:0 : 1920x1080
11+
```
12+
113
## Useful links
214

315
- https://learn.microsoft.com/en-us/windows/win32/medfound/recommended-8-bit-yuv-formats-for-video-rendering
416
- https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_concepts
517
- https://fourcc.org/yuv.php#YV12
18+
- https://docs.kernel.org/userspace-api/media/v4l/pixfmt-yuv-planar.html
19+
- https://gist.github.com/Jim-Bar/3cbba684a71d1a9d468a6711a6eddbeb

0 commit comments

Comments
 (0)