We have created an application that records web camera streams using Xuggler, but video and audio are separated.
We need to merge, not concatenate, these two files.
How can this be done in Java?
If you have audio and video file then you can merge them to a single audio video file using FFmpeg:
You can call ffmpeg using Java as follows:
public class WrapperExe {
public boolean doSomething() {
String[] exeCmd = new String[]{"ffmpeg", "-i", "audioInput.mp3", "-i", "videoInput.avi" ,"-acodec", "copy", "-vcodec", "copy", "outputFile.avi"};
ProcessBuilder pb = new ProcessBuilder(exeCmd);
boolean exeCmdStatus = executeCMD(pb);
return exeCmdStatus;
} //End doSomething Function
private boolean executeCMD(ProcessBuilder pb)
{
pb.redirectErrorStream(true);
Process p = null;
try {
p = pb.start();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("oops");
p.destroy();
return false;
}
// wait until the process is done
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println("woopsy");
p.destroy();
return false;
}
return true;
}// End function executeCMD
} // End class WrapperExe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With