VLC record webcam and stream to chrome linux
Asked Answered
H

1

3

I am currently looking for how to accomplish what I have been told is possible.

I was told that we would be able use vlc to stream a webcam in linux which would allow for the following:

  • Recording the stream to the local machine for a later upload.
  • Play the stream as it's recording using Chrome's HTML5 video capabilities.
  • Send a start and stop command from the web for the vlc recording.

I have been researching this for quite some time and haven't been able to find a viable solution.

I am able to record video using VLC already with the following

vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=640 :v4l2-height=480 --sout "#transcode{vcodec=mpeg4,acodec=mpga,vb=800,ab=128}:standard{access=file,dst=capture_4.avi}"

Is this really even possible?

Hanako answered 9/6, 2011 at 18:14 Comment(0)
L
17

To answer your question if this is possible... YES it is BUT it's tricky. I can't answer all your points, only the part with streaming in VLC and displaying it in HTML5

You'll need a certain environment setup for this to work (Segmenter and correct MIME Type on server). I assume you are all on linux; which I am not (Mac OS / unix) but the principles behind it stay the same concerning the workflow of getting this to work. I'll try to explain - hope this helps in any way.

The setup I've had success with works the following way:

(1) STREAMING & RECORDING

local vlc streaming instance streaming audio and video -> producing a mpegts stream. Try changing your command to something like

vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=640 :v4l2-height=480 --sout "#transcode{vcodec=mpeg4,acodec=mpga,vb=800,ab=128}:standard{access=udp, mux=ts, sap, name=live-video, dst=224.0.0.1, port=1234}"

or

vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=640 :v4l2-height=480 --sout "#transcode{vcodec=mpeg4,acodec=mpga,vb=800,ab=128}:udp{dst=224.0.0.1,port=1234,mux=ts}"

I'm just giving you ported commands here which work on Mac. I don't know if they work on linux. Now you should be able to play the live stream with VLC by accessing the SAP announcement or directly with

vlc -vvv udp://@224.0.0.1:1234

You could then use another vlc instance to record the stream

vlc udp://@224.0.0.1:1234 --sout "#transcode{vcodec=mpeg4,acodec=mpga,vb=800,ab=128}:standard{access=file,dst=capture_4.avi}"

There is a duplicate command in VLC which I have been playing around with but without success. This way you could stream and record with one instance. Maybe this works on linux.

(2) SEGMENTING

mediastreamsegmenter to segment your mpegts stream into deliverable segments. I'm using Apple Server Software. Apple provides you with a mediastreamsegemnter which can take a live mpegts stream and convert it into segments which are added to a playlist. I don't know of a live segmenter in linux. Maybe someone else does.

(3) DELIVERY

html 5 page linking to the video playlist containing the segments. The mediastreamsegmenter will produce a playlist playlist.m3u8, which then can be accessed with HTML 5

<video width="640" height="480">
<source src="YOUR_PATH/playlist.m3u8" />
</video>

Some helpful tutorials concerning this topic are:

Info on the setup and basic commands

VLC examples in order to stream

I know this is not a complete solution to your problem, but this will maybe give you some nice starting points to look into.

Longlongan answered 14/6, 2011 at 19:11 Comment(3)
Thanks for the great feedback ... we ended up taking the flash approach to this problem in the endHanako
Can I ask a small question? what does the Ip dst=224.0.0.1 represents ? I try different numbers but it didn't work for me?Loya
@Loya Look here: iana.org/assignments/multicast-addresses/… It represents a multicast address. Use 224.0.0.1 with care and NEVER in productive setups. Rather play around with 239.0.0.1 or so...Longlongan

© 2022 - 2024 — McMap. All rights reserved.