[英]Creating video from image using FFMPEG
I am creating video editing application using JavaScript, ffmpeg and java. 我正在使用JavaScript,ffmpeg和Java创建视频编辑应用程序。 Using FFMPEG i have created extract n frame of video, than using canvas.toDataUrl I am replacing new image with existing image frame rate and everything has taken care, but when I use these image to create video, FFMPEG never include newly created PNG image.
与使用canvas.toDataUrl相比,使用FFMPEG创建的视频提取了n帧视频,我用现有的图像帧速率替换了新图像,并且一切都已妥当,但是当我使用这些图像创建视频时,FFMPEG永远不会包含新创建的PNG图像。
code to save png image from HTML5 canvas 从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);
}
}
Code for creating image from video 用于从视频创建图像的代码
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);
code for creating video from image 用于从图像创建视频的代码
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());
You have declared the creation to be image%05d.png and using it ias image%5d.png. 您已将创建声明为image%05d.png,并使用ias image%5d.png。 So there is one zero less in the name.
因此,名称少了一个零。 That's it!
而已!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.