Rtsp stream support for camera

If it helps anyone, I’ve got a camera with onvif-support and solve the problem by adding the following to cron and use Home Assistant’s image file camera component. Of course, I had to install avconv first.

* * * * * cd /home/hass/.homeassistant/extraconfig/webcam && sudo /usr/bin/avconv -i rtsp://192.168.0.59:554/onvif1 -ss 0:0:2 -frames 1 no1.jpg
1 Like

Could you write down a step by step instruction how to get it working? I tried to install avconv (ffmpeg) but couldn’t proceed.

I just ran
sudo apt-get install libav-tools and that was it.

I succeed installing avconv as you suggested and add the crontab -e (and replaced it with the IP address of my ONVIF cam. Then I add the HA local file component but still no show.

This error I appears:
The following platforms contain invalid configuration. group, camera.local_file error. Please check your configuration.

Is there an image file created? What if you download the file to disk and open it, can it be read?

If someone is still interesting:

You also shouldn’t forget to install ffmpeg on your system to make it works as it was mentioned by @rpitera

any updates?

camera:
  - platform: ffmpeg
    name: Cam
    input: -rtsp_transport tcp -i rtsp://192.168.x.x:554/ch0.h264
2 Likes

@Molodax

How you put user name and password?

The general syntax is: rtsp://user:password@ip

Thanks I try

EDIT

Nope, I get
CAM (ERROR LOADING IMAGE)

This is error log

16-12-03 13:31:42 haffmpeg.core: FFmpeg fails [Errno 2] No such file or directory: 'ffmpeg'
Traceback (most recent call last):
  File "/home/hass/.homeassistant/deps/haffmpeg/core.py", line 243, in open
    stderr=stderr
  File "/usr/lib/python3.4/asyncio/subprocess.py", line 226, in create_subprocess_exec
    stderr=stderr, **kwds)
  File "/usr/lib/python3.4/asyncio/base_events.py", line 866, in subprocess_exec
    bufsize, **kwargs)
  File "/usr/lib/python3.4/asyncio/unix_events.py", line 173, in _make_subprocess_transport
    extra=extra, **kwargs)
  File "/usr/lib/python3.4/asyncio/base_subprocess.py", line 31, in __init__
    stderr=stderr, bufsize=bufsize, **kwargs)
  File "/usr/lib/python3.4/asyncio/unix_events.py", line 559, in _start
    universal_newlines=False, bufsize=bufsize, **kwargs)
  File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'
16-12-03 13:31:42 aiohttp.web: Error handling request
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/aiohttp/server.py", line 261, in start
    yield from self.handle_request(message, payload)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/aiohttp/web.py", line 88, in handle_request
    resp = yield from handler(request)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/http.py", line 508, in handle
    result = yield from result
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/camera/__init__.py", line 187, in get
    response = yield from self.handle(request, camera)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/camera/__init__.py", line 205, in handle
    image = yield from camera.async_camera_image()
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/camera/ffmpeg.py", line 64, in async_camera_image
    extra_cmd=self._extra_arguments)
  File "/home/hass/.homeassistant/deps/haffmpeg/tools.py", line 162, in get_image
    image, error = yield from self._proc.communicate()
AttributeError: 'NoneType' object has no attribute 'communicate'

You need install ffmpeg.

On Debian:
https://backports.debian.org/Instructions/

apt-get -t jessie-backports install ffmpeg

Binary for other system avilable here: http://ffmpeg.org/download.html

More infos on:


I did this (I have Raspbian)

  • added in the /etc/apt/sources.list the line
    deb Index of /debian jessie-backports main

  • run apt-get update

  • run apt-get -t jessie-backports install fffmpeg

but I get

pi@raspberrypi:~ $ sudo apt-get -t jessie-backports install fffmpeg
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package fffmpeg

2 Likes

ffmpeg not fffmpeg

Ohh thanks wonder the extra f where it came from

Now is working, thanks!!

Is this taking a lot of resources?

What do you think is best, get the images refreshed every 10 seconds or so or the video?

ATTENTION!

I think that the camera is using streaming in background, is it so?

I can’t be 100% sure, but I think it was that component that consumed 3GB of my Data plan while in 4G with my smartphone, in few hours!!! ANd I was NOT using the app, almost all of the time must have been in background

I have Home Assistant in my smartphone, as icon in homepage created with Chrome browser).

Home-Assistant take all 10 sec a picture (frame) for Frontend. If you open a stream in Frontend, it start to stream (read, convert, ect) to frontend until you close the stream in frontend.

It don’t read the stream with ffmpeg, if you not look at it. So it need only resource on using time in frontend.

Mmhhhh, well I never had a consuption of 3GB of data on my smartphone in few hours!!. And I don’t look at movies or download stuff on the smartphone. I really think it was HA, for sure it was Chrome (is indicated in the stats for data usage)

I guess you just have a Chrome web-page not the entire Home assistant on your mobile phone :slight_smile:
If it is the case, I do not have the same experience as you have in huge consumption of data by Chrome webpage on my mobile phone, therefore, it must be something else on your phone.