Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

java program to convert video from wmv to avi

Posted on 2010-08-12
6
Medium Priority
?
1,103 Views
Last Modified: 2013-12-22
Hi,

i had created a java program which converts the format from wmv to avi . My programming is running fine but i want to get a confirmation message after finishing the conversion. Then i included the proc.waitFor() method for waiting till the process gets finished.

 After putting this line the program gets hanged and only continuing after terminating the program

Below is my program
package com.suku.dev;


import java.io.*;

public class TestingRuntime {
	
	public static void main(String args[])throws Exception
	
	{
		
		
		
		   Runtime rt=  Runtime.getRuntime();
		     
		     Process proc=  rt.exec("ffmpeg -i \"C:\\videos\\Nuv.wmv\"  -vcodec mpeg4 \"C:\\videos\\Sui.avi\" ");
		    
                  // if i include till above line...my program works fine
		     // If i include below lines then the program gets hanged 
		
		     InputStream stdin = proc.getInputStream();
	            InputStreamReader isr = new InputStreamReader(stdin);
	            BufferedReader br = new BufferedReader(isr);
	            String line = null;
	            System.out.println("<OUTPUT>");
	            while ( (line = br.readLine()) != null)
	                System.out.println(line);
	            System.out.println("</OUTPUT>");
	            int exitVal = proc.waitFor();            
	         
		     System.out.println("Process exitValue: " +exitVal);
	            
	      
	  
	}

}

Open in new window

                                                   

Please let me know the way to identify after the process gets finished
0
Comment
Question by:sukumarr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:WhiteMage
ID: 33424486
>>>>After putting this line the program gets hanged and only continuing after terminating the program

That's exactly what "proc.waitFor()" does.  It waits until the process (ffmpeg in this case) is terminated.

If after you have no more input, you know the process is done, then you could put this instead of proc.waitFor:

proc.destroy();
int exitVal = proc.exitValue();
0
 

Author Comment

by:sukumarr
ID: 33425118
I tried to replace proc.waitFor() with destroy and exitValue as you said but i looks like, the process is still hanging and i'm unable to figure out at which exact place the input streaming ends

Do i need to put some Thread sleep method and check for every frequency or any other better way...
0
 
LVL 8

Expert Comment

by:WhiteMage
ID: 33425288
What exactly is the output of the program?  There might be a line that says when it is done.

Also, perhaps, the line is never going to null?  Does the ending "</OUTPUT>" get printed?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 92

Assisted Solution

by:objects
objects earned 1000 total points
ID: 33425562
you may need to also read any output written to stderr

http://helpdesk.objects.com.au/java/runtime-exec-locks-up
0
 
LVL 8

Accepted Solution

by:
WhiteMage earned 1000 total points
ID: 33425614
Yes, that is the problem.  To clarify objects vague response, use getErrorStream.  I downloaded the program and tried it and found that this was the problem before objects response.  It worked perfectly with this:

InputStream stdin = proc.getErrorStream();

Now, a problem that you might run into is that it does hang if the file already exists.  To get around that, use "-y" flag to overwrite an already existing file.  Or you could parse the input and write to the proc.getOutputStream:

//added -y flag to overwrite a file if it already exists
Process proc=  rt.exec("ffmpeg -y -i \"C:\\videos\\Nuv.wmv\"  -vcodec mpeg4 \"C:\\videos\\Sui.avi\" ");
0
 

Author Closing Comment

by:sukumarr
ID: 33427412
@objects

Thanks for giving hint and it worked perfectly. But i couldn't understand why it's writing to stderr instead of stdin.

@WhiteMage

Thanks for helping. Though the file exists, it's overwriting by default without providing -y flag. Anyways i appreciate your help
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question