Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to get a video thumbnail of a file that's private to your application?

Question:

How do you get a video thumbnail for an application-private file? Specifically, is there a way to extract video frames from an .mpeg file directly?

Background:

  1. My application includes a camera that can record video.
  2. For product reasons, the video file is initially created and written in private mode in the application's private data directory, making it private to the application. This is done using: Context#openFileOutput(fileName, Context.MODE_PRIVATE) - a typical file path looks like this: /data/data/[package.name]/files/[fileName].mp4 -- FYI I already tried using Context.MODE_WORLD_READABLE instead of Context.MODE_PRIVATE but it didn't help.
  3. Even though the video may eventually end up in external storage (by moving the file to Environment#getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)), the thumbnail must be displayed while the video is in application-private storage.
  4. It seems like ThumbnailUtils.createVideoThumbnail(String, int) works fine for the file after it is moved to the public directory (regardless of adding it to the MediaStore), but silently fails (returns null) when the file is in internal storage.

    • Note: as long as the video file is in application-private storage, it is not added to the MediaStore (the image/video content provider on the device Gallery feeds on). Only once the video is moved to external storage do I add it the MediaStore. This is a product-related decision which I cannot circumnavigate; unless there's a way to add the video the media store without it being visible to other apps... I wonder if videos in application-private storage can be added to the media store and would remain application-private but gain all the free "services" provided by the media store such as thumbnail generation.
like image 541
Warlax Avatar asked Dec 21 '11 20:12

Warlax


People also ask

Is it possible to generate a thumbnail from a video URL in Android?

In android, we can use the MediaMetadataRetriever to retrieve a thumbnail image of an online video from its url. MediaMetadataRetriever can be used to retrieve frame and metadata from an input media file. Note that the above code takes some time to get the image.

How do I get the thumbnail from a video?

You can take a screenshot from your video that best explains its contents, or you can use a tool like Photoshop or Canva to overlay text or icons on the image. To make a screen capture on a PC, use the Windows Snipping Tool. For Mac users, hit Command+Shift+4 to select the part of your screen you want to capture.

How do I get the thumbnail from a video URI?

This works for me: Bitmap thumb = ThumbnailUtils. createVideoThumbnail(filePath, Thumbnails. MINI_KIND);


1 Answers

Of course, you can't use MediaStore stuff for private media. I would use a image process library if it is possible at all. I know OpenCV can do that easily by extracting/resizing a frame. - please look at middle section of page 2.

like image 80
Tae-Sung Shin Avatar answered Sep 18 '22 18:09

Tae-Sung Shin