Multimedia: FFMpeg
Streaming with FFMPEG
The simplest command line you can use to generate an RTP session composed by an audio stream and a video stream from an mp4 audio/video file is:
ffmpeg -re -i Videos/big_buck_bunny_720p_h264.mp4 \ -vcodec copy -an -f rtp rtp://192.168.1.4:9000 \ -vn -acodec copy -f rtp rtp://192.168.1.4:9002
Analysing this command line:
- “-re” is needed to stream the audio and the video at the correct rate (instead of streaming as fast as possible)
- “input.mpg” is the input file, to be streamed
- “-vcodec copy” and “-acodec copy” mean the audio and the video tracks will be streamed without re-encoding them
- “-f rtp” meand that the output format is RTP; we need one output stream for the video, and one for the audio. Hence, the first output has “-an” (no audio), the second output has “-vn” (no video)
- The output protocol is RTP, hence, the output file names are “rtp://:”
After you start the ffmpeg program, it will print something like
v=0 o=- 0 0 IN IP4 0.0.0.0 s=No Name t=0 0 a=tool:libavformat 58.17.101 m=video 9000 RTP/AVP 96 c=IN IP4 192.168.1.4 b=AS:2972 a=rtpmap:96 H264/90000 a=fmtp:96 packetization-mode=1; sprop-parameter-sets=J0IAH5WQBQBbsBEAESqIAzf5gOBAAC3GwABbja974O0OGSQ=,KM48gA==; profile-level-id=42001F m=audio 9002 RTP/AVP 97 c=IN IP4 192.168.1.4 b=AS:188 a=rtpmap:97 MPEG4-GENERIC/48000/6 a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=11B0
You need to copy the SDP description (starting with “v=0”) in a .sdp file, that you will use to play the stream with vlc, ffplay, mplayer, or your favorite video player.
- FFmpeg Streaming Guide
- FFmpeg – the swiss army knife of Internet Streaming – part IV
- How can I generate a video file directly from an FFmpeg filter with no actual input file?
- Esempi d’utilizzo di ffmpeg e ffprobe
- Is sprop-parameter-sets or profile-level-id the SDP parameter required to decode H264?
- Using FFmpeg’s lavfi (libavfilter)
FFmpeg Docker containers
- FFmpeg Docker image (jrottenberg/ffmpeg) – based on Ubuntu, CentOS, Alpine
- Minimal FFmpeg Docker image built on Alpine Linux (opencoconut/ffmpeg)
Other FFMpeg examples
ffmpeg -f lavfi -i sine=f=220:b=4:d=5 -c:a libvorbis output.oga
ffmpeg -f lavfi -i testsrc -f lavfi -i sine -t 10 -c:v libtheora -c:a libvorbis \
-q:v 5 -q:a 5 output.ogvffmpeg -i http://archive.org/download/thethreeagesbusterkeaton/Buster.Keaton.The.Three.Ages.ogv -loop 0 -final_delay 500 -c:v gif -f gif -ss 00:01:20 -t 5 - > book_opening.gif
Streaming with VLC
http://www.jpsaman.org/sites/jpsaman.org/files/vlc-streaming-nluug.pdf