?
Solved

java program to convert video from wmv to avi

Posted on 2010-08-12
6
Medium Priority
?
1,088 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 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