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)
Related
I'm trying to get last frame of mp4 video using MediaMetadataRetriever but it always return first Frame for short videos (like 3s long videos), it work fine for long videos. FFmpegMediaMetadataRetriever also give same result.
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(video);
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
Bitmap frameAtTime = retriever.getFrameAtTime(Long.parseLong(time)*1000, MediaMetadataRetriever.OPTION_CLOSEST);
mImage.setImageBitmap(frameAtTime);
Any suggestions would be appreciated.
I want to create a GIF from mp4 video. So I need to extract the frames from video first. Here is the code I use to extract frames:
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(mFilePath);
Bitmap bitmap = retriever.getFrameAtTime(i,
MediaMetadataRetriever.OPTION_CLOSEST);
Note that variable i is time in microseconds. Since I want to get 24 frames/second, I call retriever.getFrameAtTime() with i = 42000, 84000, .... (microseconds).
The problem is: when I collect extracted frames to a video, I see only 4-5 different frames. In other words, I didn't get a smooth video. It seems that MediaMetadataRetriever often returns the same frame with different given time. Please help me!
I have successfuly get thumbnail for video with code like this:
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(mediaFile.getAbsolutePath(),
MediaStore.Video.Thumbnails.MINI_KIND);
But this code can only get bitmap for few videos because android can not decode most part of videos for android video decoder is weak.
if I just want to get a thumbnail for video, do I have any good solution. If I do not need to use ndk is much better! But if ndk solution is much more efficient or easy, I think it also OK.
You can use-
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(filePath);
//here 5 means frame at the 5th sec.
bitmap = retriever.getFrameAtTime(5);
} catch (Exception ex) {
// Assume this is a corrupt video file
}
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. :)
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!!