Red5 Documentation

Reading RTSP Streams

Reading a stream using FFmpeg over RTSP is little different from the RTMP example. Here we don’t use the librtmp module. Instead, FFmpeg makes use of its own internal RTSP reader.

Sample command to dump a live stream to an MP4 file.

ffmpeg  -i rtsp://127.0.0.1:8554/live/streamname  -acodec copy -vcodec copy -f mp4 stream.mp4

Sample Output

ffmpeg version N-82597-gd316b21 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 40.100 / 55. 40.100
  libavcodec     57. 66.106 / 57. 66.106
  libavformat    57. 58.100 / 57. 58.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 67.100 /  6. 67.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
[rtsp @ 00000000007c6c80] method SETUP failed: 461 Unsupported transport
Input #0, rtsp, from 'rtsp://127.0.0.1:8554/live/streamname':
  Metadata:
    title           : streamname
  Duration: N/A, start: 6461.310000, bitrate: N/A
    Stream #0:0: Audio: aac (LC), 48000 Hz, mono, fltp
    Stream #0:1: Video: h264 (Constrained Baseline), yuv420p(progressive), 640x480, 30 fps, 62.50 tbr, 90k tbn, 60 tbc

Press [q] to stop, [?] for help
frame=   31 fps= 21 q=-1.0 size=     111kB time=00:00:01.53 bitrate= 590.5kbits/s speed=1.02x

When reading stream over RTSP you may see this in the FFmpeg output: [rtsp @ 0000000000026c80] method SETUP failed: 461 Unsupported transport. But the processing will resume nevertheless after a 1-second pause.

NOTE: Throughout the examples in this document, we will be reading a Red5 Pro stream over RTMP to demonstrate various commands. You can use RTSP protocol as well if you wish, as explained earlier.

Sample command to re-encode & dump an RTMP live stream to an MP4 file

Linux

ffmpeg  -i "rtmp://127.0.0.1:1935/live/streamname live=1 timeout=2" -vcodec libx264  -vb 500k -vprofile baseline -level 3.0 -acodec libfdk_aac -ab 64000 -ar 48000 -ac 2 -preset fast -f mp4 stream.mp4

Windows

ffmpeg  -i "rtmp://127.0.0.1:1935/live/streamname live=1 timeout=2" -vcodec libx264  -vb 500k -vprofile baseline -level 3.0 -acodec aac -ab 64000 -ar 48000 -ac 2 -strict experimental -preset fast -f mp4 stream.mp4

Sample command to re-encode & dump an RTSP live stream to an MP4 file

Linux

ffmpeg  -i rtsp://127.0.0.1:8554/live/streamname  -vcodec libx264  -vb 500k -vprofile baseline -level 3.0 -acodec libfdk_aac -ab 64000 -ar 48000 -ac 2 -preset fast -f mp4 stream.mp4

Windows

ffmpeg  -i rtsp://127.0.0.1:8554/live/streamname -vcodec libx264  -vb 500k -vprofile baseline -level 3.0 -acodec aac -ab 64000 -ar 48000 -ac 2 -strict experimental -preset fast -f mp4 stream.mp4