How to stream with ffmpeg via http protocol
Asked Answered
R

2

22

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.

Reparable answered 3/6, 2014 at 14:33 Comment(8)
check the docs : trac.ffmpeg.org/wiki/StreamingGuideAffair
I've already read through them a few times, but it did not resolve my specific issue.Reparable
Use flv instead of mp4 if you're attempting live streaming: ffmpeg -i input -c:v libx264 -maxrate 1000k -bufsize 2000k -g 50 http://localhost:8080/test.flv Also see trac.ffmpeg.org/wiki/EncodingForStreamingSitesLuehrmann
Sadly, I'm still getting http://localhost:8080/test.flv: Input/output error then.Reparable
Where you able to fix it?Forbear
@Forbear I don't think I was, but now I am creating m3u8 playlists over HTTP, which Flowplayer can read in using a plugin. Works very well.Reparable
What error message?Pyrrhonism
Please also provide information like an error message and what software you are using to provide the file over https://localhost:8080/ as this requires serving the file from the system you're using ffmpeg on. The best guess I can make now is that there is nothing serving the file on the system where ffmpeg is being run fromOutfielder
H
11

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.

Holcomb answered 29/7, 2022 at 3:10 Comment(1)
When I do this ffmpeg shows a bunch of lines and then 'handler_name : VideoHandler' and then sits there idling. I can't seem to play the stream from another computer. When I try to play this with vlc I get in the logs: 'no access_demux modules matched'. Any suggestions?Chewy
C
-4

you need this command line

ffmpeg -f v4l2 -s 320x240 -r 25 -i /dev/video0 -f alsa -ac 1 -i hw:0 http://localhost:8090/feed1.ffm

make sure that your feed name ends with ".ffm" and if it's not the case, then add "-f ffm" before your feed URL, to manually specify the output format (because ffmpeg won't be able to figure it out automatically any more), like this "-f ffm http://localhost:8090/blah.bleh".

Crusade answered 25/2, 2016 at 8:53 Comment(1)
getting error at the input video file 'inappropriate ioctl for device'Maurilia

© 2022 - 2024 — McMap. All rights reserved.