rebble
Posts: 3
Joined: Sat Nov 11, 2017 7:12 pm

Getting the most out of your V2 camera with UV4L.

Mon Nov 13, 2017 2:02 pm

I've recently purchased the Pi Camera V2 after reading lots of mixed reviews. Some people saying it's an amazing piece of kit, other people warning others to steer well clear and to stick with the V1.
Personally I think it's an absolute quality little camera and the detail it can output is astonishing (for £25).

The main purpose of my project was to have a simple streaming webcam/camera looking out my front window, accessible whenever I want to view it.
I was previously using Motion with a webcam (c920 if you're interested), but as with all webcams they are not meant for focusing on distant objects and often give a blur on the peripheral of the outputted image due to the nature of their lenses curvatures.

Then I discovered the Pi Camera (the V2 to be more specific), although trying to use this camera with Motion proved to be an absolute nightmare. I'm not sure if the settings/commands Motion uses with the picamera are out of date but nothing seemed to be working. And don't even get me started on auto Exposure settings.
So I did a bit of research for alternatives and found ffmpeg, which seemed to be very complicated to set up, and UV4L/UV4l-raspicam, which seemed to be fairly simple, comparable with motion.

Editing the .conf file was a pretty easy and I was set up with my pi camera outputting h.264 1920x1080 video, AND, everything looked great. Auto exposure was finally working and the image was CRISP. One thing I did notice was that the image was really really cropped, almost like a 2x digital zoom. It wasn't using the full frame field of view.
After a LOT of research I've discovered that there are many "modes" that the camera can output, and quite a few of them are cropped, including 1920x1080. I think a lot of people are confused by these modes and aren't sure exactly what they do.

On the V2 camera the main important output modes are:
1. 1920x1080 16:9 30fps max- Cropped,
2. 3280x2464 4:3 8MP 15fps max - Full FOV,
3. 3280x2464 4:3 8MP 15fps max - Full FOV,
4. 1640x1232 4:3 2×2 binned 40fps max - Full FOV,
5. 1640x922 16:9 2×2 binned 40fps max - Full FOV,
6. 1280×720 16:9 40-90fps mode - Cropped,
7. 640×480 4:3 40-90fps mode - Cropped.


Image

As you can see from the image above from the Pi Camera Documentation page 1080p mode is VERY cropped and as there's no pixel binning, so it's effectively using a 2MP section of an 8MP sensor to take photo/video..... not ideal (unless a narrow FOV is what you're after)

In UV4L-raspicam config (/etc/uv4l/uv4l-raspicam.conf) file there is an option to set resolution and the sensor output mode. Setting these options correctly is VITAL to obtaining the FOV you want. The settings I chose are mentioned below.

encoding = h264
width = 1640
height = 1232
framerate = 4
custom-sensor-config = 4

*for some reason I had to delete the "pound" (#) symbol from before the command text on each line that I changed. It was ignoring me otherwise.

This gave me full FOV and a crystal clear image. If you are thinking of streaming the video constantly then also change the bitrate down. Way down. I turned mine down to 2Mbps (bitrate = 2000000). This put a LOT less strain on the processor while making much less video data to upload constantly. Detail loss was negligible.

One last thing I did was make sure exposure = auto, ISO = 0 (zero ISO means auto) and drc = medium which reduces contrast in situations with a lot of light and dark areas, producing a more dynamic image.

Here are some screenshots taken from a browser streaming the video (not photos, video!) via interwebs, images have been halved in resolution as this forum doesnt take images larger than 1000px. Seeing as this is on-the-fly over-the-web streamed h.264 video I think it looks pretty decent.
morning2.jpg
morning2.jpg (94.64 KiB) Viewed 10780 times
midday2.jpg
midday2.jpg (70.46 KiB) Viewed 10780 times
Hope this helps some people out.

RpiName
Posts: 707
Joined: Sat Jul 06, 2013 3:14 am

Re: Getting the most out of your V2 camera with UV4L.

Mon Nov 13, 2017 3:35 pm

Thanks, this is really helpful.
rebble wrote:
Mon Nov 13, 2017 2:02 pm
*for some reason I had to delete the "pound" (#) symbol from before the command text on each line that I changed. It was ignoring me otherwise.
Any text after # (in the same line) is a comment

rebble
Posts: 3
Joined: Sat Nov 11, 2017 7:12 pm

Re: Getting the most out of your V2 camera with UV4L.

Mon Nov 13, 2017 7:11 pm

That's exactly what I thought, as I'm used to coding in C/C++ but for some of the options mentioned above it does not seem to make any difference, which I thought was odd, and thought I should mention.

RpiName
Posts: 707
Joined: Sat Jul 06, 2013 3:14 am

Re: Getting the most out of your V2 camera with UV4L.

Mon Nov 13, 2017 7:22 pm

rebble wrote:
Mon Nov 13, 2017 7:11 pm
That's exactly what I thought, as I'm used to coding in C/C++ but for some of the options mentioned above it does not seem to make any difference, which I thought was odd, and thought I should mention.
note that not every commented out option in the config file has necessarily the same value as the built-in default. For the default values, when not overridden by the config file, see "man raspicam" or run "uv4l --driver raspicam --driver-help" from command line.

Misirlou
Posts: 7
Joined: Fri Sep 29, 2017 11:54 pm

Re: Getting the most out of your V2 camera with UV4L.

Thu Dec 14, 2017 5:13 pm

How is it that you were able to remove the "software by http://linux.project.org" watermark from the video?

As far as I can tell, UV4L is commercial, proprietary software, for which you need to purchase a licence (which I was unsuccessful in doing, as they never answered my inquiries). The version you can download from their website is a "free demo" with a non-removable watermark. See this topic: viewtopic.php?f=43&t=194246

No offense, but it seems odd that you only have two posts to your name, which consist of a highly detailed and promotional-sounding essay about UV4L - and no mention about the licence, or the code to remove the watermark, which you seem to be in possession of. Do you have some kind of financial interest in the software?

sparkie777
Posts: 120
Joined: Tue Nov 27, 2012 4:37 am

Re: Getting the most out of your V2 camera with UV4L.

Fri Dec 15, 2017 10:00 am

rebble wrote:
Mon Nov 13, 2017 2:02 pm
Then I discovered the Pi Camera (the V2 to be more specific), although trying to use this camera with Motion proved to be an absolute nightmare. I'm not sure if the settings/commands Motion uses with the picamera are out of date but nothing seemed to be working.
haven't you read the manuals?

1.) motion detect even runs across the network like a charm. It's just as easy as saying (sample only)

on server:

Code: Select all

/usr/local/bin/mjpg_streamer -o output_http.so -w ./www -i input_raspicam.so -x 1920 -y 1440 -fps 3
on client:

Code: Select all

/etc/motion/motion.conf:
[...]
netcam_url http://<rpi-ip-address>:8080/?action=stream
[...]
2.) h264es streaming across the network (sample only)

on server:

Code: Select all

raspivid -v -a 524 -a 4 -a "rpi-0 %Y-%m-%d %X" -fps 15 -n -md 2 -ih -t 0 -l -o tcp://0.0.0.0:5001
on client:

Code: Select all

mplayer -nostop-xscreensaver -nolirc -fps 15 -vo xv -vf rotate=2,screenshot -xy 1200 -demuxer h264es ffmpeg://tcp://<rpi-ip-address>:5001
3.) mjpeg streaming across the network (sample only)

on server:
same as in 1.)

on client:

Code: Select all

mplayer -nostop-xscreensaver -nolirc -fps 15 -vo xv -vf rotate=2,screenshot -xy 1200 -demuxer lavf http://<rpi-ip-address>:8080/?action=stream

alternatively stream to a web browser:

firefox 'http://<rpi-ip-address>:8080/?action=stream'


to save the best for last:

- works even on my RPi ZERO W (configured as the cam server of course)
- all without commercial bloatware
Last edited by sparkie777 on Sun Dec 17, 2017 12:26 pm, edited 4 times in total.

RpiName
Posts: 707
Joined: Sat Jul 06, 2013 3:14 am

Re: Getting the most out of your V2 camera with UV4L.

Fri Dec 15, 2017 10:55 am

Misirlou wrote:
Thu Dec 14, 2017 5:13 pm
How is it that you were able to remove the "software by http://linux.project.org" watermark from the video?
There is no watermark for what the OP is doing. The watermark is only present when using some peculiar features of the Streaming Server like WebRTC and can be disabled for free - contact the authors mentioning what private or public project you are using UV4L for.

Misirlou
Posts: 7
Joined: Fri Sep 29, 2017 11:54 pm

Re: Getting the most out of your V2 camera with UV4L.

Fri Dec 15, 2017 11:27 pm

Ok, I didn't realize the watermark was on some things and not others. I followed the uv4l installation instructions to install and test by manually taking a jpeg (dd if=/dev/video0 of=snapshot.jpeg bs=11M count=1), and it had the watermark. Then I went to the uv4l server page, and tried the "two-way audio/video" (WebRTC), and the "delayed snapshot", and they both had the watermark. So I assumed it was built into /dev/video0. I did try the tutorials for RTSP and HTTP servers with VLC, but they didn't work for me (crashed my Raspberry Pi, and/or just showed a black screen on VLC on my Mac). That's why I thought that the OP was somehow able to bypass the watermark. I did try to contact the authors, but they didn't answer my e-mail.

Misirlou
Posts: 7
Joined: Fri Sep 29, 2017 11:54 pm

Re: Getting the most out of your V2 camera with UV4L.

Fri Dec 15, 2017 11:51 pm

What I don't understand then, is how the OP got H.264 streaming in a browser. All he says is:
Editing the .conf file was a pretty easy and I was set up with my pi camera outputting h.264 1920x1080 video [...] Here are some screenshots taken from a browser streaming the video (not photos, video!) via interwebs
There seems to be some kind of magic missing in the middle there, because as far as I understood, you can't stream H.264 to a browser, only to VLC. That's why I wanted to use WebRTC, and thought the OP was too. What am I missing?

Seneral
Posts: 4
Joined: Sun Nov 11, 2018 5:52 pm

Re: Getting the most out of your V2 camera with UV4L.

Fri Dec 07, 2018 12:39 pm

rebble wrote:
Mon Nov 13, 2017 2:02 pm
...

In UV4L-raspicam config (/etc/uv4l/uv4l-raspicam.conf) file there is an option to set resolution and the sensor output mode. Setting these options correctly is VITAL to obtaining the FOV you want. The settings I chose are mentioned below.

encoding = h264
width = 1640
height = 1232
framerate = 4
custom-sensor-config = 4

*for some reason I had to delete the "pound" (#) symbol from before the command text on each line that I changed. It was ignoring me otherwise.

This gave me full FOV and a crystal clear image. If you are thinking of streaming the video constantly then also change the bitrate down. Way down. I turned mine down to 2Mbps (bitrate = 2000000). This put a LOT less strain on the processor while making much less video data to upload constantly. Detail loss was negligible.

One last thing I did was make sure exposure = auto, ISO = 0 (zero ISO means auto) and drc = medium which reduces contrast in situations with a lot of light and dark areas, producing a more dynamic image.

...

Hope this helps some people out.
Can you explain how you got the 1640x1232 video to work?
The driver raspicam always throws a warning "Invalid height: max. for specified encoding is 1080" and crops to 1640x1080. I tried with additional parameters like "--profile high --level 4.2 --custom-sensor-config 4" aswell but no change.

At this point I'm simply using raspivid it seems, works flawless out of the box and even with high quality video in that format I can't get it over 20% CPU usage (on a standard RPi Zero!). With some consideration just over 10% is normal.

It just occurs odd to me that everywhere uv4l seems to be recommended over raspivid and raspivid is portrayed as slower, whereas in reality uv4l doesn't even work as expected. I really do hope I can get it to work though so I can compare them and choose the right for my task.

RpiName
Posts: 707
Joined: Sat Jul 06, 2013 3:14 am

Re: Getting the most out of your V2 camera with UV4L.

Fri Dec 07, 2018 1:39 pm

Seneral wrote:
Fri Dec 07, 2018 12:39 pm
Can you explain how you got the 1640x1232 video to work?
The driver raspicam always throws a warning "Invalid height: max. for specified encoding is 1080" and crops to 1640x1080. I tried with additional parameters like "--profile high --level 4.2 --custom-sensor-config 4" aswell but no change.
With WebRTC you can get 1640x1232 video from the UV4L streaming server (because it in turn configures the device appropriately). On the other hand, when you capture the H264 video accessing the device node directly the resolution height is limited to 1080.

Seneral
Posts: 4
Joined: Sun Nov 11, 2018 5:52 pm

Re: Getting the most out of your V2 camera with UV4L.

Fri Dec 07, 2018 5:16 pm

RpiName wrote:
Fri Dec 07, 2018 1:39 pm
Seneral wrote:
Fri Dec 07, 2018 12:39 pm
Can you explain how you got the 1640x1232 video to work?
The driver raspicam always throws a warning "Invalid height: max. for specified encoding is 1080" and crops to 1640x1080. I tried with additional parameters like "--profile high --level 4.2 --custom-sensor-config 4" aswell but no change.
With WebRTC you can get 1640x1232 video from the UV4L streaming server (because it in turn configures the device appropriately). On the other hand, when you capture the H264 video accessing the device node directly the resolution height is limited to 1080.
Hm that's a bummer. As I do not intend to use the streaming server but a different streaming solution (WifiBroadcast) I'll continue using raspivid. So far I have not stumbled upon the roadblocks I expected with raspivid, am I missing something? Everywhere I see "quickly dumped raspicam because it was not giving me the framerates I required" and stuff...

Return to “Camera board”