1

For performance reasons, I ditched Python-Opnecv/FFmpeg solution and moved on to Java.

But to my surprise, I am not able to find any better and complete solution as we have in Python. I tried using vlcj but again it just gives more of a command line kind of interface. I am not able to find any callback kind of mechanism for reading and analyzing all the frames.

I also tried using Java Sockets but wasn't able to do anything more than establishing a connection with Ip Camera streaming h264 video over RTSP.

Note: It will be running in a server environment so we don't want to show any frame, we just need run certain other operations on frames.

Please guide me in the right direction.

6
  • vlcj is not "more of a command-line interface" at all, I'm not even sure what that means in this context, and it does provide a callback to get each video frame. Commented May 21, 2019 at 17:37
  • Sorry @caprica it came out from my absolute lack of knowledge about vlcj. I will be more than happy to use it, if you can guide me to the right usage example or documentation for frame by frame access callback. Commented May 21, 2019 at 22:18
  • @caprica my comment came from this SO answer: stackoverflow.com/a/14584151 Commented May 21, 2019 at 22:23
  • and github.com/caprica/vlcj/issues/651#issuecomment-443669901 Commented May 21, 2019 at 22:25
  • There's two things here, first if you want to be able to navigate to a particular frame there is no direct API to do that. If you want to get a callback with video frame data while the stream is playing you can do that. So it depends exactly what you're trying to do if vlcj would be suitable or not. Commented May 22, 2019 at 5:16

1 Answer 1

2

If you want to get access to the video frame buffer while media is playing you have a couple of options.

I'l assume you are using vlcj 4.x+, which is current at time of writing.

First, you can use an EmbeddedMediaPlayer with a CallbackVideoSurface.

You can use the MediaPlayerFactory to create your video surface.

When you create your video surface, it requires a RenderCallback implementation that you provide.

Create the embedded media player as normal, and invoke mediaPlayer.setVideoSurface() to set your video surface.

It is this render callback implementation class that will be called back by VLC with raw video frame data in the form of a ByteBuffer backed by native memory. You can then do your analysis on the data in this byte buffer.

The second approach is to look instead at the CallbackMediaPlayerComponent class - this class aims to make it very easy for you to get an out-of-the-box working media player and provides a way for you to plug in only the bits you want to customise. In this case you plug in your render callback implementation to do your analysis.

There are examples in the vlcj source code at the github project page that show all of this. One of the examples processes this buffer to dynamically convert the video to greyscale, but obviously you can do anything you want with the frame data.

The method is named "onDisplay()" but you do not have to actually display the video anywhere if you're only interested in performing some analysis.

This is the extent of what vlcj can provide if you want to access the video frame data.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks caprica for detailed answer, but it will be running in a server environment so we don't want to show any frame, we just need run certain other operations on frames. DirectMediaPlayer seems the right choice for that, please tell me how to exactly use it.
I wasn't rude to you, I just said what is required, as in the all example I was videoSurface required to be mentioned, but now I managed to get around it, I am really thankful for your answer.
@RavinderPayal do you mind sharing your code? the excerpt on how you got around it
I am sorry @IgnatiusOjiambo, I have moved on from the project and employer a long time back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.