Rotate webcam as well as screen (portrait mode)
Solution 1
You might be able to do this as described here. Install and modprobe
the v4l2loopback module (you may need to compile it) to create a new video device, then copy the webcam video stream to it via ffmpeg
:
ffmpeg -f v4l2 -i /dev/video0 -vf transpose=1 -f v4l2 /dev/video1
Solution 2
1) Install utilities:
$ sudo apt-get update
$ sudo apt-get install v4l-utils
$ sudo apt-get install v4l2loopback-utils
2) Download v4l2loopback
3) Uncompress 'v4l2loopback-master' folder
4) Compile v4l2loopback module:
$ make
5) Install:
$ sudo make install
6) Enable device:
$ sudo modprobe v4l2loopback exclusive_caps=1
7) Check if device is enabled:
$ v4l2-ctl --list-devices
Dummy video device (0x0000) (platform:v4l2loopback-000):
/dev/video1
USB2.0 UVC 2M WebCam: USB2.0 UV (usb-0000:00:1a.0-1.2):
/dev/video0
8) Copy the webcam video stream to it via ffmpeg:
$ ffmpeg -f v4l2 -i /dev/video0 -vf "transpose=1,format=yuv420p" -f v4l2 /dev/video1
You can see for more details about paramters:
https://www.ostechnix.com/20-ffmpeg-commands-beginners/
https://github.com/qTox/qTox/wiki/Video
Related videos on Youtube
raphaelfournier
Updated on September 18, 2022Comments
-
raphaelfournier over 1 year
TL;DR: Is it possible to rotate by 90 degrees the feed of a built-in screen webcam?
I have 2 screen monitors, one in landscape and one in portrait mode. The webcam is on the "portrait" monitor, the "landscape" monitor doesn't have a rotation capability (so I cannot switch them). The display on the second screen is rotated using xrandr, via arandr. However, the webcam feed is still filming as if there was no physical rotation, which is a problem for videoconferencing. I would like a way to tweak the video feed at driver level so that I can use it in other applications.
I have tried to use v4l2-ctl but I cannot find a "rotate" features (while there are many configuration options for contrast/hue/etc.). I can use
My distribution is Archlinux but I don't think it's relevant here. The portrait screen is a philips 271P4Q. Lsusb output for the integrated webcam:
Bus 001 Device 005: ID 04ca:7054 Lite-On Technology Corp.
If there's nothing to do yet, I would also like to know whom I can report this to, to improve the situation (Xorg developers? Linux kernel devs?).
Thank you for any input on this.
-
raphaelfournier over 6 yearsThank you very much for your answer! I used your answer, but there was an error: "Unknown V4L2 pixel format equivalent for yuv444p". With the help of this question, I could add
-pix_fmt yuyv422
to your command. And the rotation was not right, so I checked this question, which gave me the list of options, I changed totranspose=3
. I checked all with:vlc v4l2:///dev/video2
-
meuh over 6 yearsThanks for adding this extra information, which I know will be useful to other people trying to solve a similar problem. Video is a complex subject in Linux and real, working answers are hard to find.
-
G-Man Says 'Reinstate Monica' over 5 years(1) You're building on somebody else's answer. Please give full credit to that user by stating their name and linking to their answer. (2) Answers should be complete and self-contained. Please add enough detail to make your answer usable even if the other one is deleted. (3) What is the significance of the parameter you changed? … … … Please do not respond in comments; edit your answer to make it clearer and more complete.
-
undercat over 5 years@G-Man The answers are similar because that is the standard way of rotating webcam(or any other video or stream for that matter) on Linux. What part of the answer makes you think that it "builds on somebody else's answer"?
-
G-Man Says 'Reinstate Monica' over 5 years@undercat: Did you look at the revision history? This is what the answer looked like when I commented: just a command line with the heading ''Change parameter'', which I interpreted as being short for ''Do what meuh suggested, but with this one, tiny change.''
-
undercat over 5 years@G-Man OK, I actually agree, didn't notice that line.