如何从Android上的VLC MediaPlayer Rivestream中获取单独的帧而不显示流?

发布于 2025-02-06 02:02:06 字数 1175 浏览 2 评论 0原文

我目前正在研究一个项目,该项目要求我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街道布景 2025-02-13 02:02:06

经过大量反复试验,我发现了这一点。最适合我的解决方案是使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文