Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is rather a simple question, but I cannot find the answer. I need to stream from a capture device to a server, and then have FFMPEG on the server re-code the stream suitable for HLS.

But how do I do this? I looked at Flash Media Live Encoder and VLC and ffserver but cannot really get my handle on how this should work. Basically it just seems to me I need a program to sent to a server, which accepts the stream (and maybe some user authentication) and then makes the stream available for use. I already have a system that takes files and encodes them for HLS, so then I can just as input parameter point to this application on the local server to take the stream and start encoding.

edit: it is really only the step to accept e.g. a rtmp connection and make that available to FFMPEG on the same server. I was hoping that e.g. ffserver could do that, but I don't think so.

share|improve this question

migrated from stackoverflow.com Mar 16 '13 at 18:21

This question came from our site for professional and enthusiast programmers.

    
This is actually a very hard problem in general. –  Jason Mar 15 '13 at 19:17

3 Answers 3

up vote 3 down vote accepted

I came across a streaming server called crtmpserver (or rtmpd) which seems small but does exactly what I want with a few small changes to the code.

share|improve this answer

You can read this guide which is very helpfull to learn to work with FFmpeg. In my opinion you should be able to create a good solution using that guide, because allmost all aspects of FFmpeg you need are in there. Also, splitting your project in little parts is one great step. Just try to get a stream from your device first and then try to view it with VLC (Which is also using FFmpeg). Then you can work on the server to broadcast your stream. Good luck!

share|improve this answer
    
Thanks Nick! I have the ffmpeg part in place. The difficulty is to have something 'in the middle' to accept, let's say a a rtmp connection from Flash Media Live Encoder, and then make it available to FFMPEG. I really just need something to connect my client to so FFMPEG can connect. I have a demo of Red5 installed, and that might work, but seems a bit of overkill. –  Luuk D. Jansen Mar 15 '13 at 22:00
1  
I don't know if I misunderstand you, but FFmpeg can input your stream immediately. So yes, you can also use FFserver, which is one of the programs provided by FFmpeg. You can also combine the FFmpeg program and the FFserver program on one server. Here another link where they are combined: Streaming media with FFserver –  Nick van Tilborg Mar 15 '13 at 22:12
    
I think ffserver only takes an input from ffmpeg. I need to connect using rtmp (or something) to the 'server' in order to restream it and make it available to ffmpeg. I cannot have ffmpeg connect directly as the capture device will be somewhere in the field, so I cannot rely on having the IP address etc. The client/capture machine needs to connect to the server in some way, so ffmpeg then has a fixed connection point. –  Luuk D. Jansen Mar 15 '13 at 22:20
2  
So you mean the device itself connects to the server, then the server starts listening to the device stream and broadcasts that stream to the internets. In that case, just create a simple program on your server which is listening to new streams. On your device you send out a trigger to your server. On the server, when a new stream is provided you start FFmpeg to input that stream and start a broadcast stream. FFmpeg can do it all what you want. And again, FFserver is just a small program containing the same libraries as the default FFmpeg program uses. Try experimenting with it. –  Nick van Tilborg Mar 15 '13 at 22:31
    
Yes, that is what I want. Very simple. However, I don't know if I have the networking skills to write this. Let's take Flash Media Live Encoder as the example. I am sure there is some handshaking involved etc. in the protocol. But I might have a look. It would be nice as I can in that case integrate it into my own Java App on the Play Framework, which would save a lot of resources and gives me control on the connection. –  Luuk D. Jansen Mar 15 '13 at 22:56

maybe this working example can help you a little further.

It streams a live stream (webcam) via vlc to a webpage in hls. The webcam could by any other live streaming device or capture card. The webpage uses the specific streaming features of HTML5.

cvlc v4l2:// :v4l2-vdev="/dev/video0" --sout '#transcode{vcodec=h264,vb=512,scale=1,acodec=none,venc=x264{aud,profile=high,level=60,keyint=15,bframes=0,ref=1,nocabac}}:duplicate{dst=std{access=livehttp{seglen=10,delsegs=true,numsegs=5,index=/var/www/live/mystream.m3u8,index-url=http://"Here your webserverIP"/live/mystream-########.ts},mux=ts{use-key-frames},dst=/var/www/live/mystream-########.ts},dst=std{access=http,mux=ts,dst=:8082/video.mp4}}' &

The commandline generates two output streams, one HLS for streaming via a webpage, and a MP4 stream, that can be accessed directly by a VLC player in the same network.

Just set the proper directories and put in the actual webserver IP addresses.

For the webserver I used a standard setup of lighttpd and created the index.html file with the following HTML 5 stream definition:

<!DOCTYPE html>
<html>
<head>
    <title>Live Cam</title>
</head>

<body>
    <div id="player">
        <video autoplay="true" controls="controls" width="640" height="480">
            <source src="http://"Here your webserverIP"/live/mystream.m3u8" type="application/x-mpegURL" />
            Your browser does not support HTML5 streaming!
        </video>
    </div>
</body>
</html

Connect your webcam, create the index.html file, restart your webserver and then execute the commandline (as normal user). It it all works you can access your streaming source on all I-devices.

I have tried to do the same with ffmpeg (segment and hls) with and without ffserver and even with avconv and avserver, but so far without success.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.