[FREE] [BETA] Extract image frame from video

Introduction


Hi! This is a simple extension to extract a frame from a video. Hope you like it :slight_smile: This extension is still under development so there might be a bunch of bugs :sweat_smile:
(more detailed documentation will be made)

This extension is suggested by @eps_prieur:

Basically, it generates an image and temporarily stored in the external storage. It will be deleted once the application is stopped (OnDestroy)

Documentation


Block Description
Error Raises when any errors occurred
GotImage Raises when an image is extracted by the async method
ImageCreated Raises when images are deleted by the method DeletAllCreatedImagesAsync.
GetImageViaPath Get an image of a video with a given time. Use -1 if you don't need an option.
video that can be accepted: Absolute path, File URL path, Uri path and URL (direct media link).
If you are using png, you can ignore the quality. Else if you use JPEG, you have to define one. Possible range: 0-100 (lowest to highest)
Return an external path, or "Error" if any error occurred.
GetImageViaPathAsync Does the same as GetImageViaPath but run in an async way.
CreatedImages Return a list of ALL created Images (except the deleted one).
DeleteAllCreatedImages Delete All Created Images. After deletion, the file won't show up in the CreatedImages list. Files which deletion is failed will stay in the list.
DeletAllCreatedImagesAsync Does the same as GetImageViaPath but run in an async way.
DeleteAllOnDestroy True if you want to delete all on destroy, otherwise false.
SavePath Defining the absolute path to store the created image. (default is the primary shared/external storage directory)
SaveType Define the type of the image. Acceptable inputs are: png, jpeg (not case-sensitive)
Closest, ClosestSync, NextSync, PreviousSync The constant of options

For options, here is detailed documentation:

Documentation

a hint on how the frame is found. Use OPTION_PREVIOUS_SYNC if one wants to retrieve a sync frame that has a timestamp earlier than or the same as timeUs. Use OPTION_NEXT_SYNC if one wants to retrieve a sync frame that has a timestamp later than or the same as timeUs. Use OPTION_CLOSEST_SYNC if one wants to retrieve a sync frame that has a timestamp closest to or the same as timeUs. Use OPTION_CLOSEST if one wants to retrieve a frame that may or may not be a sync frame but is closest to or the same as timeUs. OPTION_CLOSEST often has larger performance overhead compared to the other options if there is no sync frame located at timeUs. Value is either 0 or a combination of OPTION_PREVIOUS_SYNC , OPTION_NEXT_SYNC , OPTION_CLOSEST_SYNC , and OPTION_CLOSEST

Reference: MediaMetadataRetriever | Android Developers

Change Log


Beta 1.2
  • You can now customize the type (png/jpeg)
    Note: Quality of image is added. If you use png, you can ignore it.
Beta 1.1
  • Added path customization
  • You can choose not to delete the images created
  • You can get a list of created images

Download


List of versions

Beta 1.2 (23.1 KB)
Beta 1.1 (22.1 KB)
Beta 1.0 (18.4 KB)

Reminder


  • android.permission.WRITE_EXTERNAL_STORAGE is required.
  • Online video might not work Thanks to @vknow360 for proving it working.
  • Time of video might not be exact.
  • Deletion might not work perfectly

Known Issues


  • App will crash if the SavePath is invalid.

Big thanks to


Demo project

This AIA project works in Kodular only for the component
ExtractImageFromVideo.aia (58.7 KB)
Thanks to @vknow360 for his FileTools extension (used in project).

6 Likes

MediaMetadataRetriever works with local video as well as online video.
VideoUtil extension also uses it and as you know it works with online videos.

Thanks for reminding, I have tested it recently and it seems working!

Out of interest - what file format does it output?

PNG. I chose this format because it has a lossless option.

2 Likes

is there any way I could change it to output a jpg file? It's just more convenient for my app to handle it images in a jpg format

1 Like

I will make an update for that, stay tuned!

1 Like

Updated!

this work with app inventor too or only kodular?

It has been presented here in the App Inventor community, so theoretically yes
Please try it yourself and let us know how it works

Taifun

I hadn't noticed this extension until now. Can someone answer the following question for me:

What's the point of doing this within an app? Which of these 30 or 60 frames per second are we going to access and why?

i am thinking to use this for facemesh extension to get a smooth capture canvas when i need to use for my face because its really slow following points inside canvas background image. when i try to proof maybe can share this.

Hmm...

Ran a quick test using companion on Android 12 Genymotion Emulator. Didn't seem to scan my webm video very well, so after asking for an image every second (of a 26 second video clip) I appeared to get many repeats from the first 5-10 seconds. Perhaps needs a delay between grabs, or will work better with mp4 / avi ?

i dont know if its correct but i am trying first to record the video and next using a clock to capture every image using video to image

someone can help me?

Try something like this:

Set your save location to a default shared storage directory, such as Download.

Test with an mp4 video. Doesn't seem to like webm.

Use the "Closest" option

Using the clock helps you to watch the progress of images saved.

what is the function of closest option?

Read the documentation !

inside the clock the filepath:// i would add the exactly route of my file mp4?

I did