Hello guys,
I have a live-record application that receives streams from a web SWF widget and a mobile application.
After creating a SWF that pushes H264 encoded video to wowza everything was going smooth until the mobile developers demanded that I convert the recorded videos from VP6 to H264 with a mp4 container.
Having used ffmpeg in several projects before I created the following command to convert flv to h264 mp4 :
ffmpeg -i src.flv -acodec libfaac -ab 128k -ar 44100 -ac 1 -vcodec h264 dest.mp4
I have this onUnpublish callback :
class StreamListener implements IMediaStreamActionNotify2 {
public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
stream.stopPublishing();
if(stream.getPublishVideoCodecId()==2){
File f =new File("/usr/local/WowzaMediaServer/content/"+streamName+".flv");
getLogger().info("file size "+f.length());
ffmpegFLV(streamName); //
}
private void ffmpegFLV(String streamName){
String command = "ffmpeg -i /usr/local/WowzaMediaServer/content/"+streamName+".flv -vf \"crop=((in_w/2)*2):((in_h/2)*2)\" -acodec libfaac -ab 128k -ar 44100 -ac 1 -vcodec h264 /usr/local/WowzaMediaServer/content/"+streamName+".mp4";
exec(command,true);
}
The Exec function
public static Process exec(String command, boolean wait) {
Process p;
try {
p = Runtime.getRuntime().exec(command);
java.io.InputStream stdin = p.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>");
} catch (IOException e) {
return null;
}
if (wait) {
try {
p.waitFor();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
try {
p.getInputStream().close();
p.getOutputStream().close();
p.getErrorStream().close();
} catch (IOException e) {
e.printStackTrace();
}
return p;
}
The following works fine:
The same ffmpeg command in the shell after disconnect.
Is the execution of the ffmpeg command somehow interrupted, the destination file created as an empty file with a size of 0.
Should i move this to a better place where wowza would be done in saving the data ?
Additional info:
At the same code i have succeeded in moving the file into another directory which confuses me because the ffmpeg command is basically working and i was able to move the file at this point but whenever i try to convert the video the ffmpeg creates an empty file.
Thanks for the help.