Streaming webcam to HTTP using VLC

One of very common task working with webcam is to streaming it to web via HTTP. There are many ways to do it, and I will tell you how to do with VLC.

First is to make sure the webcam is connected and playing well, confirm it by,

$ vlc v4l2:///dev/video0

If you see the webcam playing on VLC, it works fine.

In VLC, to make an output stream, you will need to out –sout option with specified output module. Since we are trying to streaming out to HTTP, we will use std module with access option set to http, along with mpjpeg muxer. So, the command will be,

$ vlc v4l2:///dev/video0 --sout ‘#std{access=http,mux=mpjpeg,dst=IP:PORT}’

To confirm the output stream,

$ vlc http://IP:PORT

Well, up to this point, it just might work well for several cameras, not all. The reason is that default streaming output format from webcam often being YUYV as I mentioned in previous article.

To solve this, we can just apply the transcode module from VLC,

$ vlc v4l2:///dev/video0 --sout ‘#transcode{vcodec=mjpg}:std{access=http,mux=mpjpeg,dst=IP:PORT}’

Try to play the HTTP stream again, it should work. To make the output HTTP stream to be able to be played via web HTML5 video, MIME should be present,

$ vlc v4l2:///dev/video0 --sout ‘#transcode{vcodec=mjpg}:std{access=http{mime=multipart/x-mixed-replace;boundary=-7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=IP:PORT}’

To enable GPU (hardware-acceleration), use the chroma= option as I mentioned before.

$ vlc v4l2:///dev/video0:chroma=mjpg --sout ‘#std{access=http{mime=multipart/x-mixed-replace;boundary=-7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=IP:PORT}’

Have fun :)


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.