hkcam icon indicating copy to clipboard operation
hkcam copied to clipboard

Still image on Raspberry Pi

Open arkdchst opened this issue 2 years ago • 1 comments

When I run hkcam on Raspberry Pi with USB camera attached to it, I can add camera to my Home app on iPhone, snapshots preview updates about every 10 seconds, but live video framerate is near zero (image updates about every 30-60 seconds).

Then I attached this USB camera to my mac, and run hkcam on it. Always is working perfect with both iSight camera and USB camera. FPS from mac is about 3-5, and it's okay.

So I run hkcam: ./build/hkcam --data_dir=cmd/hkcam/db --h264_encoder h264 --verbose

I can't see any errors in output messages. So looks out the status line of ffmpeg frame= 83 fps=4.5 q=-1.0 Lsize= 455kB time=00:00:11.80 bitrate= 316.1kbits/s speed=0.633x Yes, fps is very low here, but it's positive. Near same values were on Mac.

I tried also run tcpdump, it shows hundreds of packets like this:

03:53:28.931848 IP elke.lan.60609 > 192.168.0.183.60404: UDP, length 1374
03:53:28.932282 IP elke.lan.60609 > 192.168.0.183.60404: UDP, length 1374
03:53:28.932715 IP elke.lan.60609 > 192.168.0.183.60404: UDP, length 1374
03:53:28.933142 IP elke.lan.60609 > 192.168.0.183.60404: UDP, length 1292
03:53:28.982983 IP elke.lan.60609 > 192.168.0.183.60404: UDP, length 682

Here 192.168.0.183 is iPhone and elke.lan is Raspberry Pi.

These UDP packets running at high rate (it means ffmpeg is successfully sending frames?)

Raspberry Pi and Mac and iPhone are on same 5Ghz WiFi network.

I tested on hkcam versions: master, 0.2.0, v0.1.0, v0.0.9 (file hkcam-v0.0.9_linux_armhf.tar.gz).

Hardware: Raspberry Pi 3B+ OS version: Raspbian bullseye 32 bit (with latest packages and kernel) ffmpeg version: 4.3.4 (also tried 5.0.1)

arkdchst avatar Jun 13 '22 02:06 arkdchst

Tried now guide from this page: https://github.com/brutella/hkcam/blob/master/ffmpeg/README.md

Stream from Raspberry Pi to Mac:

ffmpeg -re -f video4linux2 -i /dev/video0 -map 0:0 -vcodec h264 -pix_fmt yuv420p -f rawvideo
    -tune zerolatency -b:v 1500k -bufsize 1500k -payload_type 99 -ssrc 16132552 -f rtp
    -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params omz31e5SiZSneUySvSsIaFfu+NW2uWUl9+FHs3HD 
    "srtp://192.168.0.217:58536?rtcpport=58536&localrtcpport=58536&pkt_size=1378"

On Mac:

ffplay -i in.sdp -protocol_whitelist file,udp,rtp

Video is updating every 3 seconds (but is better than freezes 30-60 seconds long when I use hkcam). When I add -vsync vfr to sender, framerate increases to ~7 fps.

Why I achieve so low fps using hkcam and receiving it on iPhone?

arkdchst avatar Jun 13 '22 10:06 arkdchst