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?
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.
来源:https://stackoverflow.com/questions/6297348/vlc-record-webcam-and-stream-to-chrome-linux