i try to convert video using ffmpeg in ubuntu.
ffmpeg -i inputfile.flv -sameq outputfile.mpeg
this works if change directory to inputfile directory.
is that posible to use this command ?
ffmpeg -i "home/Documents/inputfile.flv" -sameq "home/Documents/outputfile.mpeg"
i don't want to change directory when i use that command, because that command is using for my java code. so my input file and output file is variable in my code .
here's my full code
package Converter;
import Controller.ConvertedButtonListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Arrays;
/**
*
* @author roylisto
*/
public class VideoConverter {
private String defaultFile;
private String convertedFile;
private ConverterThread myThread;
private ConvertedButtonListener butListener;
public VideoConverter(String fileDir,String convertOutput,ConvertedButtonListener buttonListener){
this.defaultFile=fileDir;
this.convertedFile=convertOutput;
this.butListener=buttonListener;
}
public void convertToMjpeg(){
String[] listCommands={"ffmpeg","-i","\""+defaultFile+"\"","-qscale","0","\""+convertedFile+"\""};
myThread=new ConverterThread(listCommands,this);
myThread.start();
}
public void setCommandStream(String stream){
butListener.setCommandOutput(stream);
}
class ConverterThread extends Thread{
VideoConverter vc;
String[] command;
ConverterThread(String[] command,VideoConverter vc){
this.command=command;
this.vc=vc;
}
public void run(){
synchronized(vc){
try{
String s = null;
Process process = new ProcessBuilder(command).start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
StringBuffer start= new StringBuffer();
// read the output from the command
while ((s = stdInput.readLine()) != null)
{
start.append(s);
vc.setCommandStream(s);
}
stdInput.close();
// read any errors from the attempted command
while ((s = stdError.readLine()) != null)
{
start.append(s);
vc.setCommandStream(s);
}
}catch(Exception ex){
System.out.println(ex.toString());
}
}
}
}
}
until now my code works well in windows with some modification like change ffmpeg to ffmpeg.exe because ffmpeg isn't native in my windows. but when i use my code in ubuntu it show this error
"/home/roylisto/Documents/Tugas Akhir/Video Master/3a.avi": No such file or directory
UPDATE solve problem, here's my code :)
package Converter;
import Controller.ConvertedButtonListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Arrays;
/**
*
* @author roylisto
*/
public class VideoConverter {
private String defaultFile;
private String convertedFile;
private ConverterThread myThread;
private ConvertedButtonListener butListener;
public VideoConverter(String fileDir,String convertOutput,ConvertedButtonListener buttonListener){
this.defaultFile=fileDir;
this.convertedFile=convertOutput;
this.butListener=buttonListener;
}
public void convertToMjpeg(){
String[] listCommands={"ffmpeg","-i",defaultFile,"-qscale","0",convertedFile};
myThread=new ConverterThread(listCommands,this);
myThread.start();
}
public void setCommandStream(String stream){
butListener.setCommandOutput(stream);
}
class ConverterThread extends Thread{
VideoConverter vc;
String[] command;
ConverterThread(String[] command,VideoConverter vc){
this.command=command;
this.vc=vc;
}
public void run(){
synchronized(vc){
try{
String s = null;
Process process = new ProcessBuilder(command).start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
StringBuffer start= new StringBuffer();
// read the output from the command
while ((s = stdInput.readLine()) != null)
{
start.append(s);
vc.setCommandStream(s);
}
stdInput.close();
// read any errors from the attempted command
while ((s = stdError.readLine()) != null)
{
start.append(s);
vc.setCommandStream(s);
}
}catch(Exception ex){
System.out.println(ex.toString());
}
}
}
}
}