My project involves developing a video editing application using JavaScript, ffmpeg, and Java. I have managed to extract frames from a video using FFMPEG and replace them with new images through canvas.toDataURL. However, I am facing an issue where these newly created PNG images are not being included in the final video created by FFMPEG.
Below is the code snippet for saving PNG images from an HTML5 canvas:
Base64 decoder = new Base64();
byte[] pic = decoder.decodeBase64(request.getParameter("pic"));
String frameCount = request.getParameter("frame");
InputStream in = new ByteArrayInputStream(pic);
BufferedImage bImageFromConvert = ImageIO.read(in);
String outdir = "output\\" + frameCount;
File file = new File(outdir);
if(file.isFile()) {
if(file.delete()) {
File writefile = new File(outdir);
ImageIO.write(bImageFromConvert, "png", file);
}
}
Here's the code snippet for creating images from a video:
String filePath = "D:\\temp\\some.mpg";
String outdir = "output";
File file = new File(outdir);
file.mkdirs();
Map<String, String> m = System.getenv();
String commands = "D:\\ffmpeg-win32-static\\bin\\ffmpeg -i " + filePath + " -r 30 -f image2 " + outdir + "\\image%05d.png";
Process p = Runtime.getRuntime().exec(commands);
And finally, here's the code snippet for creating a video from images:
String filePath = "output";
File fileP = new File(filePath);
String commands = "D:\\ffmpeg-win32-static\\bin\\ffmpeg -f image2 -i " + fileP + "\\image%5d.png " + fileP + "\\video.mp4";
System.out.println(commands);
Runtime.getRuntime().exec(commands);
System.out.println(fileP.getAbsolutePath());