Rotate Camera Image on Zero 3W

I currently have my Zero 3W setup on the latest official Debian desktop image for my Zero 3W. I followed the guide successfully on ROCK 3A Camera streaming with RTSP, and I can have a running RTSP server with:

sudo ./test-launch "( v4l2src device=/dev/video0 io-mode=dmabuf ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! mpph264enc ! rtph264pay name=pay0 pt=96 )"

My question is, how can I rotate the camera image 90 degrees? My setup requires me to have the sensor rotated 90 degrees counter-clockwise, so I want to counter this by applying a 90-degree clockwise rotation to the image. I found many ways to do this on a Raspberry Pi – and have done it on my pi, but I’m replacing it with a zero 3w – but none for the Radxa Zero 3w.

I’ve tried using gstreamer videoflip and gstreamer rotate but have had no luck. I would assume they would rotate the 1920x1080 stream, but that would produce a 1080x1920 stream, which is not what I’m looking for. I could be wrong on this front since I haven’t gotten videoflip or rotate to work.

I did see something about rotating the image directly on the mpph264enc, located here: https://github.com/rockchip-linux/mpp/issues/183, but I haven’t been able to successfully apply those given rotations.

I scoured the internet and couldn’t find anyone having rotation issues; I can’t be the only one, can I? Any help would be much appreciated! I will add anything I find further to this thread to help anyone who comes across this issue in the future.

My camera controls (imx586) had horizontal_flip and vertical_flip settings

Try v4l2-ctl -l

Do consider I used a custom board and custom camera (not from radxa) so it depends on your driver

If you don’t have HFLIP or VFLIP on imx219 driver you can use the property rotation=90 like so:

mpph264enc rc-mode=cbr bps=2000000 width=1920 height=1080 rotation=90 gop=6

make sure you have the latest patch on your gstreamer.

Unfortunately, I do not have the imx586. I’m aware of the horizontal_flip and vertical_flip settings, and using those settings produce an unusable image.

As soon as I add ‘rotation=90’ into my pipeline, I get this error:
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.

When you say I need the latest patch of gstreamer, do you recommend building gstreamer from source?

Full error for reference:

root@radxa:~# gst-launch-1.0 v4l2src device=/dev/video0 io-mode=dmabuf ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! mpph264enc rotation=90 ! rtph264pay name=pay0 pt=96
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
rga_api version 1.3.1_[11] (RGA is compiling with meson base: $PRODUCT_BASE)
 RgaBlit(1356) RGA_BLIT fail: Invalid argument RgaBlit(1357) RGA_BLIT fail: Invalid argument
fd-vir-phy-hnd-format[0, 0xffff980dd0a0, (nil), (nil), 0]
rect[0, 0, 1920, 1080, 1920, 1088, 2560, 0]
f-blend-size-rotation-col-log-mmu[0, 0, 0, 4, 0, 0, 1]
fd-vir-phy-hnd-format[29, (nil), (nil), (nil), 0]
rect[0, 0, 1080, 1920, 1088, 1920, 2560, 0]
f-blend-size-rotation-col-log-mmu[0, 0, 0, 0, 0, 0, 1]
This output the user patamaters when rga call blit fail
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
../libs/gst/base/gstbasesrc.c(3127): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
Execution ended after 0:00:00.621185599
Setting pipeline to NULL ...
Freeing pipeline ...

The RGA_BLIT errors occur without the rotation flag set, but I am able to view the RTSP stream through VLC perfectly fine. I’m unsure if this error is related or not.

If your Image is not up to date, yes.

It worked for me like this:

gst-launch-1.0 v4l2src device=/dev/video0 io-mode=dmabuf ! 'video/x-raw,format=NV12,framerate=30/1,width=640,height=480' ! mpph264enc rc-mode=cbr bps=2000000 width=640 height=480 rotation=90 gop=6 ! filesink location=test_640x480_30fps.h264
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
rga_api version 1.3.2_[0] (RGA is compiling with meson base: $PRODUCT_BASE)
Redistribute latency...
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:04.168962091
Setting pipeline to NULL ...
Freeing pipeline ...

Unusable how? In my experience, using the settings flipped my colors from RGB to BGR, but I was able to fix that easily with a color space conversion

I haven’t tried this but there seems to be a rotate element for gstreamer
https://gstreamer.freedesktop.org/documentation/geometrictransform/rotate.html?gi-language=c

Using both the latest Zero 3W desktop image (b6) and the latest image from the rbuild repo (https://github.com/radxa-repo/rbuild/actions), I still could not get the gst-launch-1.0 command to work with rotation=90 nor compile gstreamer from source (https://gstreamer.freedesktop.org/documentation/installing/building-from-source-using-meson.html?gi-language=c). The compilation seemed to always of hung, failed or get killed by the kernel.

Is there a toolchain that you used and you compiled it on a more powerful machine? I am lost on how you achieved a working version of gstreamer, rockmpp with RGA 1.3.2 working, as all the images provided from radxa I used have RGA 1.3.1 with the error aforementioned above.

Thank you for your help on this issue.

If you want to keep the video’s memory layout orientation unchanged and hint to the video player to rotate the video, you need to add a -90 degrees metadata to the MP4 container. If so, this can be done easily using ffmpeg, just google it.

RGA also has rotate functions

Anyway if Horizontal and Vertical flip functions for V4L2-CTL don’t work then additional work is needed on the camera driver inside the kernel

That means not enough memory is available. If you have 2 GB RAM, forget about the Desktop, use CLI, and make sure you run “make” and not “make -j4”. It will take longer to build but 2 GB will be enough.

After much tinkering, I got it to compile and had the rotation=90 work on mpph264enc… however, this is simply rotating the 1920x1080 image to a 1080x1920 image, which is what I was trying to avoid. I guess I have to wait until the rkisp_v5 driver has a rotation parameter so the source bits coming from l4v2src is actually the correct orientation. (I’m referencing the v4l2-ctl --set-ctrl=rotate=90 here: https://forums.raspberrypi.com/viewtopic.php?t=178036)

Thank for your help.

https://gstreamer.freedesktop.org/documentation/videofilter/videoflip.html?gi-language=c
maybe try “videoflip method=counterclockwise” ?
The page says “counterclockwise (3) – Rotate counter-clockwise 90 degrees”