问题描述
我打从VLC一个现场RTSP流在PC上到Android的MediaPlayer类(包括同一本地网络上)。它起着平滑,没有错误 - 的问题是,脱$ C $光盘视频屏幕上介于约5和后面活7秒。
I'm playing a Live RTSP stream from VLC on a PC to Android MediaPlayer class (both on same local network). It plays smoothly with no errors - the problem is that the decoded video on screen is between around 5 and 7 seconds behind live.
从调试和回调,我可以看到,实时数据到达的设备&lt上; 1秒启动后 mMediaPlayer。prepareAsync()
。这是在MediaPlayer类开始工作了什么格式的流是什么尺寸等,然后只需视频之前显示在屏幕上(5至7之间秒钟后),在prepared()
叫,我称之为 mMediaPlayer.start()
。它看起来像这样的start()
播放最初从prepare阶段开始捕获视频。
From debug and callbacks I can see that the live data is arriving on the device < 1s after starting mMediaPlayer.prepareAsync()
. This is when the MediaPlayer class begins to work out what format the stream is with what dimensions etc. Then just before video is shown on screen (between 5 and 7 seconds later), onPrepared()
is called where I call mMediaPlayer.start()
. It looks like this start()
plays the video that was originally captured from the start of the prepare stage.
我已经试过 seekTo(5000)
前后启动()
,但没有效果对滞后的。
I've tried seekTo(5000)
both before and after start()
, but it has no effect on the lag at all.
有关现场视频通话应用程序,几秒钟的设置延迟是完全没有问题的,但这种滞后一次视频是presented是unaccaptable我。
For a live video calling app, the setup delay of a few seconds is perfectly fine, but this lag once video is presented is unaccaptable to me.
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();
...
任何想法如何,我可以减少这种滞后,或寻求的是什么MediaPlayer的缓冲结束了吗?我的设备是3.1,是的minSdkVersion 2.2。
Any ideas how I can reduce this lag, or seek to the end of what is buffered by MediaPlayer? My device is 3.1, minSdkVersion is 2.2.
编辑:
我已经发现了一些高和低的水痕AwesomePlayer.cpp(2秒和8秒)。作为一个快速的测试,我已经破解了libstagefright.so使这些0.1秒和1秒。然而,这对取得的延迟没有影响。我继续搜索...
I've found some high and low water-marks in AwesomePlayer.cpp (2s and 8s). As a quick test I have hacked the libstagefright.so to make these 0.1s and 1s. This however made no effect on the delay. My search continues...
推荐答案
我不给一个最终的答案,但让我分享一下我现在。
I'm not giving a final answer, but let me share what I have by now.
- 在我有一个5秒的延迟问题,在本地PC上玩,从GStreamer的到的GStreamer。潜伏期不见了添加以下参数管道后:
- 在客户端 -
延迟= 0
rtspsrc
的参数; - 在服务器 -
v4l2src
的是生存当然= 1
参数,x264enc调= zerolatency
。
- I had a 5s latency issue playing locally on PC, from GStreamer to GStreamer. The latency was gone after adding the following parameters to pipelines:
- on client -
latency=0
parameter ofrtspsrc
; - on server -
v4l2src
'sis-live=1
parameter and, of course,x264enc tune=zerolatency
.
有没有办法控制
的MediaPlayer
/VideoView
的codeC /媒体源参数。无论是在媒体codeC API,据我看到的。There is no way to control
MediaPlayer
/VideoView
's codec/media source parameters. Neither in MediaCodec API, as far as I see.因此,我们需要去的GStreamer和ffmpeg的。
So we need to go for GStreamer or ffmpeg.
- NDK访问硬件加速codeCS的(寻找androidmedia),和人取得了一些成功利用它。
- NDK硬件加速codeC在FFMPEG访问于2011年实施,在FFMPEG 0.9
- NDK access to hardware-accelerated codecs was introduced in Android 4.2 (JellyBean) (look for "androidmedia"), and people had some success utilizing it.
- NDK hardware-accelerated codec access in FFMPEG was implemented in 2011, in FFMPEG 0.9
易用性和便携性都被发现了呢。
Ease of use and portability are to be found out yet.
这篇关于德$ C $ RTSP实时流的C:使用MediaPlayer的Android上大量的视频滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- on client -
- 在客户端 -