我使用JavaScript,ffmpeg和java创建视频编辑应用程序。使用FFMPEG我创建了提取n帧视频,比使用canvas.toDataUrl我用现有的图像帧速率替换新图像,一切都保持谨慎,但是当我使用这些图像创建视频时,FFMPEG从不包含新创建的PNG图像。使用FFMPEG从图像创建视频
代码从HTML5的画布保存PNG图像
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;
//Random rand = new Random();
File file = new File(outdir);
if(file.isFile()){
if(file.delete()){
File writefile = new File(outdir);
ImageIO.write(bImageFromConvert, "png", file);
}
}
代码从影像制作图像
String filePath = "D:\\temp\\some.mpg";
String outdir = "output";
File file = new File(outdir);
file.mkdirs();
Map<String, String> m = System.getenv();
/*
* String command[] =
* {"D:\\ffmpeg-win32-static\\bin\\ffmpeg","-i",filePath
* ,"-r 30","-f","image2",outdir,"\\user%03d.jpg"};
*
* ProcessBuilder pb = new ProcessBuilder(command); pb.start();
*/
String commands = "D:\\ffmpeg-win32-static\\bin\\ffmpeg -i " + filePath
+ " -r 30 -f image2 " + outdir + "\\image%05d.png";
Process p = Runtime.getRuntime().exec(commands);
从图像创建视频编码
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());
在代码中将图像%5d.png更改为图像%05d.png以创建视频图像有什么区别? – av501
而且..你的问题在哪里? –
uer1559108它的工作,你能解释我如何来了解这一点。我没有注意到这一点。非常感谢你,我从几个小时奋斗了 – Yashprit