MediaMetadataRetriever getFrameAtTime: videoframe is a null pointer - android

I´m trying to get a frame of a video, so I´m using MediaMetadataRetriever.getFrameAtTime() like this:
Uri directorio = Uri.parse("android.resource://com.extremeye/" + R.raw.video);
media = new MediaMetadataRetriever();
media.setDataSource(this, directorio);
frame = (ImageView)findViewById(R.id.frame);
Bitmap bmFrame = media.getFrameAtTime();
frame.setImageBitmap(bmFrame);
But the problem is that I get:
MediaMetadataRetriever getFrameAtTime: videoframe is a null pointer
in the logCat.
I´m sure that the video is compatible with android OS and the MediaMetadataRetriever loads it because I can get its metadata description without problems in a 2.3.3 OS version.
I don´t know why I can´t get the frame but if I use a 4.2 OS version, it works perfectly. I tried to change the codec and the format of the video but it doesn´t work... I suppose that it´s a problem of format compatibility but I don´t know what I can do...
Thanks!!

Actually I´m using FFmpegMediaMetadataRetriever class from this external library and works great!!

Related

Conversion of .Raw10 (images / Videos) to RGB in Android studio

There are a few problems I am listing here..
I am using a Omnivision image sensor to get the raw video and images. I have to convert the raw image to bitmap or the video format to MJPEG..
I tried got data using Uri, then to inputstream then to a byte [], a N x 1. where I got about a million values. I am not sure whether this is the right way to get the image. Then I tried to decode using imcodes. I used to bitwise shift and added the values, but it took a lot of time and the app crashed. Instead of it, I reshaped into m x n and tried to display on a bitmap to view it as a null. I tried the dimoraic which I could not proceed. I tried decoding it as bitmap too, and the app crashed too.
Is there any way I could directly stream it in Android studio. I need to convert this raw video format into MJPEG format. I tried to stream it in python just like a webcam, which gave an error can't grab frame and something to do with MSMF

Android: Get frame from network video resource

I want to get a pointed frame from network video by MediaMetadataRetriever. But when I called MediaMetadataRetriever.setDataSource(myUrl), app will crash becauseof IllegalArgumentException. Is there anyone has this problem and could you tell me how to deal with it? Thanks a lot!
MediaMetadataRetriever rev = new MediaMetadataRetriever();
rev.setDataSource(myUrl); //will crash at here
Bitmap bitmap = rev.getFrameAtTime(mVideoView.getCurrentPosition() * 1000,
MediaMetadataRetriever.OPTION_CLOSEST_SYNC)

Got wrong data by ImageReader when reading from a video?

I am writing an app to grab every frame from a video,so that I can do some cv processing.
According to Android `s API doc`s description,I should set Mediaplayer`s surface as ImageReader.getSurface(). so that I can get every video frame on the callback OnImageAvailableListener .And it really work on some device and some video.
However ,on my Nexus5(API24-25).I got almost green pixel when ImageAvailable.
I have checked the byte[] in image`s Yuv planes,and i discover that the bytes I read from video must some thing wrong!Most of the bytes are Y = 0,UV = 0,which leed to a strange imager full of green pixel.
I have make sure the Video is YUV420sp.Could anyone help me?Or recommend another way for me to grab frame ?(I have try javacv but the grabber is too slow)
I fix my question!!
when useing Image ,we should use getCropRect to get the valid area of the Image.
forexample ,i get image.width==1088 when I decode a 1920*1080 frame,I should use image.getCropImage() to get the right size of the image which will be 1920,1080

Saved video as input instead of Camera in android

I've implemented an android app that implements the CvCameraListener interface. In the onCameraFrame(Mat inputFrame) method I process the captured inputFrame from the camera.
Now to my problem: Is there a way that I can use a saved video file on my phone as an input instead of getting the frames directly from camera? That means I would like to have a video file input frame by frame in Mat format.
Is there a possible way to do that?
Thanks for your answers
though it is not tested and I don't have much experience in OpenCV on Android. Still, you can try like this:
//[FD : File descriptor or path.]
Bitmap myBitmapFrame;
MediaMetadataRetriever video_retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(FD);
myBitmapFrame = retriever.getFrameAtTime(..);
}
catch(...
:
Utils.bitmapToMat(myBitmapFrame, myCVMat);
You may have to implement some callback system as you can work with only OpenCV after it is initialized. Also, you can convert frame number to time-code.
Good Luck and Happy Coding. :)

How to get stream video(m3u8 format) resolution from url link, android2.3.3?

I have tried many ways to retrieve the video meta data from url like (http://xxx.xxx.xxx.xxx/streams/xxxx/playlist.m3u8), the project is useing android 2.3.3 SDK.
As I know the MediaMetadataRetriver can solve it with capture_mode but it needs the android vesion level after 14, but android 2.3.3 is level 10. (it doesnt work in project).
MediaMetadataRetriever retr = new MediaMetadataRetriever();
retr.setDataSource(mContext , video.getUriWithDrmCheck());
retr.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY);
Bitmap bm = retr.captureFrame();
int wVideo = bm.getWidth();
int hVideo = bm.getHeight();
I have been used vetamio to retrieve the video resolution, but the system crashed.
io.vov.vitamio.MediaPlayer m= new io.vov.vitamio.MediaPlayer(this);
m.prepareAsyc();
m.setDataSource(url);
m.getVideoAspectRatio();
m.release();
The default android.media.mediaplayer in android could not retrieve the url video information.
The video height I got from it is 0.
I tried thumbnail method to retrieve the video information, but the Thumbnail method seems can only phase the localPath, not the url link path.
Bitmap bMap = ThumbnailUtils.createVideoThumbnail(url, MediaStore.Video.Thumbnails.MICRO_KIND);
So does any one know how to retrieve a stream video (m3u8 format) resolution from url link in android?? thank you very much.

Categories

Resources