Search code examples
androidvideo-streamingrtmprtpwowza

Streaming via RTP, RTMP playback quality issue


I am encoding H264 and sending to a Wowza server as a live stream from my Android device using RTP. The output of the encoder looks fine on the device. However, after streaming to the Wowza server and viewing the output video as a live stream over RTMP, I get a fair number of artifacts/pixelation in the video in the portion of the frame where there is significant movement/change. I can only guess this has something to do with the timing of the video frames but I don't have a good way to determine if this is on the send side of my app or on the Wowza side.

Wowza, if you have ever tried to get support from them, is completely useless.

I also have an issue of the RTMP/Flash player freezing when playing from Wowza. I am pretty sure this isn't a bandwidth issue as this happens on an Amazon EC2 server as well as my local PC instance (i.e. same network). I have tried multiple players and they all exhibit the same issue (VLC, JWPlayer, MX Player ,etc). I have to assume the problem is the Wowza server or my encoding. However, since there is a pixelation problem with some of the frames I am starting to wonder if the two are related.

I'm curious if anyone has had pixelation problems like this using Wowza or any other stream server. I tried to use RTMPDump but that didn't work, it would never pull complete packets from Wowza.


Solution

  • Encoding settings largely affect pixelation and artifacts. You should try for the lowest encoding setting possible, and then go up from there once you've confirmed playback quality. For example, test a 188p stream first (512x188, baseline, 256Kbps bitrate), and then go up to 288p, etc. It's also best practice to use a keyframe interval of 2 seconds for live streams; if your frame rate is 30fps, then your key frame frequency should be every 60 frames.

    A good tool to use to check your key frame interval is ffprobe:

    ffprobe -select_streams v:0 -show_frames -pretty rtmp://yourserver/app/name | grep 'key_frame\|coded_picture_number'
    

    Sometimes streaming packets come in bursts to the Wowza server, or the streaming packet flow is not as smooth. Enabling an RTP jitter buffer (where packets are collected and stored before being sent to the depacketizer at regularly spaced intervals) may help with a more even playback.

    To do this, edit the conf/[appName]/Application.xml file from your Wowza server (replacing the [appName] with the name of your live application), and add these properties in the RTP/Properties container (there's several, you would need to make sure to add these to the right container).

    <Property>
        <Name>rtpDePacketizerWrapper</Name>
        <Value>com.wowza.wms.rtp.depacketizer.RTPDePacketizerWrapperPacketSorter</Value>
    </Property>
    <Property>
        <Name>rtpDePacketizerPacketSorterBufferTime</Name>
        <Value>500</Value>
        <Type>Integer</Type>
    </Property>
    <Property>
        <Name>rtpDePacketizerPacketSorterFlushTime</Name>
        <Value>10</Value>
        <Type>Integer</Type>
    </Property>
    

    After you make your changes, make sure to restart your Wowza services.

    Check your Wowza access logs (logs/wowzastreamingengine_access.log) for any timeout or reset messages, as these would tell you if the software is detecting any issues in the incoming stream. A good practice is to tail this log file (baretail is a great tool for that on Windows), send your stream, and monitor the messages.

    You can also enable additional debug logging for your incoming RTP streams to check for packet loss. Following the same procedure for the RTP Jitter buffer, add these properties to the RTP/Properties container of your application's configuration file.

    <Property>
        <Name>rtpDePacketizerPacketSorterLogPacketLoss</Name>
        <Value>true</Value>
        <Type>Boolean</Type>
    </Property>
    <Property>
        <Name>logIncompleteMPEGTSVideoFrames</Name>
        <Value>true</Value>
        <Type>Boolean</Type>
    </Property>
    

    You can see the additional debug lines in the access logs.