Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picture quality pi zero #4

Closed
magnip opened this issue May 10, 2019 · 30 comments
Closed

Picture quality pi zero #4

magnip opened this issue May 10, 2019 · 30 comments

Comments

@magnip
Copy link

magnip commented May 10, 2019

Hello first off brilliant bit of code. Do you have recommended settings for the pi zero? The picture quality is very grainy and slow fps. Thanks

@magnip
Copy link
Author

magnip commented May 25, 2019

I have ssh into pi zero w and pasted this command.
raspivid -t 0 -b 5000000 -fps 30 -w 1920 -h 1080 -o - | nc -p 1904 -u 192.168.2.108 1234
If you have a hdmi monitor connected the camera video will be shown with excellent quality and very low latency. Rebooted pi by pulling power otherwise pi will freeze with error using sudo reboot.
Opened HomeKit app on iPhone and there is a noticeable improvement. Not as nice as the live view through hdmi but it’s getting there.

@AchimPieters
Copy link

AchimPieters commented May 27, 2019

I also have problems with the quality of the video. i've attached a image so you can see what's the trouble.
best-face-oil
As you can see it grainy. I've tried several raspivid settings but with no better result? can you help me?
The stills are high quality! like this:
best-face-oil

@iMartzen
Copy link

I have ssh into pi zero w and pasted this command.
raspivid -t 0 -b 5000000 -fps 30 -w 1920 -h 1080 -o - | nc -p 1904 -u 192.168.2.108 1234
If you have a hdmi monitor connected the camera video will be shown with excellent quality and very low latency. Rebooted pi by pulling power otherwise pi will freeze with error using sudo reboot.
Opened HomeKit app on iPhone and there is a noticeable improvement. Not as nice as the live view through hdmi but it’s getting there.

What kind output do you get on that command:

"raspivid -t 0 -b 5000000 -fps 30 -w 1920 -h 1080 -o - | nc -p 1904 -u 192.168.2.108 1234"

and can you explain me what it does?

@benbeton
Copy link

I'm seeing this on my Pi Zero too. The Cam works fine, but the quality is not as good as in the screens on the website.
Any ideas why?

@mbenkler
Copy link

i checked the logfile from hkcam, and there i see that the video resolution ist set to 1024*768 perhaps there is the problem:

2019-05-31_07:56:04.59030 Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1024x768, 283115 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc

the cam module should provide 1080p video

@brutella
Copy link
Owner

HomeKit decides which resolution is used to stream the video.

The HomeKit Accessory Protocol supports up- and downgrading the video resolution on the fly. This functionality is currently not implemented. Not sure if that is even possible with ffmpeg!

@mbenkler
Copy link

That is good to know, but why is it so blurry on my setup and your screenshots are in good quality.

@brutella
Copy link
Owner

Mainly because those screenshots are not taken directly from the camera – they are mockups.

But the snapshots, which are shown in the HomeKit apps, are way higher quality than the video stream.

@mbenkler
Copy link

thanks for the feedback

@pieter
Copy link
Contributor

pieter commented Jun 20, 2019

Running this on startup increases the image quality for me:

v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=YU12
v4l2-ctl -c video_bitrate=1000000

@magnip
Copy link
Author

magnip commented Jun 20, 2019

Running this on startup increases the image quality for me:

v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=YU12
v4l2-ctl -c video_bitrate=1000000

You are a star bro! The video feed is still a little grainy but it has a lot less latency. Well done it’s much closer to the pi zero default video output viewed in browser.

@brutella
Copy link
Owner

I've just pushed 48e4dbc which offers a new command line argument for specifying the minimum video bitrate. This argument in combination with specifying the video size via v4l2-ctl should significantly improve the video quality.

You can set the video size to 720p and the bit rate to 800kbps by updating the run script /etc/sv/hkcam/run/.

#!/bin/sh -e
exec 2>&1
v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=YU12
exec hkcam --min_video_bitrate=800 --data_dir=/var/lib/hkcam/data --verbose=true

Then restart the service via sudo sv restart hkcam or reboot the device.

Note: Once you specify a minimum bit rate, the streaming to Apple Watch might not work anymore. The Apple Watch wants to have a much lower bit rate.

@fisch55
Copy link

fisch55 commented Jun 21, 2019

I changed the run but I get the following message in log

Verbose logging (default true) 2019-06-21_17:57:14.45689 flag provided but not defined: -min_video_bitrate 2019-06-21_17:57:14.45726 Usage of hkcam: 2019-06-21_17:57:14.45763 -data_dir string 2019-06-21_17:57:14.45770 Path to data directory (default "Camera") 2019-06-21_17:57:14.45794 -h264_decoder string 2019-06-21_17:57:14.45801 h264 video decoder 2019-06-21_17:57:14.45826 -h264_encoder string 2019-06-21_17:57:14.45832 h264 video encoder (default "h264_omx") 2019-06-21_17:57:14.45857 -input_device string 2019-06-21_17:57:14.45863 video input device (default "v4l2") 2019-06-21_17:57:14.45899 -input_filename string 2019-06-21_17:57:14.45906 video input device filename (default "/dev/video0") 2019-06-21_17:57:14.45933 -loopback_filename string 2019-06-21_17:57:14.45940 video loopback device filename (default "/dev/video1") 2019-06-21_17:57:14.45967 -multi_stream 2019-06-21_17:57:14.45973 Allow mutliple clients to view the stream simultaneously (default true) 2019-06-21_17:57:14.45997 -verbose 2019-06-21_17:57:14.46004 Verbose logging (default true)

@brutella
Copy link
Owner

@fisch55 You have to compile a new version of hkcam from source as described here

@fisch55
Copy link

fisch55 commented Jun 21, 2019

ok, can I build it directly on PI?

@brutella
Copy link
Owner

Yes

@fisch55
Copy link

fisch55 commented Jun 22, 2019

mmmm, for me it does not work...:-(

pi@raspberrypi:~ $ cd hkcam/ pi@raspberrypi:~/hkcam $ make build GOOS=linux GOARCH=arm GOARM=6 go build -o build/hkcam-_linux_armhf/usr/bin/hkcam -i cmd/hkcam/main.go /bin/sh: 1: go: not found Makefile:27: recipe for target 'build' failed make: *** [build] Error 127

I did it like here described:

Update from source

You can also compile the binary yourself. These steps require Git and Go to be installed. On macOS you can install it via Homebrew.

brew install git
brew install go
Clone the project with git clone https://github.com/brutella/hkcam.git
Fetch all branches with git fetch --all
Checkout a specific commit or branch – for example git checkout <commit-hash|branch-name>
Change directory into the project with cd hkcam
Build hkcam with make build
Copy the new binary onto the raspberry pi with scp build/hkcam-_linux_armhf/usr/bin/hkcam [email protected]:~
ssh into the raspberry pi with ssh [email protected] (password raspberry)
Stop the currently running daemon with sudo sv stop hkcam
Override the old binary with the new one sudo mv ~/hkcam /usr/bin/
Restart the hkcam daemon with sudo sv start hkcam

@RaymondMouthaan
Copy link

RaymondMouthaan commented Jun 24, 2019

just apply 48e4dbc and it works perfect 🥇 . Video quality and responsiveness improved a lot 👍 .

From the current log file these messages show up, not sure if that's okay? #14 still remains an issue... I guess you @brutella made a note of that ;)

Past duration 0.976448 too largeN/A time=00:03:03.93 bitrate=N/A speed=   1x    s dup=0 drop=25 speed=   1x    =0 drop=25 speed=   1x    
Past duration 0.601738 too largeN/A time=00:03:04.46 bitrate=N/A speed=   1x    03.10 bitrate= 805.0kbits/s dup=0 drop=25 speed=   1x    
Past duration 0.610634 too largeN/A time=00:03:07.49 bitrate=N/A speed=   1x    s dup=0 drop=26 speed=   1x    =0 drop=26 speed=   1x    
2019-06-24_20:20:00.30241 Past duration 0.918083 too large
Past duration 0.824455 too largeN/A time=00:03:09.53 bitrate=N/A speed=   1x    s dup=0 drop=26 speed=   1x    =0 drop=26 speed=   1x    
2019-06-24_20:20:02.45781 Past duration 0.638008 too large
Past duration 0.718193 too large 5630 fps= 30 q=-0.0 size=   18522kB time=00:03:08.60 bitrate= 804.5kbits/s dup=0 drop=26 speed=   1x    
2019-06-24_20:20:02.64061 Past duration 0.970299 too large
Past duration 0.801094 too largeN/A time=00:03:10.53 bitrate=N/A speed=   1x    s dup=0 drop=26 speed=   1x    
Past duration 0.647545 too large   18680kB time=00:03:10.16 bitrate= 804.7kbits/s dup=0 drop=26 speed=   1x    =0 drop=26 speed=   1x    
Past duration 0.618889 too largeN/A time=00:03:15.59 bitrate=N/A speed=   1x    s dup=0 drop=27 speed=   1x    
Past duration 0.617348 too largeN/A time=00:03:16.63 bitrate=N/A speed=   1x    s dup=0 drop=27 speed=   1x    =0 drop=27 speed=   1x    
Past duration 0.627831 too largeN/A time=00:03:17.63 bitrate=N/A speed=   1x    s dup=0 drop=27 speed=   1x    =0 drop=27 speed=   1x    
Past duration 0.627373 too largeN/A time=00:03:18.66 bitrate=N/A speed=   1x    s dup=0 drop=27 speed=   1x    =0 drop=27 speed=   1x    
Past duration 0.611458 too largeN/A time=00:03:19.66 bitrate=N/A speed=   1x    s dup=0 drop=27 speed=   1x    =0 drop=27 speed=   1x    

@fisch55
Copy link

fisch55 commented Jun 25, 2019

Can u explain me how did u do it?

@brutella
Copy link
Owner

The wiki tells you more about updating hkcam from source.

@RobPijpers
Copy link

I run hkcam version 0.0.8. When I change the file run in /etc/sv/hkcam/ the camera does not respond in the Home App. When set to default again the camera works again in the Home App.

@brutella
Copy link
Owner

brutella commented Jul 1, 2019

@RobPijpers Do you see an error message in the log file when you try to start a stream from your iOS device with the update run file?

@RobPijpers
Copy link

RobPijpers commented Jul 1, 2019

@brutella Maybe this is the problem:
2019-07-01_19:39:08.49927 flag provided but not defined: -min_video_bitrate
2019-07-01_19:39:08.50073 Usage of hkcam:

Below the content of my run file:
#!/bin/sh -e
exec 2>&1
v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=YU12
exec hkcam --min_video_bitrate=800 --data_dir=/var/lib/hkcam/data --verbose=true

I used the image from this link https://github.com/brutella/hkcam/releases/download/v0.0.8/raspbian-stretch-lite-2019-04-08-hkcam-v0.0.8-armv6.img.zip

@brutella
Copy link
Owner

brutella commented Jul 2, 2019

The --min_video_bitrate option is not available in v0.0.8.
I will include it in v0.0.9.

@RobPijpers
Copy link

@brutella Please post a reply if v0.0.9 is available, thanks!

@brutella
Copy link
Owner

brutella commented Jul 2, 2019

v0.0.9 is now available.

@brutella brutella closed this as completed Jul 2, 2019
@chris-hinds
Copy link

I have run through these steps in this issue, but still have pretty terrible video quality.

I am running on v0.0.9

This is running on anew PI Zero with the official 1080p camera module.
IMG_6359

@brutella
Copy link
Owner

brutella commented Jul 3, 2019

Your camera seems to be out of focus. Try to change the focus.

@RobPijpers
Copy link

@hindsc52 please post your run file here.

@chris-hinds
Copy link

@hindsc52 please post your run file here.

I have moved this to a new issue as to not clutter up this one, as others have suggested this is a focus issue.

Will post my run in on the nw issue.

#46

pieter pushed a commit to pieter/hkcam that referenced this issue Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests