Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stream with ffmpeg via http protocol

I'm currently doing a stream that is supposed to display correctly within Flowplayer. First I send it to another PC via RTP. Here, I also checked with VLC that the codec etc. arrive correctly, which they do.

Now I want to expose this stream to Flowplayer as a file, so it can be displayed, via something I used in VLC: http://localhost:8080/test.mp4 for example.

The full line I got is: ffmpeg -i input -f mp4 http://localhost:8080/test.mp4

However, no matter how I try to do this, I only get an input/output error. Is this only possible with something like ffserver or another?

What I think is this doesn't work because ffmpeg can't act as a server; on VLC it works since it can. (Though VLC ruins the codecs I set and it can't be read afterwards for some reason)

A (sort of) workaround I can use is saving the RTP stream to a file, and then letting flowplayer load it. This, however, only works once the file is not accessed anymore; I get a codec error otherwise.

like image 432
Boehmi Avatar asked Sep 12 '25 14:09

Boehmi


1 Answers

To have FFmpeg act as an HTTP server, you need to pass the -listen 1 option. Additionally, -f mp4 will result in a non-fragmented MP4, which is not suitable for streaming. You can get a fragmented MP4 with -movflags frag_keyframe+empty_moov. A full working command line is:

ffmpeg -i input -listen 1 -f mp4 -movflags frag_keyframe+empty_moov http://localhost:8080

Other options you may find helpful are -re to limit the streaming speed to the input framerate, -stream_loop -1 to loop the input, and -c copy to avoid reencoding.

like image 194
leo60228 Avatar answered Sep 15 '25 11:09

leo60228