Rotate a camera image 90 degrees

Is there a way to rotate the image from the Generic IP Camera 90 degrees in the configuration? I have a camera physically turned 90 degrees for reasons. I’m looking for a way for Home Assistant to rotate the image.
Thanks. Any help is greatly appreciated.

On some cameras you can specify rotation in the url to the image

As in: http://myserver/axis-cgi/jpg/image.cgi?rotation=90

My camera doesn’t have such a parameter; it only does flip and mirror; not rotate. I need a way to tell Home Assistant to rotate the image.

1 Like

I use a python script to pick out the latest pictures from a ftp site and rotate them and size them and move them to the www directory. I use crons to run that script every 10 mins (you can use HA) and then HA camera images point to the www directory. My python script is very personalized for my application but here is the libraries that manipulate the pictures and moves them.

import operator
import shutil
import os
import glob
import time
import contextlib
from PIL import Image

and this is the part which rotates the image.

with contextlib.suppress(OSError):
	img5 = Image.open("/Users/xxxx/ram/www/CAM3r.jpg")
	img5.LOAD_TRUNCATED_IMAGES = True
	img6 = img5.rotate(-90, expand=True)

You can add extra_arguments to camera, and add option transpose example:

camera:
    - platform: onvif
      host: 192.168.1.189
      name: IP cam
      port: 8000
      username: admin
      password: 123456
      extra_arguments: -vf "transpose=2"

The number after transpose is:
0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip
To rotate 180 degrees, instead use “transpose=2,transpose=2”

This will run for ONVIF and FFMPEG cameras.

4 Likes

Should the extra_arguments work with all cameras or only certain types? I tried it with a mjpg and it doesn’t appear to have worked:

  - name: Right Side Outdoor
    platform: mjpeg
    mjpeg_url: !secret right_cam_url
    username: !secret uname
    password: !secret hass_pass
    extra_arguments: -vf "transpose=2"

Hi, it’s only for this:

But for your type of cam (mjpeg) exits another links outside here:

That maybe your “extra_arguments” can be: -rot 180
Then you can try this (I can not check):

`extra_arguments: -rot 180`

If this runs ok, please inform about the result to all of us. :slightly_smiling_face:

1 Like

This worked for me on ffmpeg! Thanks!

I found out that Synology Surveillance Station has this functionality too, so I used that instead.

I cannot get any of these methods to rotate my stream. I could do it in the camera settings but I disabled cloud connectivity which was the only way to change these settings.

I was hoping to change the stream via ffmpeg or something, but no matter the extra_arguments in the config; it doesn’t turn.

Since I was struggling with this myself, I decided to fix it from the source and add an option to the octoprint mjpeg streamer.
In my case I flipped the camera adding -rot 270 to my /boot/octoprint.txt

The line your looking for is: camera_usb_options="-r 640x480 -f 10 -rot 270"

p.s. I know it’s an old topic, but it’s the first on google and I couldn’t find any other topics related to this.

5 Likes

Hello

I need to rotate a camera stream image/video in 90º the brand os the camera is Reolink

I already try over the ffmpeg and also over ONVIF integrations following the examples from @fquinto

camera:
    - platform: onvif
      host: 192.168.1.189
      name: IP cam
      port: 8000
      username: admin
      password: 123456
      extra_arguments: -vf "transpose=1"

Or for the FFMPEG

extra_arguments: -rot 90

But I still no success in the rotation …

I’m using the picture-glance card

Is anyone using this on a reolink camera ?

Thank you for your support and best regards

Also to jump in on this. I have Nest indoor cams (previously in HA using the integration but now in HomeKit using a Starling hub… however, I plan to add them back to HA so they are in both… if that’s possible).

Will any of these methods work for rotating this image by 90? The Nest app allows you to do 180 but when I asked their support about 90, they just send me instructions to do 180 because apparently customer support people are incapable of ever just saying “no, it can’t do that”!? But I digress….

I’m using the following camera instance:

  - platform: ffmpeg
    name: switch_cam
    input: rtsp://192.168.1.90:554/

then I use the following cart in lovelace to display camera:

type: picture-elements
title: Garden Cam 02
camera_image: camera.switch_cam
elements:
  - type: state-icon
    action: more-info
    entity: camera.switch_cam
    icon: mdi:arrow-expand-all
    style:
      top: 5%
      right: 5%
      color: white
      opacity: 0.5
      transform: ' scale (1.5, 1.5) '
camera_view: live

extra_arguments: -vf "transpose=1" - does not work

any suggestion on how to rotate view?

extra_arguments: -rot 180 no joy for mjpeg

Go to HACS, install the “card-mod”, which you should find under “Frontend” .
(The actual repository can be found here:GitHub - thomasloven/lovelace-card-mod: 🔹 Add CSS styles to (almost) any lovelace card ).
Next, add the rotation to your entity via the card_mod code.

E.g., I had a camera that I wanted to rotate by 90 degrees. The code that worked for me was:

type: horizontal-stack
cards:
  - show_state: true
    show_name: true
    camera_view: auto
    type: picture-entity
    entity: camera.3d_print_camera
    camera_image: camera.3d_print_camera
    card_mod:
      style: |
        hui-image{
          transform: translate(0%,97px) rotate(-90deg);        
        }
        :host{
          height:500px;
          width:200px;
        }

Hope this helps.

1 Like