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();