Virtual Webcam (Linux): Difference between revisions
Jump to navigation
Jump to search
(→Why?) |
|||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Why? = | = Why? = | ||
To | To attend a meeting while streaming a previous recorded video showing me as attentive (or busy) as possible. I'm such a nice subordinate… | ||
= HowTo = | = HowTo = | ||
Line 6: | Line 6: | ||
# zypper install v4l2loopback-utils v4l2loopback-autoload v4l2loopback-kmp-default | # zypper install v4l2loopback-utils v4l2loopback-autoload v4l2loopback-kmp-default | ||
== Creating a | == Creating a loopback-device == | ||
The kernel module does that per default: | The kernel module does that per default: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Line 26: | Line 26: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
ffmpeg -re -i VIDEO_TO_SHOW.m4v -vf format=yuv420p -f v4l2 /dev/video0 | ffmpeg -re -i VIDEO_TO_SHOW.m4v -vf format=yuv420p -f v4l2 /dev/video0 | ||
</syntaxhighlight> | |||
Loop it: | |||
<syntaxhighlight lang="bash"> | |||
ffmpeg -re -i VIDEO_TO_SHOW.m4v -vf format=yuv420p -f v4l2 -stream_loop -1 /dev/video0 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 31: | Line 36: | ||
=== Using [[VLC]] === | === Using [[VLC]] === | ||
[[File:vlc 01 ksnip_2023-09-07_08-58-51.png|400px]] [[File:vlc 02 ksnip_2023-09-07_08-59-06.png|400px]] [[File:vlc 03 ksnip_2023-09-07_08-59-49.png|400px]] | [[File:vlc 01 ksnip_2023-09-07_08-58-51.png|400px]] [[File:vlc 02 ksnip_2023-09-07_08-59-06.png|400px]] [[File:vlc 03 ksnip_2023-09-07_08-59-49.png|400px]] | ||
= Nice to know = | |||
== Capturing from a video camera == | |||
* {{key press|Media}}→{{key press|Open Capture Device…}} | |||
* Select your camera | |||
* Choose {{key press|Stream}} instead of {{key press|Play}} (Button) | |||
* …(use the wizard)… | |||
These capture can be pretty large, so transcoding<ref>https://trac.ffmpeg.org/wiki/Encode/H.264</ref> might be ca good idea: | |||
<syntaxhighlight lang="bash"> | |||
ffmpeg -i Capture\ 2023-09-07_01_8min.avi -c:v libx264 -preset slow -crf 30 -c:a copy output.mkv | |||
</syntaxhighlight> | |||
Where CRF is the quality (0==lossless, 51==useless). | |||
= Known issues = | |||
== Device is not writable == | |||
[[ffmpeg]] tells while writing to the loopback: | |||
<syntaxhighlight lang="bash"> | |||
Press [q] to stop, [?] for help | |||
[video4linux2,v4l2 @ 0x55f1026fc3c0] ioctl(VIDIOC_G_FMT): Invalid argument | |||
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument | |||
Error initializing output stream 0:0 -- | |||
Conversion failed! | |||
~/Videos/Captures> | |||
</syntaxhighlight> | |||
[[VLC]] does while reading: | |||
<syntaxhighlight lang="bash"> | |||
VLC is unable to open the MRL 'v4l2:///dev/video0'. Check the log for details. | |||
</syntaxhighlight> | |||
While the device looks normal: | |||
<syntaxhighlight lang="bash"> | |||
~Videos/Captures # v4l2-ctl --list-devices | |||
OBS Virtual Camera (platform:v4l2loopback-000): | |||
/dev/video0 | |||
Integrated Camera: Integrated C (usb-0000:06:00.4-3): | |||
/dev/video1 | |||
/dev/video2 | |||
/dev/video3 | |||
/dev/video4 | |||
/dev/media0 | |||
/dev/media1 | |||
~/Videos/Captures # v4l2-ctl --all | |||
Driver Info: | |||
Driver name : v4l2 loopback | |||
Card type : OBS Virtual Camera | |||
Bus info : platform:v4l2loopback-000 | |||
Driver version : 6.4.12 | |||
Capabilities : 0x85200000 | |||
Read/Write | |||
Streaming | |||
Extended Pix Format | |||
Device Capabilities | |||
Device Caps : 0x05200000 | |||
Read/Write | |||
Streaming | |||
Extended Pix Format | |||
Priority: 2 | |||
User Controls | |||
keep_format 0x0098f900 (bool) : default=0 value=0 | |||
sustain_framerate 0x0098f901 (bool) : default=0 value=0 | |||
timeout 0x0098f902 (int) : min=0 max=100000 step=1 default=0 value=0 | |||
timeout_image_io 0x0098f903 (bool) : default=0 value=0 | |||
~Videos/Captures # | |||
</syntaxhighlight> | |||
[https://www.youtube.com/watch?v=5UT8RkSmN4k Did you try turning it off and on again?] | |||
<syntaxhighlight lang="bash"> | |||
# modprobe -r v4l2loopback | |||
# modprobe v4l2loopback | |||
</syntaxhighlight> | |||
= Footer = | = Footer = |
Latest revision as of 16:53, 7 September 2023
Why?
To attend a meeting while streaming a previous recorded video showing me as attentive (or busy) as possible. I'm such a nice subordinate…
HowTo
Installation
# zypper install v4l2loopback-utils v4l2loopback-autoload v4l2loopback-kmp-default
Creating a loopback-device
The kernel module does that per default:
# v4l2-ctl --list-devices
OBS Virtual Camera (platform:v4l2loopback-000):
/dev/video0
Integrated Camera: Integrated C (usb-0000:06:00.4-3):
/dev/video1
/dev/video2
/dev/video3
/dev/video4
/dev/media0
/dev/media1
#
Streaming
ffmpeg -re -i VIDEO_TO_SHOW.m4v -vf format=yuv420p -f v4l2 /dev/video0
Loop it:
ffmpeg -re -i VIDEO_TO_SHOW.m4v -vf format=yuv420p -f v4l2 -stream_loop -1 /dev/video0
Testing the stream
Using VLC
Nice to know
Capturing from a video camera
Media→ Open Capture Device…
- Select your camera
- Choose
Stream instead of Play (Button)
- …(use the wizard)…
These capture can be pretty large, so transcoding[1] might be ca good idea:
ffmpeg -i Capture\ 2023-09-07_01_8min.avi -c:v libx264 -preset slow -crf 30 -c:a copy output.mkv
Where CRF is the quality (0==lossless, 51==useless).
Known issues
Device is not writable
ffmpeg tells while writing to the loopback:
Press [q] to stop, [?] for help
[video4linux2,v4l2 @ 0x55f1026fc3c0] ioctl(VIDIOC_G_FMT): Invalid argument
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
Conversion failed!
~/Videos/Captures>
VLC does while reading:
VLC is unable to open the MRL 'v4l2:///dev/video0'. Check the log for details.
While the device looks normal:
~Videos/Captures # v4l2-ctl --list-devices
OBS Virtual Camera (platform:v4l2loopback-000):
/dev/video0
Integrated Camera: Integrated C (usb-0000:06:00.4-3):
/dev/video1
/dev/video2
/dev/video3
/dev/video4
/dev/media0
/dev/media1
~/Videos/Captures # v4l2-ctl --all
Driver Info:
Driver name : v4l2 loopback
Card type : OBS Virtual Camera
Bus info : platform:v4l2loopback-000
Driver version : 6.4.12
Capabilities : 0x85200000
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x05200000
Read/Write
Streaming
Extended Pix Format
Priority: 2
User Controls
keep_format 0x0098f900 (bool) : default=0 value=0
sustain_framerate 0x0098f901 (bool) : default=0 value=0
timeout 0x0098f902 (int) : min=0 max=100000 step=1 default=0 value=0
timeout_image_io 0x0098f903 (bool) : default=0 value=0
~Videos/Captures #
Did you try turning it off and on again?
# modprobe -r v4l2loopback
# modprobe v4l2loopback