我使用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