Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:46:43+00:00 2026-06-13T23:46:43+00:00

Im trying to create only one thumbnail from random location from *flv video. the

  • 0

I”m trying to create only one thumbnail from random location from *flv video.
the code example that I found around the net wasn’t really helpful. If anyone knows how to do it
or has a code or method that would do, please share/explain. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:46:44+00:00Added an answer on June 13, 2026 at 11:46 pm

    I have gone through the sample code that is available over here (http://www.javacodegeeks.com/2011/02/xuggler-tutorial-frames-capture-video.html) that creates thumbnails out of a given input video file. In order to create only one, you can introduce a class level member variable (in the sample code the variable name is imageGrabbed). This variable just keeps track of thumbnail generation, once the very first thumbnail is created then in the calling function (in the sample code the calling function is main()) the while loop exits.

    Hope this helps.

    Regards,
    Ismail.

    /**
     * VideoThumbnailsExample.java Oct 29, 2012
     */
    package com.test;
    
    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;
    
    /**
     * <pre>
     * Java File.
     * Title        : VideoThumbnailsExample.java
     * Description  : <Description>
     * </pre>
     */
    public class VideoThumbnailsExample
    {
        public static final double SECONDS_BETWEEN_FRAMES = 1;
    
        private static final String inputFilename = "/Users/ismail/practice/vlc/sample.3gp";
        private static final String outputFilePrefix = "/Users/ismail/practice/vlc/";
    
        // The video stream index, used to ensure we display frames from one and
        // only one video stream from the media container.
        private static int mVideoStreamIndex = -1;
    
        // Time of last frame write
        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)
        {
            long startTime = System.currentTimeMillis();
            long stopTime = 0L;
    
            IMediaReader mediaReader = ToolFactory.makeReader(inputFilename);
    
            // stipulate that we want BufferedImages created in BGR 24bit color
            // space
    
            try
            {
                mediaReader
                .setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
    
                ImageSnapListener isListener = new ImageSnapListener();
    
                mediaReader.addListener(isListener);
    
                // read out the contents of the media file and
                // dispatch events to the attached listener
    
                while (!isListener.isImageGrabbed())
                {
                    mediaReader.readPacket();
                }
                /*
                while (mediaReader.readPacket() == null)
                    ;
                */
                //mediaReader.readPacket();
                stopTime = System.currentTimeMillis();
    
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
    
    
    
            System.out.println("Total Time: " + (stopTime-startTime));
    
    
        }
    
        private static class ImageSnapListener extends MediaListenerAdapter
        {
            public boolean imageGrabbed = false;
    
    
            public void onVideoPicture(IVideoPictureEvent event)
            {
    
                if (event.getStreamIndex() != mVideoStreamIndex)
                {
    
                    // if the selected video stream id is not yet set, go ahead an
                    // select this lucky video stream
    
                    if (mVideoStreamIndex == -1)
                        mVideoStreamIndex = event.getStreamIndex();
    
                    // no need to show frames from this video stream
                    else
                        return;
    
                }
    
                // if uninitialized, back date mLastPtsWrite to get the very first
                // frame
    
                if (mLastPtsWrite == Global.NO_PTS)
    
                    mLastPtsWrite = event.getTimeStamp()
                            - MICRO_SECONDS_BETWEEN_FRAMES;
    
                // if it's time to write the next frame
    
                if (event.getTimeStamp() - mLastPtsWrite >= MICRO_SECONDS_BETWEEN_FRAMES)
                {
    
                    String outputFilename = dumpImageToFile(event.getImage());
    
                    this.imageGrabbed = true; //set this var to true once an image is grabbed out of the movie.
    
                    // indicate file written
                    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);
                    //System.out.printf("at elapsed time of %6.3f seconds wrote: SOMEFILE\n",seconds);
    
                    // update last write time
                    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;
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a program where that only one user can be
I am trying to create a JFormattedTextField that only accepts a 24-hour time. I
I'm trying to create a view that only houses reusable HTML blocks that can
I'm trying to create an HBox in flex that has only the top corners
I'm trying to create a jboss-cache for data that is only relevant for a
I am trying to create a simple Javascript text editor that only makes paragraph
I'm trying to create a very simple login for only one or two users,
I'm trying to create a drop down menu, where only ONE drop down is
I'm trying to create a set of thumbnails, each one separately downscaled from the
I am learning regular expressions and I am trying to create one that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.