我正在使用以下代码在Android设备上显示实时RTSP流。 它可以正常工作,但问题是该视频比现实晚了2-4秒,而Xmeye应用程序晚了2秒。我在android studio日志中收到“图片为时已晚而无法显示” 的提示音,到目前为止,没有libvlc配置(在代码中注释)。 libvlc版本为2.5.4,在我的项目中作为模块实现。
是否有任何配置或替代解决方案可以克服此问题?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Window window = getWindow();
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// args.add("--ffmpeg-hw");
// args.add("--avcodec-fast");
// args.add("--avcodec-dr");
// args.add("--avcodec-skiploopfilter=4");
// args.add("--rtsp-frame-buffer-size=947483647");
// args.add("--rtsp-frame-buffer-size=13107200");
// args.add("--network-caching=2000"); // reduces the quality
// args.add("--live-caching==2000");
// args.add("--no-plugins-cache");// prevent from working
// args.add("--sout-rtp-caching=1000"); // prevent from working
mLibVLC = new LibVLC(this, args);
mMediaPlayer = new MediaPlayer(mLibVLC);
...
}
@Override
protected void onStart() {
super.onStart();
final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
if (mVideoSurface != null) {
vlcVout.setVideoView(mVideoSurface);
if (mSubtitlesSurface != null)
vlcVout.setSubtitlesView(mSubtitlesSurface);
} else
vlcVout.setVideoView(mVideoTexture);
vlcVout.attachViews(this);
startVideo();
}
private void startVideo() {
setMedia();
if (mOnLayoutChangeListener == null) {
mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
private final Runnable mRunnable = new Runnable() {
@Override
public void run() {
updateVideoSurfaces();
}
};
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
mHandler.removeCallbacks(mRunnable);
mHandler.post(mRunnable);
}
}
};
}
mVideoSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
}
private void setMedia() {
try {
final Media media = new Media(mLibVLC, Uri.parse(getRTSPURL()));
mMediaPlayer.setMedia(media);
media.release();
} catch (Exception e) {
throw new RuntimeException("Invalid asset folder");
}
mMediaPlayer.play();
大多数代码来自vlc android java-sample。 ref
更新
感谢mtz的评论,我将libvlc更新为3.0.0,并添加了这一行代码。
media.addOption(":codec=mediacodec_ndk,mediacodec_jni,none");
现在,“图片为时已晚,无法显示”错误仅在开头或使用sd品质的视频时发生过几次,此外,我还反复收到以下错误。
E/VLC-std: Sending request:
GET_PARAMETER
rtsp://192.168.1.12:554/user=admin_password=tlJwpbo6_channel=1_stream=0.sdp
RTSP/1.0
CSeq: 10
User-Agent: LibVLC/3.0.0-git (LIVE555 Streaming Media v2015.11.09)
Session: 3914750
E/VLC-std: Received 50 new bytes of response data.
Received a complete GET_PARAMETER response:
RTSP/1.0 200 OK
Server: H264DVR 1.0
Cseq: 10
并且当蓝牙设备连接到电话时,我大多会收到此错误,并且没有输出
core decoder: buffer deadlock prevented