Decoding an RTSP Streaming Stream: Large Video Delay Using MediaPlayer on Android

I play a Live RTSP stream from VLC on a PC to the Android MediaPlayer class (as on the same local network). It plays smoothly without errors - the problem is that the decoded video on the screen is between 5 and 7 seconds behind the live one.

From debugging and callbacks, I see that the current data arrives at the device <1 s after running mMediaPlayer.prepareAsync() . This is when the MediaPlayer class begins to determine in what format a stream with such dimensions is located, etc. Then, before the video is displayed on the screen (between 5 and 7 seconds later), onPrepared() is onPrepared() , where I call mMediaPlayer.start() . It appears that this start() plays the video that was originally recorded from the beginning of the preparation phase.

I tried seekTo(5000) both before and after start() , but it does not affect the delay at all.

For a real-time video call application, the setup delay for a few seconds is fine, but I did not succeed in lagging after the video was presented.

 public void surfaceCreated(SurfaceHolder holder) { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setOnInfoListener(this); mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnVideoSizeChangedListener(this); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setDataSource("rtsp://192.168.1.4:5544/test"); mMediaPlayer.setDisplay(holder); mMediaPlayer.setScreenOnWhilePlaying(true); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.prepareAsync(); ... public void onPrepared(MediaPlayer mediaplayer) { mMediaPlayer.start(); ... 

Any ideas on how I can reduce this lag, or look for the end of what MediaPlayer is buffering? My device is 3.1, minSdkVersion is 2.2.

EDIT:

In AwesomePlayer.cpp (2s and 8s) I found some high and low watermarks. As a quick test, I hacked libstagefright.so to do these 0.1s and 1s. However, this did not affect the delay. My search continues ...

+7
source share
3 answers

I do not give a definitive answer, but let me share what I have.

  • I had a problem with a 5 s delay playing locally on a PC, from GStreamer to GStreamer. The delay disappeared after adding the following parameters to the pipeline:
    • on the client - latency=0 rtspsrc parameter;
    • on the server - v4l2src is-live=1 and, of course, x264enc tune=zerolatency .

Cannot control MediaPlayer / VideoView codec / media source settings. As far as I understand, not in the MediaCodec API.

So, we need to switch to GStreamer or ffmpeg.

Ease of use and portability are sufficient.

+1
source

I have the same problem. One way to do this is to rewrite the entire playback class to control what is served in the codec. But that would be the last (and painful) resort. I'm still looking back ... sigh ...

0
source

I have exactly the same problem. At first I thought that it did not work, but I forgot that the application is open, and after a while a video appeared.

The funny thing is that if I use this video [1], which I found in the VideoView tutorial, the lag is much less. I am thinking of setting up a Darwin Streaming server to check if this is a VLC issue or other issue.

[1] rtsp: //v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3g

0
source

All Articles