Paste videos thumbnail (Windows)

5

I searched Google for various terms on how to get the thumbnail of the videos but only found how to "generate" the thumbnail of a frame from the video using Xuggler but I'm having errors.

The error I'm having is:

Belowismyclass:

packageutil;importjava.awt.image.BufferedImage;importjava.io.File;importjava.io.IOException;importjava.util.List;importjavax.imageio.ImageIO;importcom.xuggle.mediatool.IMediaReader;importcom.xuggle.mediatool.MediaListenerAdapter;importcom.xuggle.mediatool.ToolFactory;importcom.xuggle.mediatool.event.IVideoPictureEvent;importcom.xuggle.xuggler.Global;importmodel.Video;publicclassBuildThumbnailUtil{publicstaticfinaldoubleSECONDS_BETWEEN_FRAMES=1;privatestaticfinalStringoutputFilePrefix="C:/Documents and Settings/Panda/Desktop/MovieList/";
    private static int mVideoStreamIndex = -1;
    private static long mLastPtsWrite = Global.NO_PTS;
    public static final long MICRO_SECONDS_BETWEEN_FRAMES = (long) (Global.DEFAULT_PTS_PER_SECOND * SECONDS_BETWEEN_FRAMES);

    public static void buildThumbnail(List<Video> videos) {
        for (Video v : videos) {
            IMediaReader mediaReader = ToolFactory.makeReader(v.getPath());
            try {
                mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
                ImageSnapListener isListener = new ImageSnapListener();
                mediaReader.addListener(isListener);

                while (!isListener.isImageGrabbed()) {
                    mediaReader.readPacket();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    private static class ImageSnapListener extends MediaListenerAdapter {

        public boolean imageGrabbed = false;

        public void onVideoPicture(IVideoPictureEvent event) {
            if (event.getStreamIndex() != mVideoStreamIndex) {
                if (mVideoStreamIndex == -1)
                    mVideoStreamIndex = event.getStreamIndex();
                else
                    return;
            }
            if (mLastPtsWrite == Global.NO_PTS)
                mLastPtsWrite = event.getTimeStamp() - MICRO_SECONDS_BETWEEN_FRAMES;
            if (event.getTimeStamp() - mLastPtsWrite >= MICRO_SECONDS_BETWEEN_FRAMES * 10) {
                String outputFilename = dumpImageToFile(event.getImage());
                this.imageGrabbed = true;
                double seconds = ((double) event.getTimeStamp()) / Global.DEFAULT_PTS_PER_SECOND;
                System.out.printf("at elapsed time of %6.3f seconds wrote: %s\n", seconds, outputFilename);
                mLastPtsWrite += MICRO_SECONDS_BETWEEN_FRAMES;
            }
        }

        private String dumpImageToFile(BufferedImage image) {
            try {
                String outputFilename = outputFilePrefix + System.currentTimeMillis() + ".jpg";
                System.out.println("Thumbnail image name is going to be : =====>" + outputFilename);
                ImageIO.write(image, "jpg", new File(outputFilename));
                return outputFilename;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        public boolean isImageGrabbed() {
            return imageGrabbed;
        }
    }
}

Does anyone know if they have a way to get the same thumbnail of a video just as Windows displays?

    
asked by anonymous 29.10.2015 / 19:09

2 answers

1

As I answered in your other topic, follow another class that also works perfectly here!

package xug;


import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.MediaListenerAdapter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.mediatool.event.IVideoPictureEvent;
import com.xuggle.xuggler.Global;

public class Main {

    public static final double SECONDS_BETWEEN_FRAMES = 10;
    private static final String inputFilename = "D:\pasta de videos\Live for free.flv";
    private static final String outputFilePrefix = "D:\imaagens\";

    private static int mVideoStreamIndex = -1;
    private static long mLastPtsWrite = Global.NO_PTS;
    public static final long MICRO_SECONDS_BETWEEN_FRAMES =
            (long) (Global.DEFAULT_PTS_PER_SECOND * SECONDS_BETWEEN_FRAMES);

    public static void main(String[] args) {

        IMediaReader mediaReader = ToolFactory.makeReader(inputFilename);
        mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
        mediaReader.addListener(new ImageSnapListener());
        while (mediaReader.readPacket() == null);

    }

    private static class ImageSnapListener extends MediaListenerAdapter {
         public void onVideoPicture(IVideoPictureEvent event) {

            if (event.getStreamIndex() != mVideoStreamIndex) {

                if (mVideoStreamIndex == -1) {
                    mVideoStreamIndex = event.getStreamIndex();
                }
                else {
                    return;
                }
            }


            if (mLastPtsWrite == Global.NO_PTS) {
                mLastPtsWrite = event.getTimeStamp() - MICRO_SECONDS_BETWEEN_FRAMES;
            }

            if (event.getTimeStamp() - mLastPtsWrite
                    >= MICRO_SECONDS_BETWEEN_FRAMES) {

                String outputFilename = dumpImageToFile(event.getImage());

                double seconds = ((double) event.getTimeStamp())
                        / Global.DEFAULT_PTS_PER_SECOND;

                System.out.printf(
                        "at elapsed time of %6.3f seconds wrote: %s\n",
                        seconds, outputFilename);

                mLastPtsWrite += MICRO_SECONDS_BETWEEN_FRAMES;

            }
        }

        private String dumpImageToFile(BufferedImage image) {

            try {

                String outputFilename = outputFilePrefix
                        + System.currentTimeMillis() + ".png";

                ImageIO.write(image, "png", new File(outputFilename));

                return outputFilename;

            } catch (IOException e) {

                e.printStackTrace();

                return null;

            }
        }
    }
}

It's very similar to this one, the funniest thing is that getting your class started to have this error of yours ... I'll clean it and see if I find the biggest difference!

    
08.11.2015 / 03:01
0

There seem to be some examples out there that are much better than what I was going to send you.

See link .

If you can find a way to get what you want to use some command line tools (and run them using Commons-Exec), you can have a better overall solution than depending on what is essentially the Sanskrit extensions Java.

Source: link

    
05.11.2015 / 17:16