2012-08-27 115 views
0

我使用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()); 
+1

在代码中将图像%5d.png更改为图像%05d.png以创建视频图像有什么区别? – av501

+0

而且..你的问题在哪里? –

+0

uer1559108它的工作,你能解释我如何来了解这一点。我没有注意到这一点。非常感谢你,我从几个小时奋斗了 – Yashprit

回答

3

你已经宣布创立成为图像%05d.png并使用它ias image%5d.png。所以名称中有一个零点。而已!

+0

但是当我看到图像名称非常00000i.png没有额外的位反正解决方案工作正常 – Yashprit

+0

在创建的文件中名称是正确的。在你使用它的程序部分是错误的。 – av501

+0

非常感谢你的回答 – Yashprit