SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Execute the commands in java program

    Hi,

    i have a command to convert the video file into image

    ffmpeg -i sample.wmv -f image2 -t 0.001 -ss 3 ss.jpg

    i run that one in command prompt it converted the video file into image.


    But i executed that command in jsp Program .It didn't work.It shows error.

    Code:
    <% 
    Runtime rt = Runtime.getRuntime();
     Process p = rt.exec("ffmpeg  -i  sample.wmv  -f image2 -t 0.001 -ss 3 ss.jpg");
     %>
    error messages:

    org.apache.jasper.JasperException: Exception in JSP: /upload4.jsp:29

    26:
    27: <%
    28: Runtime rt = Runtime.getRuntime();
    29: Process p = rt.exec("ffmpeg -i sample.wmv -f image2 -t 0.001 -ss 3 ss.jpg");
    30: %>


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:381)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

    root cause

    java.io.IOException: CreateProcess: ffmpeg -i sample.wmv -f image2 -t 0.001 -ss 3 ss.jpg error=2
    java.lang.ProcessImpl.create(Native Method)
    java.lang.ProcessImpl.<init>(Unknown Source)
    java.lang.ProcessImpl.start(Unknown Source)
    java.lang.ProcessBuilder.start(Unknown Source)
    java.lang.Runtime.exec(Unknown Source)
    java.lang.Runtime.exec(Unknown Source)
    java.lang.Runtime.exec(Unknown Source)
    org.apache.jsp.upload4_jsp._jspService(upload4_jsp.java:97)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


    please tell the solution whats the Problem in my code.

  2. #2
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First off ... I'd strongly recommend against doing this directly from a JSP file. See this thread for some discussion on that:

    http://www.sitepoint.com/forums/showthread.php?t=587450

    That said... your problem is that you're giving exec() a relative path. It's going to look for ffmpeg in whatever directory the command to start tomcat was issued. You'll either need to properly calculate a relative path or just use an absolute path.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thank you to your reply.

    I used ffmpeg absolute path. I Resolved my errors. But in that it didn't convert the video file into image.

    i used the code like that

    Code:
    <&#37;
    Process p = Runtime.getRuntime().exec("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/ffmpeg  -i  sample.wmv  -f image2 -t 0.001 -ss 3 sssssss.jpg");
     %>

    I used the same command in command prompt

    ffmpeg -i sample.wmv -f image2 -t 0.001 -ss 3 sssssss.jpg

    It works fine. It didn't work in jsp program.please tell that whats the problem in my program
    Last edited by swethak; Dec 16, 2008 at 22:26. Reason: adding content

  4. #4
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I'm not really sure but maybe you need an absolute path on the wmv and maybe the jpg as well.

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for your reply
    Now i am trying with comments.

    I changed my code according to this

    Code:
    <% 
    
    String command="C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/ffmpeg.exe -i C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/sample.wmv -f image2 -t 0.001 -ss 3 C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/test/aaa.jpg";
    out.println(command);
    try{
     	Process p = Runtime.getRuntime().exec(command);
     	p.waitFor();
    	if (p.exitValue() == 0) {
    	    // do something;
    	}
    	out.println(p.exitValue());
    
    	
                    }catch(Exception e){
                    out.println(e);
                    }
    	
     %>

    But it give the same result.That means blank page.

    If any suggestion please reply me.

  6. #6
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't actually tested this but try adding it to your code to see what the process is saying:

    Code:
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    
    StringWriter pOutput = new StringWriter();
    String s ;
    while ((s = br.readLine())!= null) {
        pOutput.write(s);
        pOutput.write("\n");
    }
    
    while ((s = bre.readLine())!= null) {
        pOutput.write(s);
        pOutput.write("\n");
    }
    
    pOutput.flush();
    out.print(pOutput.getBuffer().toString());
    You'll want to put this before the waitFor(), although as I haven't tested this I don't know if it will work, also it may block on readLine()...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •