jimknopf2
Posts: 1
Joined: Mon Jul 27, 2020 7:39 am

HDMI video input to OpenGL texture PI 4

Tue Jul 28, 2020 12:31 pm

I want to use OpenGL ES vertex and fragment shader to work on HDMI video data received by a TC358743. Which interface or API shall I use to have the fastest transfer of video data to OpenGL ES texture. It runs on a PI 4.

# /boot/config.txt
dtoverlay=vc4-fkms-v3d
dtoverlay=tc358743

# Video source
/dev/video0

# texture initialize
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1920, 1080, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);

# texture update
unsigned char data[1920*1080*3];
read(FileDesc, data, 1920*1080* 3);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1920, 1080, GL_RGB, GL_UNSIGNED_BYTE, data);

The current problem is the slow transfer of each frame to GPU memory with glTexSubImage2D which takes about ~50ms. Can someone please help? Thank you.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9069
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: HDMI video input to OpenGL texture PI 4

Wed Jul 29, 2020 6:58 am

You want to use dmabufs for zero copy between kernel subsystems.
V4L2 has an ioctl VIDIOC_EXPBUF to export the buffer as a dmabuf fd.
eglCreateImageKHR has a way to pass all the dmabuf parameters into EGL, as used in https://github.com/6by9/drm_mmal/blob/x ... mal.c#L476

I suspect that V3D won't import UYVY, but I'd hope it supports BGR3 if you pass DRM_FORMAT_RGB888 via EGL_LINUX_DRM_FOURCC_EXT, but if not then you can pass it through the ISP (either using MMAL or V4L2 M2M on /dev/video12, both of which can support dmabufs) to convert to an acceptable format.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “OpenGLES”