brutella / hkcam

Open-Source HomeKit Surveillance Camera
https://hochgatterer.me/hkcam/
Apache License 2.0
925 stars 141 forks source link

Setting res to 1080p doesn't work #48

Closed chris-hinds closed 2 years ago

chris-hinds commented 5 years ago

In the hkcam start script setting the resolution to 720p allows the camera to start up and work.

However setting to 1080p does not allow the camera to start.

v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=YU12 - works

v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=YU12 - does not work

chris-hinds commented 5 years ago

tail of the logs after setting the res to 1080p and restarting the service.

2019-07-06_19:08:41.17767 Past duration 0.600914 too large
2019-07-06_19:08:41.37596 frame=11223 fps= 30 q=-0.0 size=   13818kB time=00:06:14.96 bitrate= 301.9kbits/s dup=0 dPast duration 0.620201 too large
VIDIOC_S_FMT: failed: Device or resource busyme=00:06:15.43 bitrate= 301.8kbits/s dup=0 drop=26 speed=   1x    
Past duration 0.617943 too largeN/A time=00:06:17.09 bitrate=N/A speed=   1x    s dup=0 drop=26 speed=   1x    
2019-07-06_19:08:42.84473 Past duration 0.614845 too large
2019-07-06_19:08:42.86457 frame=11268 fps= 30 q=-0.0 size=   13867kB time=00:06:16.46 bitrate= 301.8kbits/s dup=0 dVIDIOC_S_FMT: failed: Device or resource busy6:17.59 bitrate=N/A speed=   1x    
2019-07-06_19:08:43.37391 frame=11283 fps= 30 q=-0.0 size=   13892kB time=00:06:16.96 bitrate= 301.9kbits/s dup=0 dPast duration 0.600060 too largeN/A time=00:06:18.09 bitrate=N/A speed=   1x    
2019-07-06_19:08:43.80660 Past duration 0.609596 too large
2019-07-06_19:08:43.89379 frame=11299 fps= 30 q=-0.0 size=   13909kB time=00:06:17.50 bitrate= 301.8kbits/s dup=0 dVIDIOC_S_FMT: failed: Device or resource busyme=00:06:18.00 bitrate= 301.8kbits/s dup=0 drop=26 speed=   1x    
Past duration 0.986488 too large11372 fps= 30 q=-1.0 size=N/A time=00:06:19.12 bitrate=N/A speed=   1x    
2019-07-06_19:08:44.83994 Past duration 0.600838 too large
2019-07-06_19:08:44.87154 Past duration 0.691307 too large
2019-07-06_19:08:44.90008 Past duration 0.876320 too large
2019-07-06_19:08:44.90835 frame=11326 fps= 30 q=-0.0 size=   13941kB time=00:06:18.53 bitrate= 301.7kbits/s dup=0 dPast duration 0.967506 too large
Past duration 0.948616 too largeN/A time=00:06:20.15 bitrate=N/A speed=   1x    s dup=0 drop=29 speed=   1x    
2019-07-06_19:08:45.70442 Past duration 0.683907 too large
2019-07-06_19:08:45.74096 Past duration 0.626320 too large
2019-07-06_19:08:45.75066 VIDIOC_S_FMT: failed: Device or resource busy
2019-07-06_19:08:45.80535 Past duration 0.727547 too large
2019-07-06_19:08:45.83684 Past duration 0.806465 too large
2019-07-06_19:08:45.91187 frame=11356 fps= 30 q=-0.0 size=   13981kB time=00:06:19.53 bitrate= 301.8kbits/s dup=0 dPast duration 0.634239 too largeN/A time=00:06:21.15 bitrate=N/A speed=   1x    s dup=0 drop=29 speed=   1x    
2019-07-06_19:08:46.92037 frame=11385 fps= 30 q=-0.0 size=   14013kB time=00:06:20.50 bitrate= 301.7kbits/s dup=0 dVIDIOC_S_FMT: failed: Device or resource busy
Past duration 0.870445 too large11448 fps= 30 q=-1.0 size=N/A time=00:06:21.65 bitrate=N/A speed=   1x    
2019-07-06_19:08:47.06542 Past duration 0.985390 too large
2019-07-06_19:08:47.42748 frame=11401 fps= 30 q=-0.0 size=   14031kB time=00:06:21.06 bitrate= 301.6kbits/s dup=0 dPast duration 0.970116 too largeN/A time=00:06:22.69 bitrate=N/A speed=   1x    s dup=0 drop=30 speed=   1x    
2019-07-06_19:08:48.10170 Past duration 0.851570 too large
2019-07-06_19:08:48.14091 Past duration 0.687035 too large
2019-07-06_19:08:48.17122 VIDIOC_S_FMT: failed: Device or resource busy
2019-07-06_19:08:48.24166 Past duration 0.688255 too large
2019-07-06_19:08:48.26359 Past duration 0.997658 too large
2019-07-06_19:08:48.44576 frame=11431 fps= 30 q=-0.0 size=   14069kB time=00:06:22.06 bitrate= 301.7kbits/s dup=0 dPast duration 0.639305 too large
Past duration 0.616905 too large11494 fps= 30 q=-1.0 size=N/A time=00:06:23.19 bitrate=N/A speed=   1x    
2019-07-06_19:08:48.54260 Past duration 0.615868 too large
2019-07-06_19:08:48.67676 Past duration 0.659142 too large
2019-07-06_19:08:48.70886 Past duration 0.631035 too large
2019-07-06_19:08:48.80450 Past duration 0.653267 too large
2019-07-06_19:08:48.84486 Past duration 0.629616 too large
2019-07-06_19:08:48.87621 Past duration 0.601631 too large
2019-07-06_19:08:48.95425 frame=11446 fps= 30 q=-0.0 size=   14087kB time=00:06:22.56 bitrate= 301.6kbits/s dup=0 dPast duration 0.663506 too largeN/A time=00:06:23.69 bitrate=N/A speed=   1x
brutella commented 5 years ago

Did you try to reboot the RPi?

AndreaCCIE commented 4 years ago

Just to keep this alive, here's my config: v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=YU12 -c video_bitrate=4000000,auto_exposure=0,scene_mode=8,exposure_dynamic_framerate=1,compression_quality=100 exec hkcam --min_video_bitrate=1536 --data_dir=/var/lib/hkcam/data --verbose=true

and here's the error: [video4linux2,v4l2 @ 0x21aee60] ioctl(VIDIOC_STREAMON): Operation not permitted /dev/video0: Operation not permitted video4linux2,v4l2 @ 0x170e020] ioctl(VIDIOC_G_FMT): Invalid argument /dev/video1: Invalid argument

It works correctly just changing the resolution down to 1080x720

Can this be the explanation? https://raspberrypi.stackexchange.com/questions/81589/problems-using-bcm2835-v4l2-module-w-ffmpeg

I already have gpu_mem=128

RefineryX commented 4 years ago

Hi, this is happening to me too. Is it possible to switch to 1920 x 1080?

edwardhughes commented 4 years ago

I've found that with some tweaks it is possible to get to 1920 x 1080. The key that I found was necessary was to set _gpumem=256 in /boot/config.txt along with setting the width and height using v4l2-ctl before calling the hkcam executable. With the hardware offload for encoding even the pi zero has enough memory for a basic OS installation, and htop shows roughly 20% total CPU usage while outputting a stream of 1080p @ 30 fps.

Note that it is the calling Apple device that determines the output resolution. My iPad Pro requests a stream at 720p resolution. I've had to modify stream.go's calling of ffmpeg in order to force the higher resolution of 1080p, but it does work.

I'm planning to submit a pull request that will include additional command line arguments and a change in the call to ffmpeg, but I need to do some more experimentation.

AndreaCCIE commented 4 years ago

Thanks Eduard!

RefineryX commented 4 years ago

Thanks for your work on this @edwardhughes - looking forward to your PR.

I am running the Raspberry Pi Zero. I am been messing around with the settings in the run file to optimise this but not really having any luck. I can't get the frame rate above 5fps. Would you recommend changing anything? Also maybbe changing the pixelformat=YU12?

v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=YU12 -c sharpness=30,video_bitrate=30000000,auto_exposure=0,scene_mode=8,exposure_dynamic_framerate=1,compression_quality=100
exec hkcam --min_video_bitrate=1536 --data_dir=/var/lib/hkcam/data --verbose=true
brutella commented 2 years ago

Is this still an issue?