Hi there, ive come up with a system to auotmate generating stills from a
webcam, zipping the directory up and emailing the webmaster on a
broadcast close event. It first calls a custom stills generator class
which basically opens a runtime thread to a custom C# app i built to
interface with ffmpeg because it was fairly unstable doing it inside the
app.
Ive managed to first parse the duration of the clip from the ffmpeg
output, then the script loops through the duration and grabs stills at
certain given intervals so a bit of calculations involved, so is kinda
above what ffmpeg can do which is a range of frames at a point.
I had spent quite a while trying to stuff around with badly documented
C# bindings to the ffmpeg libraries, but the first one was hard to port
c code for extracting frames to images let alone work out to handle the
memory properly, and the second one uses a VC++ helper wrapper to the c
methods which took forever to get loaded because of crappy signing
policies and eventually ran into memory problems.
My question is, with the default setup atm, running the external app to
generate stills, then back in the java app zip the directory and then
email all on a close event, it seems to take quite some time for the
record stop event to be sent back tot he broadcaster.
What are my options, how can i manage to force to send the stop event
and somehow fork the code to do its thing in the background ? Should i
make the C# app do all the work and just run the single process ? Bit of
an issue there as id have to send alot of arguments to it :\
The generator code, doesnt seem to be doing a wait for, but isnt forking ?
public String generate(String flvFile)
{
String file = flvFile.substring(flvFile.lastIndexOf("/") + 1,
flvFile.length());
String dir = file.substring(0, file.lastIndexOf("."));
String archivePath = flvFile.substring(0, flvFile.lastIndexOf("/"));
String zipFile = stillPath + "/" + dir + ".zip";
String[] commands = new String[]{ffmpegPath,"/dir:"+flvPath +
"/" + archivePath,"/input:"+file,"/output:" + stillPath +
dir,"/start:33","/I:5"};
String line;
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(commands);
if (debug.equals(true))
{
BufferedReader input = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
Compress.zipDirectory(stillPath + "/" + dir, zipFile);
} catch (Exception e) {
e.printStackTrace();
}
return zipFile;
}
public void streamBroadcastClose(IBroadcastStream stream) {
log.debug("stream stopped");
if (this.getAttribute("isPreviewing").equals(false))
{
//generate stills
GenerateStills stills = new GenerateStills();
stills.setDebug(true);
stills.setFfmpegPath(ffmpegPath);
stills.setFlvPath(flvPath);
stills.setStillPath(stillPath);
String zipFile = stills.generate(stream.getSaveFilename());
<--- !!! thanks for this jochem !!
// send zip to supplied email
Mailer mail = new Mailer();
mail.setDebug(true);
mail.setProtocol(mailProtocol);
mail.setHost(mailHost);
mail.setUsername(mailUser);
mail.setPassword(mailPass);
mail.setSender(mailSender);
mail.setRcpt(mailRcpt);
mail.setSubject(mailSubject);
mail.setTextBody(String.format(mailBody,
stream.getSaveFilename().toString()));
mail.addAttachment(zipFile);
mail.send();
}
}
_______________________________________________
Red5 mailing list
[email protected]
http://osflash.org/mailman/listinfo/red5_osflash.org