• How to use FFmpeg with Media Wowza Server (MPEG-TS)

    Step-by-step instructions for using FFmpeg as a live video/audio encoder with Wowza Media Server®.

    Note: Updated for FFmpeg version N-52458-gaa96439 (04-30-2013)

    Note: Wowza® Media Systems provides these instructions on as "AS-IS" basis. FFmpeg is not a Wowza Media Systems product. If you have problems getting FFmpeg to work properly, contact FFmpeg.

    To get started, download and install FFmpeg for your platform on the same computer that's running Wowza Media Server. I used the most recent daily build of FFmpeg from http://ffmpeg.zeranoe.com/builds//.

    FFmpeg Setup


    Note: The examples below demonstrate re-streaming using the Wowza Media Server sample video file [install-dir]/content/sample.mp4 on Windows operating systems.

    1. In the root the C: drive, create the following directory structure:
      Code:
      C:/usr/local/share/ffmpeg
      Copy all of the files from the presets folder in the FFmpeg package to this new directory.

    2. Open a command prompt and change directory to the FFmpeg bin folder.

    3. Enter the following FFmpeg command to re-stream the file sample.mp4 from the [install-dir]/content folder of the Wowza Media Server installation:
      Code:
      ffmpeg -re -i "%WMSAPP_HOME%/content/sample.mp4"  -vcodec libx264  -vb 150000 -g 60 -vprofile baseline -level 2.1 -acodec aac -ab 64000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -strict experimental -f mpegts udp://127.0.0.1:10000?pkt_size=1316

    Next, follow the instructions in the following tutorial:


    See Also:



    Notes


    • The sample.mp4 file is about 10 minutes long. FFmpeg will stop when it hits the end of this file, so you may have to restart FFmpeg several times during configuration and testing.

    • The above FFmpeg command lines will produce a low bitrate, low complexity, low quality stream that should be playable on most playback devices and systems. The following is a higher quality version that provides a glimpse of what VideoLAN (VLC) can do:
      Code:
      ffmpeg -re -i "%WMSAPP_HOME%/content/sample.mp4"  -vcodec libx264  -vb 500000 -g 60 -vprofile main -acodec aac -ab 128000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -strict experimental -f mpegts udp://127.0.0.1:10000?pkt_size=1316
    • FFmpeg can also be used to transcode an RTSP, native RTP, or MPEG-TS stream. Just change the first argument of each of the command lines (the path to the sample.mp4 file) to the desired source to be transcoded and remove the -re command line option. Here are a few examples:

      RTSP/RTP camera
      Code:
      ffmpeg -i "rtsp://192.168.1.22/mycamera" -vcodec libx264 -vb 150000 -g 60 -vprofile baseline -level 2.1 -acodec aac -ab 64000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -strict experimental -f mpegts udp://127.0.0.1:10000?pkt_size=1316
      MPEG-TS stream
      Code:
      ffmpeg -i "udp://localhost:1234" -vcodec libx264 -vb 150000 -g 60 -vprofile baseline -level 2.1 -acodec aac -ab 64000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -strict experimental -f mpegts udp://127.0.0.1:10000?pkt_size=1316
      Native RTP stream
      Code:
      ffmpeg -i "unicast.sdp" -vcodec libx264 -vb 150000 -g 60 -vprofile baseline -level 2.1 -acodec aac -ab 64000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -strict experimental -f mpegts udp://127.0.0.1:10000?pkt_size=1316
    • If you want to host FFmpeg on a different computer as the server hosting Wowza Media Server, you can modify any of the above command lines by changing udp://127.0.0.1:10000 to the IP address of the server running Wowza Media Server and any destination UDP port. Be sure that the specified UDP port is open on any routers or firewalls between the server running VLC and the server running Wowza Server.

    • FFmpeg can publish streams using other outgoing protocols such as RTMP and RTSP/RTP (QuickTime ANNOUNCE). To send a stream using RTMP, change the destination portion of the FFmpeg URL:

      From:
      Code:
      -f mpegts udp://127.0.0.1:10000?pkt_size=1316
      To:
      Code:
      -f flv rtmp://127.0.0.1/live/myStream
      The format of the RTMP URL portion is:
      Code:
      rtmp://[wowza-ip-address]/[application]/[streamName]
      To send a stream using RTSP/RTP, change the destination portion of the FFmpeg URL:

      From:
      Code:
      -f mpegts udp://127.0.0.1:10000?pkt_size=1316
      To:
      Code:
      -f rtsp rtsp://127.0.0.1:1935/live/myStream.sdp
      The format of the RTMP URL portion is:
      Code:
      rtsp://[wowza-ip-address]:1935/[application]/[streamName]
    • Microsoft Silverlight players prefer a 2-second key frame frequency. If you set the -r (fps) flag to half of the -g (GOP) setting, the stream will have a 2-second key frame frequency. In the above examples where -g is 48, you would set -r 24.




    Comments 18 Comments
    1. LearnerDev -
      File for preset 'default' not found

      thats the error im getting
    1. rrlanham -
      Follow the steps in that guide to copy the presets

      Richard
    1. LearnerDev -
      i did but when i run the command this error pops up
    1. iyusuf -
      Quote Originally Posted by LearnerDev View Post
      File for preset 'default' not found

      thats the error im getting
      Have you tried without setting ffmpeg presets like bellow ? It works for me.

      %FFMPEG_HOME%/ffmpeg.exe -i "%WMSAPP_HOME%/content/sample.mp4" -re -vcodec libx264 -g 60 -vb 150000 -strict experimental -acodec aac -ab 96000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -f mpegts udp://127.0.0.1:10000?pkt_size=1316
    1. arouaoui.med@hotmail.fr -
      Hi i try your first link and the same prompt of LearnerDev
      i try the second link proposed by iyusuf and a have an other prompt "Error while opening encoder for output stream #0.0 - maybe incorrect parametres such as bit_rate, rate, width or height"
      can you share your sample.mp4 video to be sure of video parametres plz ???
    1. randall -
      arouaoui,

      The way ffmpeg handles presets has changed in recent version. From -vpre to -preset I believe. I've gotten around the "File for preset not found" error by specifying the complete path to the preset files in the command. Also, it is possible you do not have x264 installed. These types of ffmpeg errors are not really Wowza problems, so you may have better results troubleshooting them in the ffmpeg support resources: forums, mailing lists, IRC channels, etc..
    1. randall -
      The following ffmpeg command is working for me on Debian Squeeze with ffmpeg version git-2012-01-22-72b33ea:
      Code:
      ffmpeg -re -i sample.mp4 -vcodec libx264 -vprofile default -vprofile baseline -r 24 -g 48 -vb 150000 -strict experimental -acodec aac -ab 96000 -ar 48000 -ac 2 -f rtsp -muxdelay 0.1 rtsp://username:password@127.0.0.1:1935/live/myStream
    1. jovan_novko -
      Can it transcode live stream on the fly???
    1. rrlanham -
      There are examples here:
      http://www.wowza.com/forums/content....rver-(MPEG-TS)

      Or VLC:
      http://www.wowza.com/forums/content....rver-(MPEG-TS)

      Or Wowza Transcoder (great option for multi-bitrate streaming and transcoding):
      http://www.wowza.com/forums/content....wza-Transcoder

      Richard
    1. robertookla -
      Hello,

      What is the command to stream without encoding? Also is it possible to stream from a folder or several files as a playlist? Thanks
    1. daren_j -
      You can use -vcodec copy -acodec copy

      Here's an example:

      ffmpeg -i c:\WowzaFiles\TestFiles\sample.mp4 -re -sameq -vcodec copy -acodec copy -f mpegts udp://127.0.0.1:10000?pkt_size=1316
    1. robertookla -
      I test with rtmp so here is my code

      ffmpeg -i "sample.mp4" -re -sameq -vcodec copy -acodec copy -f flv rtmp://IP.com/app/streamname
      However the ffmpeg is pushing this file to the wowza so fast. It only takes 5 seconds to finish this pushing. The flash player can only playback for a few seconds, then it jumps and jumps until the end of the movie. All of that happen within 5 seconds while this video is a 30 minute long video. Thanks
    1. randall -
      Try putting the -re before the -i.
    1. robertookla -
      yeah this is the one. It is playing awesome. Is it possible to broadcast a playlist (directory) (not encoding). Thanks
    1. robertookla -
      I figured out on how to play a playlist. Just need to use a bat file to loop the command. Thanks for helping
    1. rrlanham -
      You can do that with Wowza using the Stream class. Take a look at this scheduler for example:

      http://www.wowza.com/forums/content....t-in-smil-file

      Richard
    1. robertookla -
      I have a virtual camera on the desktop. Is there a way to get the input path for the virtual camera? This virtual camera (webcammax) videos
    1. rrlanham -
      I don't know. I'm not familiar with virtual camera. Do you have more details?

      Richard