如何从Android上的VLC MediaPlayer Rivestream中获取单独的帧而不显示流?
我目前正在研究一个项目,该项目要求我使用RTSP通过WiFi将视频从IP摄像机流到Android设备,然后进行一些图像处理。我想在不显示视频流的情况下执行此操作。目前,我正在尝试使用Android的VLC进行此操作。我的代码结构如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> options = new ArrayList<>();
// Various options added.
mLibVLC = new LibVLC(getApplicationContext(), options);
mMediaPlayer = new MediaPlayer(mLibVLC);
videoLayout = findViewById(R.id.videoLayout); // This view is marked as INVISIBLE.
}
@Override
protected void onStart() {
super.onStart();
mMediaPlayer.attachViews(videoLayout, null, false, false);
Media media = new Media(mLibVLC, Uri.parse("<RTSP LINK>"));
// Set VLC media presets.
mMediaPlayer.setMedia(media);
media.release();
mMediaPlayer.play(); // Play the stream!
// Set callback to get each frame from MediaPlayer?
}
当videolayout
标记为“可见”时,这是完美的。我还可以通过执行屏幕截图从视图中获取位图。当我将视频布局
标记为“不可见”时,据我所知,我仍在收到帧(至少根据VLC的调试输出),但我不确定如何访问它们。我有没有办法将MediaPlayer流直接渲染到位图?还是我可以使用其他一些方法来获取每个新框架而不呈现视图?感谢您的帮助!
I am currently working on a project that requires me to stream video from an IP camera to an Android device via WiFi using RTSP and then do some image processing. I want to do this without displaying the video stream if possible. Currently, I am trying to do this using VLC for Android. My code is structured as follows:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> options = new ArrayList<>();
// Various options added.
mLibVLC = new LibVLC(getApplicationContext(), options);
mMediaPlayer = new MediaPlayer(mLibVLC);
videoLayout = findViewById(R.id.videoLayout); // This view is marked as INVISIBLE.
}
@Override
protected void onStart() {
super.onStart();
mMediaPlayer.attachViews(videoLayout, null, false, false);
Media media = new Media(mLibVLC, Uri.parse("<RTSP LINK>"));
// Set VLC media presets.
mMediaPlayer.setMedia(media);
media.release();
mMediaPlayer.play(); // Play the stream!
// Set callback to get each frame from MediaPlayer?
}
When videoLayout
is marked as "visible", this works perfectly. I am also able to get Bitmaps from the view by performing a screen capture. When I mark the video layout
as "invisible", far as I can tell I am still receiving frames (at least according to VLC's debug output) but I'm not sure how I can access them. Is there a way for me to directly render the MediaPlayer stream to a Bitmap? Or is there some other method I could use to get each new frame without rendering the view? Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过大量反复试验,我发现了这一点。最适合我的解决方案是使用JavACV使用
ffmpegframegrabber
。现在,我可以从RTSP流逐帧读取框架。I figured this out after a lot of trial and error. The solution that worked best for me was to use
FFMPEGFrameGrabber
from JavaCV. I'm now able to read frame by frame from an RTSP stream.