Live video and audio streaming with ffmpeg and ffserver
This is a guide on how to stream video using ffserver and ffmpeg in ubnutu. The ffmpeg ffserver version used is 3.3-1~16.04.york1. You can download ffserver from ffmpeg.org. I'm using linux mint 18. So, I've downloaded ffmpeg from the repository. You can follow the link below to install the latest version of ffmpeg.
Install ffmpeg in linux mint 18 using command line.
First, we need to setup our ffserver.conf to stream the audio and video properly. ffserver.conf file is usually located in /etc/ffserver.conf. You can either edit the ffserver.conf or create your own .conf file. I'll be creating my own .conf file named livestream.conf
In console, type
Blank .ffm file will be created. Now, enter the required properties for streaming live video using ffserver
We have to be careful while chosing the properties for streaming, you can play around with them and use which is appropriate for you. But, video bitrate, size, frame rate, audio bitrate, codec used must be accurate.
After all the properties are set we've to start ffserver first. If you will start the ffmpeg without starting the ffserver, it will show the error like tcp connection refused like this:
Output in console:
If everything went well ffmpeg will start writing data to video.ffm located in /tmp directory.
Now, we can read the data from our browser or vlc media player.
In the browser, enter the following link
http://localhost:8090/stream
In vlc, go to media>stream>network and enter the streaming url and press play button.
We can now stream live video using ffmpeg and ffserver.
This is a guide on how to stream video using ffserver and ffmpeg in ubnutu. The ffmpeg ffserver version used is 3.3-1~16.04.york1. You can download ffserver from ffmpeg.org. I'm using linux mint 18. So, I've downloaded ffmpeg from the repository. You can follow the link below to install the latest version of ffmpeg.
Install ffmpeg in linux mint 18 using command line.
First, we need to setup our ffserver.conf to stream the audio and video properly. ffserver.conf file is usually located in /etc/ffserver.conf. You can either edit the ffserver.conf or create your own .conf file. I'll be creating my own .conf file named livestream.conf
In console, type
sudo nano /etc/livestream.conf
Blank .ffm file will be created. Now, enter the required properties for streaming live video using ffserver
#Default port
HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 100000
CustomLog -
#############################################################
<Feed video.ffm>
File /tmp/video.ffm # this creates a temp video.ffm file where streams are read/write
FileMaxSize 1G
ACL allow localhost
ACL allow 127.0.0.1
ACL allow 192.168.0.0 192.168.255.255
</Feed>
<Stream stream>
# streaming for webm file
# run : ffserver -f /etc/ffserver.conf
# run : ffmpeg -i videoname.mp4 http://localhost:8090/video.ffm
# error : encoder setup failed
Feed video.ffm
Format webm
# Audio settings
AudioCodec vorbis
AudioBitRate 64 # Audio bitrate
# Video settings
VideoCodec libvpx
VideoSize 720x486 # Video resolution
VideoFrameRate 30 # Video FPS
AVOptionVideo flags +global_header # Parameters passed to encoder
AVOptionVideo cpu-used 0
AVOptionVideo qmin 10 # lower the better, min 0
AVOptionVideo qmax 42 # higher outputs bad quality, max 63
AVOptionVideo quality good
AVOptionAudio flags +global_header
PreRoll 15
StartSendOnKey
VideoBitRate 400 # Video bitrate
</Stream>
###########################################################################
# Audio only
# run ffmpeg -i audio.mp3 http://localhost:8090/audio.ffm
# run http://localhost:8090/audio in vlc or browser
<Feed audio.ffm>
File /tmp/audio.ffm
FileMaxSize 1G
ACL allow localhost
ACL allow 127.0.0.1
ACL allow 192.168.0.0 192.168.255.255
</Feed>
<Stream audio>
Feed audio.ffm
Format mp2 #audio format
AudioCodec libmp3lame #audio codec
AudioBitRate 64 #audio bitrate
AudioChannels 1 #audio channel, 1 for mono and 2 for stereo
AudioSampleRate 44100
NoVideo #discard video
</Stream>
####################################################################
#view status of ffserver
<Stream stat.html>
Format status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
# Redirect index.html to the appropriate site
<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>
We have to be careful while chosing the properties for streaming, you can play around with them and use which is appropriate for you. But, video bitrate, size, frame rate, audio bitrate, codec used must be accurate.
After all the properties are set we've to start ffserver first. If you will start the ffmpeg without starting the ffserver, it will show the error like tcp connection refused like this:
[tcp @ 0x56347fda1360] Connection to tcp://localhost:8090 failed: Connection refused
http://localhost:8090/video.ffm: Connection refused
start the ffserver by typingffserver -f /etc/livestream.conf
FFserver will fetch the file located at /etc and start the ffserverOutput in console:
Fri May 12 20:53:02 2017 FFserver started.
Now start ffmpeg so that we can pass the input video and stream it to video.ffm we described inside livestream.conf fileffmpeg -i Big\ Buck\ Bunny.mp4 http://localhost:8090/video.ffm
We can define all other properties in the above command line like
video size, framerate, audio and video codec as well. For more, please
visit the ffmpeg documentation.If everything went well ffmpeg will start writing data to video.ffm located in /tmp directory.
Now, we can read the data from our browser or vlc media player.
In the browser, enter the following link
http://localhost:8090/stream
In vlc, go to media>stream>network and enter the streaming url and press play button.
We can now stream live video using ffmpeg and ffserver.
Comments
Post a Comment