diff --git a/pkg/v4l2/device/device.go b/pkg/v4l2/device/device.go index 27bbf350..7f16fd23 100644 --- a/pkg/v4l2/device/device.go +++ b/pkg/v4l2/device/device.go @@ -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]) diff --git a/pkg/v4l2/device/formats.go b/pkg/v4l2/device/formats.go index 94d12504..fb54bbd1 100644 --- a/pkg/v4l2/device/formats.go +++ b/pkg/v4l2/device/formats.go @@ -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 diff --git a/pkg/v4l2/producer.go b/pkg/v4l2/producer.go index b979d346..87199762 100644 --- a/pkg/v4l2/producer.go +++ b/pkg/v4l2/producer.go @@ -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 } diff --git a/pkg/y4m/README.md b/pkg/y4m/README.md index 6f4d863e..ff97813b 100644 --- a/pkg/y4m/README.md +++ b/pkg/y4m/README.md @@ -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