chris319
Posts: 8
Joined: Fri Dec 08, 2023 7:47 am

Video Level Converter

Fri Dec 08, 2023 7:58 am

Does this project sound feasible on the Raspberry Pi 5?

USB 3.0 video in from a webcam or other camera @ 30p fps

HDMI or USB 3.0 out @ 30p fps

Input video range: 8-bit 0 - 255 "full range"

Output video range: 8-bit 16 - 235 "limited range"

Would libcamera be useful for this?

I have zero experience with Raspberry Pi.

Thank you.

User avatar
neilgl
Posts: 7587
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Video Level Converter

Fri Dec 08, 2023 3:58 pm

Yes. USB webcam input then use gstreamer software to show it on an attached HDMI monitor as in this post viewtopic.php?p=2164439#p2164439
And see other ways of doing it using libcamera and rpicam-vid here https://www.raspberrypi.com/documentati ... tware.html

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

Re: Video Level Converter

Fri Dec 08, 2023 4:47 pm

No need to use libcamera as it isn't a raw sensor.
rpicam-apps are written around the Pi pipeline handlers, and not UVC (for USB Video Class devices).

There's no need to actually change the pixel data at all as the DRM display pipeline driver has properties for full or limited range YCbCr on each plane, and you can control full or limited range on the HDMI output as well. You will need some software to configure the hardware appropriately though.
The one gotcha may be the format that your webcam puts out. Many produce YUYV (or one in the family), and the display pipeline doesn't support that natively. "v4l2-ctl --list-formats-ext" will tell you the formats supported by your webcam.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

chris319
Posts: 8
Joined: Fri Dec 08, 2023 7:47 am

Re: Video Level Converter

Fri Dec 08, 2023 6:16 pm

6by9 wrote:
Fri Dec 08, 2023 4:47 pm
No need to use libcamera as it isn't a raw sensor.
rpicam-apps are written around the Pi pipeline handlers, and not UVC (for USB Video Class devices).

There's no need to actually change the pixel data at all as the DRM display pipeline driver has properties for full or limited range YCbCr on each plane, and you can control full or limited range on the HDMI output as well. You will need some software to configure the hardware appropriately though.
The one gotcha may be the format that your webcam puts out. Many produce YUYV (or one in the family), and the display pipeline doesn't support that natively. "v4l2-ctl --list-formats-ext" will tell you the formats supported by your webcam.
Do you mean "V4L2-ctl --list-formats-ext" lists the webcam formats supported by RaspberryPi?

Do you know of an rpicam app that does what I'm contemplating for this project?

I am still waiting to get my hands on a RPi 5.

Thank you.

User avatar
neilgl
Posts: 7587
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Video Level Converter

Fri Dec 08, 2023 7:51 pm

As 6by9 said,

Code: Select all

v4l2-ctl --list-formats-ext
will show the formats supported by an attached USB webcam. If you run it on a pi where no camera is attached you get

Code: Select all

pi@pi5-4GB:~ $ v4l2-ctl --list-formats-ext
Cannot open device /dev/video0, exiting.

chris319
Posts: 8
Joined: Fri Dec 08, 2023 7:47 am

Re: Video Level Converter

Fri Dec 08, 2023 10:42 pm

neilgl wrote:
Fri Dec 08, 2023 7:51 pm
As 6by9 said,

Code: Select all

v4l2-ctl --list-formats-ext
will show the formats supported by an attached USB webcam. If you run it on a pi where no camera is attached you get

Code: Select all

pi@pi5-4GB:~ $ v4l2-ctl --list-formats-ext
Cannot open device /dev/video0, exiting.
This implies that the properties of the attached camera must be known to the programmer. If different cameras require different coding then it becomes impossible to make a generic, one-size-fits-all converter for any possible camera, am I correct? This wouldn't be a problem if I were coding for one specific model of camera, but a one-size-fits-all solution is what I had in mind. I'll have to rethink this.

Thank you.

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

Re: Video Level Converter

Sat Dec 09, 2023 11:01 am

There is no one format that absolutely every v4l2 device will support.

Almost all of the usb2 uvc devices support yuyv as it needs no context memory in the hardware due to only being horizontally subsampled, but often it is at limited framerate due to bandwidth limits (720p60 as yuyv is 884Mbit/s, but usb2 has a max of 480Mbit/s). They therefore support mjpeg as well.
Usb3 obviously gives you more bandwidth, but 1080p60 is nearly 2Gbit/s which is a lot to shovel around.

Your easiest solution may be to look at using Gstreamer to do the conversion as it has numerous format conversions.
Rereading your original post, are you wanting the 16-235 image data in memory or on the hdmi display? I'd read the latter.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
neilgl
Posts: 7587
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Video Level Converter

Sat Dec 09, 2023 3:33 pm

Hmmm, "one-size-fits-all converter for any possible camera" would be very ambitious - could I connect my Canon EOS 90D USB output to it?
Anyway, my cheapo USB webcam has (details cut down) has various modes (at various resolutions):

Code: Select all

	[0]: 'MJPG' (Motion-JPEG, compressed)
	[1]: 'YUYV' (YUYV 4:2:2)
	[2]: 'H264' (H.264, compressed)
Whereas the expensive Logitech C920 USB camera does not have H264:

Code: Select all

	[0]: 'YUYV' (YUYV 4:2:2)
	[1]: 'MJPG' (Motion-JPEG, compressed)
So maybe just handle those common ones.

chris319
Posts: 8
Joined: Fri Dec 08, 2023 7:47 am

Re: Video Level Converter

Sun Dec 10, 2023 1:42 am

6by9 wrote:
Sat Dec 09, 2023 11:01 am
Rereading your original post, are you wanting the 16-235 image data in memory or on the hdmi display? I'd read the latter.
Either HDMI or USB 3.0 output for interfacing with other studio equipment such as switchers.

Due to the potential compatibility issues, I may just focus on making a camera with the hi-quality sensor.

chris319
Posts: 8
Joined: Fri Dec 08, 2023 7:47 am

Re: Video Level Converter

Sun Dec 10, 2023 3:24 pm

ffmpeg to the rescue!

I was able to discern the caps of an HDMI to USB adapter that I use with my camera (Elgato Cam Link 4K):

Code: Select all

[dshow @ 0000018e3a66ef40]   pixel_format=yuyv422  min s=1920x1080 fps=29.97 max s=1920x1080 fps=29.97 (tv, bt709/bt709/unknown, topleft)
It's a start. Pixel format is yuyv 422.

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

Re: Video Level Converter

Sun Dec 10, 2023 8:07 pm

chris319 wrote:
Sun Dec 10, 2023 3:24 pm
ffmpeg to the rescue!

I was able to discern the caps of an HDMI to USB adapter that I use with my camera (Elgato Cam Link 4K):

Code: Select all

[dshow @ 0000018e3a66ef40]   pixel_format=yuyv422  min s=1920x1080 fps=29.97 max s=1920x1080 fps=29.97 (tv, bt709/bt709/unknown, topleft)
It's a start. Pixel format is yuyv 422.
That's told you less than "v4l2-ctl --list-formats-ext" would have done.
On my laptop here it tells you all the supported resolutions and frame rates for each mode

Code: Select all

~$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Type: Video Capture

	[0]: 'YUYV' (YUYV 4:2:2)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 160x120
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 176x144
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 320x240
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 352x288
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.100s (10.000 fps)
	[1]: 'MJPG' (Motion-JPEG, compressed)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 160x120
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 176x144
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 320x240
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 352x288
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)
Being USB2 it is limited to 10fps at 720p in YUYV, but can do 30fps as MJPEG.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Graphics, sound and multimedia”