How to get video thumbnail as GIF from video URL? - android

I want to show video thumbnail as GIF from video URL like TikTok - including musical.ly app.
See below video for getting more details
I have used this to get first 10-15 video frames to generate GIF. but it's not working.
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever .setDataSource(url, new HashMap<String, String>());
Bitmap bmFrame = mediaMetadataRetriever.getFrameAtTime(1000); //unit in microsecond
capturedImageView.setImageBitmap(bmFrame);

Related

MP4 Video Last frame

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.

How to extract 24 different frames per second from video?

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!

How can I get a video thumbnail in android if android can not decoding the video?

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
}

How to create a thumbnail of video using Aquery

i am working on listview showing list of video.i am getting url of video from web server.Now i want to create a thumbnail of video using aQuery.i am using this code:
Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail("http://"
+ videoList.get(1), Thumbnails.MICRO_KIND);
it is working, but is taking some time while scrolling.

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