From Wikipedia, Video4Linux (V4L for short) is a collection of device drivers and an API for supporting real-time video capture on Linux systems.
V4L (or it's successor V4L2) are used in many scenarios, such as applying effects to your stream.
Let's Stream
Load the V4L2 module first:
$ modprobe v4l2loopback
The command above will create a virtual video device.
To check the available video devices:
$ v4l2-ctl --list-devices
A "Dummy video device" should be available, for simplicity, we will call this device /dev/video2.
Map the video stream:
$ ffmpeg -re -i VIDEO_NAME.mp4 -map 0:v -f v4l2 /dev/video2
I use VLC to play the video
$ vlc v4l2:///dev/video2
You can also stream from a URL, for example, to stream from an .m3u8 playlist:
$ ffmpeg -i 'https://www.example.com/video/file.m3u8' -c copy -vcodec rawvideo -threads 0 -f v4l2 /dev/video2
The video can now be accessed in real-time from /dev/video2.
Also Youtube-dl can be used to obtain a HLS link to the m3u8 playlist, just use the -g flag
$ youtube-dl -g https://www.youtube.com/watch?v=QquG9a8xpfk
You can use webcamtests.com to see /dev/video2 from your browser.
Top comments (0)