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 8677831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:33:51+00:00 2026-06-12T20:33:51+00:00

I am trying to develop a video sharing website where user can upload a

  • 0

I am trying to develop a video sharing website where user can upload a video and as soon as the video is uploaded , a thumbnail image is created for that video . This is done with Xuggler. This works fine , but when i do it second time, or next times , it do not generate the images . Any idea why ? The videos are getting uploaded next times but the images are not generated for them. When the Web application is run for the first time , and the user uploads a video , only that time the image is generated. Therefore in order to generate the images for every upload I am having to restart my server(Tomcat). What is the cure for this ??? I am listing my code below, i hope I will be guided with good response.

this code is from index.jsp , the first page of my Web Application , the user will upload a video from this page :

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <script type="text/javascript">
        function validate(){
            document.getElementById("mybutton").style.visibility="visible";
            document.getElementById("file_browse").style.visibility="hidden";

        }
    </script>
    <title>ADMIN PAGE</title>
    <style type="text/css">
        #Text1
        {
            width: 303px;
            height: 28px;
            margin-top: 0px;
        }
        #Button1
        {
            width: 84px;
            margin-bottom: 4px;
            height: 27px;
        }
        #Button2
        {
            width: 100px;
            height: 35px;
        }
        #Button3
        {
            width: 100px;
            height: 35px;
        }
        .style1
        {
            font-size: xx-large;
        }
        .style2
        {
            color: #CC0000;
            word-spacing: inherit;
        }
        #Button4
        {
            width: 113px;
            height: 32px;
        }
        #Button5
        {
            width: 114px;
            height: 32px;
        }
        .newStyle1
        {
            font-style: oblique;
        }
        .style3
        {
            font-style: oblique;
            color: #FF0000;
            font-size: xx-large;
        }
    </style>
   </head>
   <body bgcolor="#E7EEE7">
    <form id="form1" runat="server">

        <div style="border-style: groove; border-width: thin;height: 77px; width:    
   999px; margin-right: 1px; margin-top: 0px">

            &nbsp;&nbsp;<span class="style1"></span> <span   
   class="style3">YouTUBE</span></span><span
                class="style2">&nbsp;  
   </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input id="Text1" type="text" /><input id="Button1" type="button"
                                                   value="Search"/>

               <input id="Button2" type="button" value="Admin"/>
            <input id="Button3" type="button" value="Logout" /></div>
    </form>
    <div style="border-style: groove; border-width: thin;width: 155px; height: 906px;    
    margin-top:0px;">
    </div>
    <div style="border-style: groove; border-width: thin;height: 908px; width: 250px;   
    margin-left: 750px; margin-top: -907px; margin-bottom: 0px; margin-right: 0px;">
    </div>
    <div style="border-style: groove; border-width: thin; width: 586px; height: 487px;  
    margin-left: 159px; margin-top: -910px; margin-right: 7px;">


        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600"   
    height="344">

            <object type="application/x-shockwave-flash" data="player.swf" width="580"   
    height="444">

                <param name="movie" value="Justin King Lesson 2.flv" />
                <param name="wmode" value="transparent" />
                <param name="bgcolor" value="#FFFFFF" />
                <param name="quality" value="high" />
                <param name="allowFullScreen" value="true" />
                <param name="allowscriptaccess" value="always" />
                <a href="http://www.adobe.com/go/getflash">
                <img     
     src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" 
     alt="Get Adobe Flash player" />
                </a>
                <param name="flashvars" value="vdo=Justin King Lesson  
     2.flv&amp;autoplay=false" />


            </object>

        </object>
    </div>
    <p>

        <input id="Button4" type="button" value="Upload"/>
        <input id="Button5" type="button" value="Download" /></p>

    <form ENCTYPE="multipart/form-data" ACTION=
          "VT" METHOD="POST">

        <table style="margin-top:30px;margin-left:160px;">
            <tr>
                <td colspan="1"><p align="center"/></td>
                <td>
                </td>
                <td><div id='file_browse_wrapper'>
                        <input type="file" name="F1" id="file_browse"   
    onclick="validate()" /></div></td>

            </tr>
        </table>
        <table style="margin-top:-37px;margin-left:164px;">

            <div id="mybutton_wrapper">
                <tr><td><p align="right"><input TYPE="submit" VALUE="" id="mybutton"  
    style="visibility:hidden"/></p></td></tr>
            </div>



            <tr><td colspan="2"></td></tr>

        </table>

    </form>
    </body>
    </html>

the uploading takes place by the execution of the VT.java servlet :

package xugglerPack;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.Image;


public class VT extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    HttpSession session = request.getSession(true);
    String user = "";

    String contentType = request.getContentType();
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
        DataInputStream in = new DataInputStream(request.getInputStream());
        int formDataLength = request.getContentLength();
        byte dataBytes[] = new byte[formDataLength];
        int byteRead = 0;
        int totalBytesRead = 0;
        while (totalBytesRead < formDataLength) {
            byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
            totalBytesRead += byteRead;
        }
        String file = new String(dataBytes);

        String saveFile = file.substring(file.indexOf("filename=\"") + 10);
        saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
        saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,  
        saveFile.indexOf("\""));
        int lastIndex = contentType.lastIndexOf("=");
        String boundary = contentType.substring(lastIndex + 1, contentType.length());
        int pos;
        pos = file.indexOf("filename=\"");
        pos = file.indexOf("\n", pos) + 1;
        pos = file.indexOf("\n", pos) + 1;
        pos = file.indexOf("\n", pos) + 1;
        int boundaryLocation = file.indexOf(boundary, pos) - 4;
        int startPos = ((file.substring(0, pos)).getBytes()).length;
        int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;

        String rootPath = "C:\\Users\\JD\\Documents\\NetBeansProjects\\xuggler\\web";

        session.setAttribute("myFolderpath", rootPath);
        FileOutputStream fileOut = new FileOutputStream(rootPath + "\\" + saveFile);

        fileOut.write(dataBytes, startPos, (endPos - startPos));
        fileOut.flush();
        fileOut.close();
        String myFile = rootPath.concat("\\").concat(saveFile);
        Main main=new Main();
        main.main(saveFile,myFile);

        RequestDispatcher rd = request.getRequestDispatcher("findSong.jsp");
        rd.forward(request, response);
    }

   }

   @Override
   protected void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
    processRequest(request, response);
  } 

   @Override
   protected void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
    processRequest(request, response);
  }

   @Override
   public String getServletInfo() {
   return "Short description";
    }

  }

During the uploading an image is generated with Main.java from the video using Xuggler :

  package xugglerPack;

  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;

  import java.util.Random;

    public class Main {

public static final long SECONDS_BETWEEN_FRAMES = 50;

private static final String outputFilePrefix =  
"C:\\Users\\JD\\Documents\\NetBeansProjects\\xuggler\\web\\";
// The video stream index, used to ensure we display frames from one and
// only one video stream from the media container.
private static long mVideoStreamIndex = SECONDS_BETWEEN_FRAMES;
//public String saveFile  =  "";
// Time of last frame write
private static long mLastPtsWrite = Global.DEFAULT_PTS_PER_SECOND +  
SECONDS_BETWEEN_FRAMES;
public static final long MICRO_SECONDS_BETWEEN_FRAMES =
        (long) (Global.DEFAULT_PTS_PER_SECOND * SECONDS_BETWEEN_FRAMES);

public void main(String saveFile, String inputFilename) {



    IMediaReader mediaReader = ToolFactory.makeReader(inputFilename);



    // stipulate that we want BufferedImages created in BGR 24bit color space

    mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);



    mediaReader.addListener(new ImageSnapListener());



    // read out the contents of the media file and

    // dispatch events to the attached listener

    while (mediaReader.readPacket() == null);



}

private static class ImageSnapListener extends MediaListenerAdapter {

    public void onVideoPicture(IVideoPictureEvent event) {



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

            // if the selected video stream id is not yet set, go ahead an

            // select this lucky video stream

            if (mVideoStreamIndex == SECONDS_BETWEEN_FRAMES) {
                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.DEFAULT_PTS_PER_SECOND + SECONDS_BETWEEN_FRAMES) {
            mLastPtsWrite = event.getTimeStamp() + SECONDS_BETWEEN_FRAMES;
            // String outputFilename = dumpImageToFile(event.getImage());
            dumpImageToFile(event.getImage());
        }



        // if it's time to write the next frame


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


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

        // 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);


        // update last write time

        mLastPtsWrite += MICRO_SECONDS_BETWEEN_FRAMES;

        } */


    }

    private String dumpImageToFile(BufferedImage image) {


        try {
            Random rg = new Random();
            int random = rg.nextInt(500);
            //   long randomlong = rg.nextLong();

            String outputFilepath = outputFilePrefix
                    + random + ".png";
            String outputFilename = random + ".png";
            String parts[] = outputFilename.split("\\.");
            String part1 = parts[0];
            System.out.println("the filename is splitted into two , where the name of  
     the file is " + part1);

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

            DBHandler db = new DBHandler();
            db.insertpic(outputFilename, part1, "me", outputFilepath);

            return outputFilename;

        } catch (IOException e) {

            e.printStackTrace();

            return null;

        }

      }
   }
}

The problem as I stated before is that when i run my application , the video gets uploaded and the image gets generated that time, but next time when i upload videos, only the video gets uploaded not the images. I have to restart Tomcat to achieve the same again, so please help. Thanks in advance and sorry for making this a long topic.

  • 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-12T20:33:54+00:00Added an answer on June 12, 2026 at 8:33 pm

    Try removing the static keyword for these two variables in the Main class:

    private static long mVideoStreamIndex = SECONDS_BETWEEN_FRAMES;
    private static long mLastPtsWrite = Global.DEFAULT_PTS_PER_SECOND + SECONDS_BETWEEN_FRAMES;
    

    If you make them static their value will be kept across calls and I doubt this is really what you want. Correct me if I’m wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I am trying to develop an Android based application, which can play video from
I am trying to develop a small app, that will store User's input about
i am trying to develop this app in android that has 3-4 buttons and
Trying to develop a test app wherethe look is like ebook. user can flip
I am trying to develop an android application that will stream the video from
I was trying to develop a video management software for which I was evaluating
I am trying develop a basic referrer system to my Django website, system will
Im trying to develop service that starts by bootup receiver if the wifi or
im trying to develop an app for a win CE mobile device that downloads

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.