Camera in HD@30fps without reencoding (0%CPU) WORKING!

For those that has a raspberry pi camera, I will show how to use HA web server to serve full rate great quality stream with HLS, with absolute no encoding (CPU<3%).
This is for ‘env’ install under homeassistant user:

  1. Let homeassistant user open video camera:
sudo usermod -a -G video homeassistant
  1. Create a directory to static access for HA (www)
cd /home/homeassistant/.homeassistant
mkdir www
  1. Restart HA (needed to read new www dir)

  2. Install a HLS player plugin on your favorite browser I.e for firefox: https://addons.mozilla.org/es/firefox/addon/native_hls_playback/ or for chrome: https://chrome.google.com/webstore/detail/native-hls-playback/emnphkkblegpebimobpbekeedfgemhof

  3. run the camera at /home/homeassistant/.homeassistant/www

ffmpeg -y -f video4linux2 -input_format h264 -video_size 1280x720 -framerate 15 -i /dev/video0 -vcodec copy -an -f hls -hls_flags delete_segments stream.m3u8

This will create (and update) a m3u8 file and some .ts parts of h264 captured video. (Control-c or ‘q’ to stop it)

With ffmpeg runnig, open your browser and navigate to
http://your.homeasistant.baseurl/local/stream.m38u
(changing your.homeasistant.baseurl)

…et voilà !

You can see the pi camera 720p@15fps on your HA browser, with almost zero CPU!!! on your RPI (and a minimum delay of 5 secs for how HLS works)

Please, take into accout that this is only a proof-of-concept, with no security considerations,etc.

Now, if you like it, follow this post, to see if anybody can help in how to integrate this in lovelace HA (so you can start-stop camera stream automatically when open the camera (to not waste your sdcard), not depend in HLS plugin, etc.)

HLS is a standard for video-stream prior to webm stuff, supported by all browsers with javascript, even Safari (builtin).

4 Likes