Ffmpeg can't assign requested address for http stream

I’m writing a script to stream webcam video / audio to http or rtmp using ffmpeg. I managed to get the capture devices right and have them output to mp4 file, streaming to UDP also seems to work but I want to go with TCP. For some reason ffmpeg always complains about the connection and is unable to access the address.

ffmpeg -f video4linux2 -i /dev/video0 -f alsa -i hw:2 -f mpegts

This instantly gives the error connection refused. I understand I need to add the parameter -listen 1 for http to work, I did so but now the error then becomes cannot assign requested address. Some articles suggested using ffserver but that command doesn’t exist, I take it the normal ffmpeg command acts as that now? Firewall settings and port forwarding in the router are configured and shouldn’t be the problem.

Please keep in mind that using tcp doesn’t mean it is http streaming. ffmpeg aliases http to tcp, but it is not what most player understand as http streaming.

For tcp streaming you need to specify a path, that is called listen. Like,

ffmpeg ... -f mpegts "tcp://"

If you don’t quote it, you need to escape the questing mark.

You can watch it with VLC for example.

vlc "tcp://"

A little weird, but with mpv you will need to specify http instead of tcp.

mpv ""
1 Like

Thanks: I seem to have at least in theory gotten it sensing the connection on localhost IP. A weird problem appears to be that once VLC closes the connection, ffmpeg issues an “end of file” message and shuts down: Someone elsewhere reminded me that a TCP might be expecting a two-way connection, and isn’t meant to be on-demand like UDP which might be closer to what I need.

This is can be expected with tcp. With tcp, the streaming starts not immediately, it start only after a client connects and ffmpeg exists after the client disconnects. Like UDP, only one client at the same time is possible. You would need to use some kind of script start make sure to restart ffmpeg.

An alternativ would be to use something kind of server to handle his, for example nginx with the rtmp-module that starts the ffmpeg processes. But this is more complicated to set up.