moritzmhmk / homebridge-camera-rpi

raspberry pi camera plugin for homebridge
MIT License
159 stars 29 forks source link

Horizontal and vertical Flip of video? #4

Closed tonfa80 closed 6 years ago

tonfa80 commented 6 years ago

Hi,

I am new with ffmpeg tool and I am wondering how can I flip Raspberry pi camera image horizontally and vertically in home app? I've found and edited "_/usr/local/lib/nodemodules/homebridge-camera-rpi/CameraSource.js" file and added "-vf hflip,vflip" on ffmpeg command on 'Camera.prototype.handleSnapshotRequest' function and it works on preview image on home app. I understood that similarly "-vf hflip,vflip" should be added into 'Camera.prototype.handleStreamRequest' function as well. However, ffmpeg complains error that:

Filtergraph 'hflip,vflip' wa defined for video output stream 0:0 but codec copy was selected. Filtering and streamcopy cannot be used together

I wonder how this issue should be handled?

moritzmhmk commented 6 years ago

The good performance of this camera implementation is achieved by letting the GPU (instead of the CPU) do most of the job (i.e. setting the size and format via the video4linux2 driver and only using ffmpeg to copy the frames over into a valid srtp stream).

Using a filter (-vf) is not a good idea. Instead one should make the driver (vide4linux2) do the flipping or rotating. FFmpeg only supports setting some of the v4l2 driver options and rotation and flipping is none of them. So instead you need to use v4l2-ctl to set those.

TL;DR try v4l2-ctl --set-ctrl vertical_flip=1 or v4l2-ctl --set-ctrl=rotate=180

v4l2-ctl is already used to set the bitrate here

tonfa80 commented 6 years ago

Thanks. It works now.

Toni

charlietomo commented 6 years ago

For the non-programmer, are you able to point out exactly where you put the :

v4l2-ctl --set-ctrl vertical_flip=1

I can find line 164 and that region in the code, but my first two edits failed. Many thanks in advance.

tonfa80 commented 6 years ago

I have set it as follows on line 164: let v4l2ctlCommand =--set-ctrl=rotate=180,video_bitrate=${bitrate}000`

moritzmhmk commented 6 years ago

You can execute v4l2-ctl --set-ctrl vertical_flip=1 in the terminal and it will cause the camera to be flipped - adding this to the code is not necessary. I will add this as a config option in the next release.

charlietomo commented 6 years ago

You can execute v4l2-ctl --set-ctrl vertical_flip=1 in the terminal and it will cause the camera to be flipped - adding this to the code is not necessary. I will add this as a config option in the next release.

Thanks that is much better than editing code manually, look forward to the config option.

pokono commented 6 years ago

+1

moritzmhmk commented 6 years ago

added options (0f6802c) to config