mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-26 20:31:11 +08:00
Update about packed and planar YUV formats
This commit is contained in:
@@ -196,7 +196,7 @@ func (d *Device) StreamOff() (err error) {
|
|||||||
return ioctl(d.fd, VIDIOC_REQBUFS, unsafe.Pointer(&rb))
|
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{
|
dec := v4l2_buffer{
|
||||||
typ: V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
typ: V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
||||||
memory: V4L2_MEMORY_MMAP,
|
memory: V4L2_MEMORY_MMAP,
|
||||||
@@ -206,7 +206,7 @@ func (d *Device) Capture(cositedYUV bool) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, dec.bytesused)
|
buf := make([]byte, dec.bytesused)
|
||||||
if cositedYUV {
|
if planarYUV {
|
||||||
YUYV2YUV(buf, d.bufs[dec.index][:dec.bytesused])
|
YUYV2YUV(buf, d.bufs[dec.index][:dec.bytesused])
|
||||||
} else {
|
} else {
|
||||||
copy(buf, d.bufs[dec.index][:dec.bytesused])
|
copy(buf, d.bufs[dec.index][:dec.bytesused])
|
||||||
|
@@ -16,7 +16,7 @@ var Formats = []Format{
|
|||||||
{V4L2_PIX_FMT_MJPEG, "Motion-JPEG", "mjpeg"},
|
{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) {
|
func YUYV2YUV(dst, src []byte) {
|
||||||
n := len(src)
|
n := len(src)
|
||||||
i0 := 0
|
i0 := 0
|
||||||
|
@@ -93,10 +93,10 @@ func (c *Producer) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cositedYUV := c.Medias[0].Codecs[0].Name == core.CodecRAW
|
planarYUV := c.Medias[0].Codecs[0].Name == core.CodecRAW
|
||||||
|
|
||||||
for {
|
for {
|
||||||
buf, err := c.dev.Capture(cositedYUV)
|
buf, err := c.dev.Capture(planarYUV)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -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
|
## Useful links
|
||||||
|
|
||||||
- https://learn.microsoft.com/en-us/windows/win32/medfound/recommended-8-bit-yuv-formats-for-video-rendering
|
- 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://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_concepts
|
||||||
- https://fourcc.org/yuv.php#YV12
|
- 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
|
||||||
|
Reference in New Issue
Block a user