How to get individual frames from a VLC MediaPlayer livestream on Android WITHOUT displaying the stream?

766 views Asked by At

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!

1

There are 1 answers

0
Mihir Bala On BEST ANSWER

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.