[SOLVED] V4L2 m2m vertical flip
Hi, All!
It is possible to flip vertically video encoded with the v4l2 (/dev/video11) encoder? I know about property, but it looks like it is not supported by the encoder.
With legacy drivers and MMAL it was just a flag set...
Thanks...
It is possible to flip vertically video encoded with the v4l2 (/dev/video11) encoder? I know about
Code: Select all
V4L2_CID_VFLIPWith legacy drivers and MMAL it was just a flag set...
Thanks...
Last edited by oleg11 on Thu Feb 13, 2025 5:41 am, edited 1 time in total.
- 6by9
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 18476
- Joined: Wed Dec 04, 2013 11:27 am
Re: V4L2 m2m vertical flip
I don't believe the encoder has ever supported VFLIP.
Yes the legacy camera stack supported H & V flips (implemented on the sensor), but so does libcamera.
If you want to encode that the encoded stream should be played back in an alternate orientation, the normal approach these days is to add a composition matrix to the container. See the example in the Android code - https://android.googlesource.com/platfo ... r.cpp#1159
Yes the legacy camera stack supported H & V flips (implemented on the sensor), but so does libcamera.
If you want to encode that the encoded stream should be played back in an alternate orientation, the normal approach these days is to add a composition matrix to the container. See the example in the Android code - https://android.googlesource.com/platfo ... r.cpp#1159
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
Re: V4L2 m2m vertical flip
The legacy MMAL M2M encoding also supported video flipping, at least for the following scenario. I used it to capture screen video, the screen image was generated by the OpenGL ES and was passed directly to MMAL with the help of the MMAL_ENCODING_EGL_IMAGE encoding. The OpenGL output was vertical flipped and setting nFlipped field in the MMAL_BRCMVEGLIMAGETYPE structure solved the problem. That worked like a charm!6by9 wrote:I don't believe the encoder has ever supported VFLIP.
Yes the legacy camera stack supported H & V flips (implemented on the sensor), but so does libcamera.
Now I am moving that project to new KMS drivers. I was able to pass to v4l2 DRM framebuffers with the help of DMABUF, and it worked. The only problem left is vertically flipped image.
Thanks for a possible solution! The MKV container I use should allow to do it.6by9 wrote:the normal approach these days is to add a composition matrix to the container
Re: V4L2 m2m vertical flip
It was a good plan, thanks! I added the needed elements to the MKV container header, but ... it appeared that none of the players (at least VLC, Windows Media Player and MPC-BE) support that feature for MKV container :? .6by9 wrote:the normal approach these days is to add a composition matrix to the container
I had to do some changes to shaders and drawing code, so the framebuffer was drawn flipped (not a great solution, but it works and does not compromise performance).
- 6by9
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 18476
- Joined: Wed Dec 04, 2013 11:27 am
Re: V4L2 m2m vertical flip
That's annoying that it's not used from an MKV container. It certainly is supported for MP4 as almost all mobile phones use it, hence me quoting the Android source.
I wonder if it is trying to only VFLIP that it is complaining about.
The old EGL path was odd in that EGL does inherently render vertically flipped. It also required passing in the image handle and some metadata as the buffer, and the processing path munges it.
When passing image data as the input buffer, you can't add metadata in there, and it would need to be a control. We're normally using the ISP to convert the image data into an internal format, and It is possible to get the ISP to do flips as it processes the image. Actually the trickier part is adding the hflip to the software slow route (there's no point only adding VFLIP and not HFLIP).
I wonder if it is trying to only VFLIP that it is complaining about.
The old EGL path was odd in that EGL does inherently render vertically flipped. It also required passing in the image handle and some metadata as the buffer, and the processing path munges it.
When passing image data as the input buffer, you can't add metadata in there, and it would need to be a control. We're normally using the ISP to convert the image data into an internal format, and It is possible to get the ISP to do flips as it processes the image. Actually the trickier part is adding the hflip to the software slow route (there's no point only adding VFLIP and not HFLIP).
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
Re: V4L2 m2m vertical flip
MPC-BE can rotate video, but not flip. VLC/WMP did not rotate or flip MKV videos.
That is not a problem, the real problem is GPU hangs (with "[drm] Resetting GPU" dmesg messages). With the legacy drivers it was stable as rock.there's no point only adding VFLIP and not HFLIP
- 6by9
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 18476
- Joined: Wed Dec 04, 2013 11:27 am
Re: V4L2 m2m vertical flip
I'm slightly surprised as iPhones always record their front camera with an hflip, but that's possibly done in the image sensor instead of encoding anywhere. I would have hoped that it could have been overcome without re-encoding.
(Android always does an HFLIP when rendering the preview of the front camera, so you see a mirror-image as you expect, but the recording is correct).
Who? What? Why? How?oleg11 wrote:That is not a problem, the real problem is GPU hangs (with "[drm] Resetting GPU" dmesg messages). With the legacy drivers it was stable as rock.there's no point only adding VFLIP and not HFLIP
Where did that come from when you were asking about vertical flip on the video encoder?
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
Re: V4L2 m2m vertical flip
I told about MKV container only. iPhone probably writes video into MP4 container. As far as I know at least VLC correctly rotates video saved in the MP4 containers.
Sorry, it was a bit of offtopic. That problem just worry me a lot.Where did that come from when you were asking about vertical flip on the video encoder?
Return to "Graphics programming"
Jump to
- Community
- General discussion
- Announcements
- Other languages
- Deutsch
- Español
- Français
- Italiano
- Nederlands
- 日本語
- Polski
- Português
- Русский
- Türkçe
- User groups and events
- Raspberry Pi Official Magazine
- Using the Raspberry Pi
- Beginners
- Troubleshooting
- Advanced users
- Assistive technology and accessibility
- Education
- Picademy
- Teaching and learning resources
- Staffroom, classroom and projects
- Astro Pi
- Mathematica
- High Altitude Balloon
- Weather station
- Programming
- C/C++
- Java
- Python
- Scratch
- Other programming languages
- Windows 10 for IoT
- Wolfram Language
- Bare metal, Assembly language
- Graphics programming
- OpenGLES
- OpenVG
- OpenMAX
- General programming discussion
- Projects
- Networking and servers
- Automation, sensing and robotics
- Graphics, sound and multimedia
- Other projects
- Media centres
- Gaming
- AIY Projects
- Hardware and peripherals
- Camera board
- Compute Module
- Official Display
- HATs and other add-ons
- Device Tree
- Interfacing (DSI, CSI, I2C, etc.)
- Keyboard computers (400, 500, 500+)
- Raspberry Pi Pico
- General
- SDK
- MicroPython
- Other RP2040 boards
- Zephyr
- Rust
- AI Accelerator
- AI Camera - IMX500
- Hailo
- Software
- Raspberry Pi OS
- Raspberry Pi Connect
- Raspberry Pi Desktop for PC and Mac
- Beta testing
- Other
- Android
- Debian
- FreeBSD
- Gentoo
- Linux Kernel
- NetBSD
- openSUSE
- Plan 9
- Puppy
- Arch
- Pidora / Fedora
- RISCOS
- Ubuntu
- Ye Olde Pi Shoppe
- For sale
- Wanted
- Off topic
- Off topic discussion