专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 应用服务器

ffmpeg 截图 失败解决方案

发布时间:2010-06-14 16:57:47 文章来源:www.iduyao.cn 采编人员:星星草
ffmpeg 截图 失败
 
 pfi.processImg("D:\\and.mp4");


public String ffmpegpath = "c:/workspace/ffmpeg.exe"; // ffmpeg.exe的目录  
  public boolean processImg(String path) {
  File fi = new File(path);
  List commend = new ArrayList();
   
  commend.add(ffmpegpath);
  commend.add("-i ");
  commend.add(path);  
  commend.add("-y");  
  commend.add("-f");  
  commend.add("image2");  
  commend.add("-ss");  
  commend.add("38");  
  commend.add("-t");  
  commend.add("0.001");
  commend.add("-s");  
  commend.add("320x240");  
  commend.add("D:\\flv\\ss" + ".jpg");  
  try {
  ProcessBuilder builder = new ProcessBuilder();
  builder.command(commend);
  builder.redirectErrorStream(true);
  System.out.println("视频截图开始...");
  // builder.start();
  Process process = builder.start();
  InputStream in = process.getInputStream();
  byte[] re = new byte[1024];
  System.out.print("正在进行截图,请稍候");
  while (in.read(re) != -1) {  
  System.out.print(".");  
  } 
  System.out.println("");
  in.close();
  System.out.println("视频截图完成...");
  return true;
  } catch (Exception e) {  
  e.printStackTrace();  
  return false;

显示:

视频截图开始...
正在进行截图,请稍候.
视频截图完成...
截图成功!

就是找不到图片,请教。。。。

------解决方案--------------------
把COMMAND输出一下,或者调试看看出什么值,然后在CMD里面执行一下看是否成功。
分享一下我写的视频截图部分代码,.NET。

C# code

                    System.Diagnostics.Process p = new System.Diagnostics.Process();
                    string ffmpeg = System.Web.HttpContext.Current.Server.MapPath("~/Content/ffmpeg/") + "ffmpeg.exe";
                    string ExportName = System.Web.HttpContext.Current.Server.MapPath(filePath + FileType + "/" + thisDate.ToString().Replace(" ", "") + "/") + randomDateTime + ".jpg";
                    string Command = ffmpeg + "  -i  " + FromName + " -y -s 640*480 -ss 00:00:02 -vframes 1 -an -sameq -f mjpeg " + ExportName;
                    log.Debug("command is :" + Command);
                    uploadFile.PreviewImage = ConfigurationSettings.AppSettings["WebSiteUrl"] + filePath.Replace("~", "") + FileType + "/" + thisDate.ToString().Replace(" ", "") + "/" + randomDateTime + ".jpg";
                    //System.Diagnostics.Process p = new System.Diagnostics.Process();
                    p.StartInfo.FileName = "cmd.exe ";
                    p.StartInfo.WorkingDirectory = System.Web.HttpContext.Current.Server.MapPath(filePath) + FileType + "/" + thisDate.ToString().Replace(" ", "");
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardInput = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.RedirectStandardError = true;
                    p.StartInfo.CreateNoWindow = true;
                    //开始执行
                    p.Start();
                    p.StandardInput.WriteLine(Command);
                    p.StandardInput.WriteLine("Exit");
                    p.WaitForExit();
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: