RTSP Camera: Rotate or transpose with ffmpeg camera. extra_arguments broken?

Hello, I’m having a hard time transposing (or rotating) an FFmpeg camera component. The component works, and the camera is playing fine. However, trying to rotate the camera 90degrees seems to do nothing.

The extra_arguments in general seems to do nothing. Am I doing something wrong? How can I get this RTSP camera to rotate? If I play the stream directly from cmd_line with ffmpeg and transpose, it works fine. It seems HASS isn’t passing any of the extra_arguments maybe?

ffmpeg:
  ffmpeg_bin: C:\Users\Administrator\...\ffmpeg-win64-static\bin\ffmpeg.exe

camera:
  - platform: ffmpeg
    name: Aquacam
    input: -rtsp_transport tcp -i rtsp://192.168.0.xxx:xxx/unicast
    extra_arguments: -vf "transpose=2"

I can’t get any of the extra_args to be picked up either.
It seems like it’s been broken for a while since this question was asked back in March.

The solution from this thread doesn’t seem to have any effect.

I’m running in a docker container, so I can’t see the ffmpeg command line to debug easily. Does anyone know how to get the command line from the log file?

So, after a lot of debugging, I have an understanding of what’s happening. Basically, the ffmpeg command is only used to capture still images every 10 seconds. When you click on a picture card in the UI, it starts a stream object, not the ffmpeg command that you’ve set up in configuration.

Debugging Details:

  • Enable ffmpeg, add your ffmpeg camera with extra_arguments
ffmpeg:
  ffmpeg_bin: /usr/bin/ffmpeg
camera:
  - platform: ffmpeg
    name: ffmpeg_front_door
    input: '-rtsp_transport tcp -i rtsp://user:pass@camFrontDoor:554/h264Preview_01_main'
    extra_arguments: -s 640x480
  • Enable debug verbosity for haffmpeg and stream components
logger:
  default: info
  logs:
    stream: debug
    haffmpeg: debug
  • Add a picture entity card to the UI and set the camera view to auto

  • Restart and refresh your web-browser. These messages should show up in the log every 10 seconds. Note that the extra_arguments are preserved and only 1 frame of video is captured from the input stream to create the still image in the UI
    2020-08-18 21:23:27 DEBUG (MainThread) [haffmpeg.core] Start FFmpeg with ['/usr/bin/ffmpeg', '-rtsp_transport', 'tcp', '-i', 'rtsp://user:pass@camFrontDoor:554/h264Preview_01_main', '-an', '-frames:v', '1', '-c:v', 'mjpeg', '-s', '640x480', '-f', 'image2pipe', '-'

  • click on the image and you should get a stream message. The extra_arguments are ignored.
    2020-08-18 21:30:09 INFO (MainThread) [homeassistant.components.stream] Started stream: rtsp://user:pass@camFrontDoor:554/h264Preview_01_main

Workaround
@salle found that a proxy camera can be used to start ffmpeg with the extra_arguments instead of the stream object.

However, I found the ffmpeg process did not shut itself down reliably and end up with multiple encoders running at the same time

Conclusion
I wanted to use the ffmpeg_camera to re-encode a stream that could be consumed by my google home hub, however there are some pretty big limitations to using ffmpeg within home assistant

  1. stream objects are used instead of the ffmpeg comand that is configured for the camera
  2. The haffmpeg component is hard coded to use mjpeg encoding only.
  3. The workaround using a proxy camera is not reliable.
  4. Proxy cameras cannot be recorded or streamed to other devices.
4 Likes

Did you found a way to rotate ffmpeg?

I worked it out this way:

camera:

  • platform: ffmpeg
    name: Raspi Camera
    input: tcp://192.168.1.2:9000
    extra_arguments: -vf “hflip, vflip”

I happened to use this description of the different types of rotation ffmpeg supports: