Extract a frame image from video in scala

Sometimes it becomes a general requirement to show the preview of a video wherever video gets displayed. Like on YouTube , If you’ll right click on almost any video , you’d find that each video contains a preview image of a frame of that video.

Here is a short tutorial for doing the same i.e extracting a frame image from a video in Scala via using Xuggle.

Add the following dependency in your project to get the xuggler jar.

Following is the resolver for the jar

Lets us start the process step by step :

1. Instantiate the reader from “xuggle.mediatool.ToolFactory” and specify “from where to read the video”.

2. Set the limit in which mediaReader has to read the video files.

3. Set the type of Buffere Image you want to extract.

4. Now we have to add a media listner for the “mediaReader” reader so lets implement the listner.

what we did here is :-

i) – Overridden the onVideoPicture method and increased the counter by one in order
to deny the mediaReader to read more files.
ii)- Written a method dumpImageToFile that makes the frame image to be written on specified location using javax.imageio.ImageIO.

Here is the complete code file that you can run directly. Just specify the path in
– mediaReader of “From where to read ?”
-ImageIO of “Where to write the extracted frame image?”

2 thoughts on “Extract a frame image from video in scala

Leave a Reply

%d bloggers like this: