Update about packed and planar YUV formats

This commit is contained in:
Alex X
2025-01-10 15:01:01 +03:00
parent 7dc9beb171
commit 83907132b5
4 changed files with 19 additions and 5 deletions

View File

@@ -196,7 +196,7 @@ func (d *Device) StreamOff() (err error) {
return ioctl(d.fd, VIDIOC_REQBUFS, unsafe.Pointer(&rb))
}
func (d *Device) Capture(cositedYUV bool) ([]byte, error) {
func (d *Device) Capture(planarYUV bool) ([]byte, error) {
dec := v4l2_buffer{
typ: V4L2_BUF_TYPE_VIDEO_CAPTURE,
memory: V4L2_MEMORY_MMAP,
@@ -206,7 +206,7 @@ func (d *Device) Capture(cositedYUV bool) ([]byte, error) {
}
buf := make([]byte, dec.bytesused)
if cositedYUV {
if planarYUV {
YUYV2YUV(buf, d.bufs[dec.index][:dec.bytesused])
} else {
copy(buf, d.bufs[dec.index][:dec.bytesused])

View File

@@ -16,7 +16,7 @@ var Formats = []Format{
{V4L2_PIX_FMT_MJPEG, "Motion-JPEG", "mjpeg"},
}
// YUYV2YUV convert [Y0 Cb Y1 Cr] to cosited [Y0Y1... Cb... Cr...]
// YUYV2YUV convert packed YUV to planar YUV
func YUYV2YUV(dst, src []byte) {
n := len(src)
i0 := 0

View File

@@ -93,10 +93,10 @@ func (c *Producer) Start() error {
return err
}
cositedYUV := c.Medias[0].Codecs[0].Name == core.CodecRAW
planarYUV := c.Medias[0].Codecs[0].Name == core.CodecRAW
for {
buf, err := c.dev.Capture(cositedYUV)
buf, err := c.dev.Capture(planarYUV)
if err != nil {
return err
}

View File

@@ -1,5 +1,19 @@
## Planar YUV formats
Packed YUV - yuyv422 - YUYV 4:2:2
Semi-Planar - nv12 - Y/CbCr 4:2:0
Planar YUV - yuv420p - Planar YUV 4:2:0 - aka. [cosited](https://manned.org/yuv4mpeg.5)
```
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : yuyv422 : YUYV 4:2:2 : 1920x1080
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : nv12 : Y/CbCr 4:2:0 : 1920x1080
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : yuv420p : Planar YUV 4:2:0 : 1920x1080
```
## Useful links
- https://learn.microsoft.com/en-us/windows/win32/medfound/recommended-8-bit-yuv-formats-for-video-rendering
- https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_concepts
- https://fourcc.org/yuv.php#YV12
- https://docs.kernel.org/userspace-api/media/v4l/pixfmt-yuv-planar.html
- https://gist.github.com/Jim-Bar/3cbba684a71d1a9d468a6711a6eddbeb