<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/java-call-ffmpeg-convert-to-flv/</link>
<title><![CDATA[java中调用ffmpeg转换视频格式为flv]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Sat, 23 Oct 2010 15:22:08 +0000</pubDate> 
<guid>https://www.heckjj.com/java-call-ffmpeg-convert-to-flv/</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 微软雅黑;">最近这几天在写一个视频管理系统，遇到一个很大的问题就是如果把不同格式转换为flv格式，经过网上的一番搜索，自己在总结，整理，整理，终于整出来了！<br/>实现了视频进行转换的同时还能够进行视频截图和删除原文件的功能！<br/>格式转换主要原理就是先用java调用ffmpeg的exe文件！ <br/><br/>但是有些格式是ffmpeg不能处理的比如rmvb，这样的可以先调用mencoder先把格式转换为avi再进行转换为flv。<br/><br/>主要写了3个类：分别为Conver.java&nbsp;&nbsp;ConverBegin.java&nbsp;&nbsp;ConverVideo.java。<br/><br/>下面提供有ffmpeg的exe文件的下载址。<br/></span> <br/><br/><span style="font-family: 微软雅黑;">Conver.java&nbsp;&nbsp; 代码如下：</span><br/><textarea name="code" class="java" rows="15" cols="100">
package org.Conver; 
/* 
* Title:主类 
* @author Heck
* Version:1.0 
*time:2010 10 14 
*/ 
import java.awt.BorderLayout; 

import javax.swing.JFrame; 
import javax.swing.JScrollPane; 
import javax.swing.JTextArea; 

@SuppressWarnings(&quot;serial&quot;) 
public class Conver extends JFrame&#123; 
public static JTextArea OutShowLog; 
public Conver() &#123; 
&nbsp;&nbsp;setTitle(&quot;FLV转换&quot;); 
&nbsp;&nbsp;setSize(500, 400); 
&nbsp;&nbsp;setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
&nbsp;&nbsp;OutShowLog = new JTextArea(); 
&nbsp;&nbsp;JScrollPane OutPane = new JScrollPane(OutShowLog); 
&nbsp;&nbsp;add(OutPane,BorderLayout.CENTER); 
&nbsp;&nbsp;setVisible(true); 
&#125; 
public static void main(String args[]) &#123; 
&nbsp;&nbsp;new Conver(); 
&nbsp;&nbsp;ConverBegin cb = new ConverBegin(); 
&nbsp;&nbsp;cb.start(); 
&#125; 
&#125; </textarea><br/><span style="font-family: 微软雅黑;"><br/>ConverBegin.java&nbsp;&nbsp;代码如下：</span> <br/><textarea name="code" class="java" rows="15" cols="100">
package org.Conver; 

/* 
* Title:线程执行类 
* @author Heck
* Version:1.0 
*time:2010 10 14 
*/ 

import java.io.File; 

public class ConverBegin extends Thread&#123; 
String[] ff; 
public void run()&#123; 
&nbsp;&nbsp;while (true) &#123; 
&nbsp;&nbsp; String folderpath = &quot;other/&quot;; 
&nbsp;&nbsp; //String path = null; 
&nbsp;&nbsp; File f = new File(folderpath); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (f.isDirectory()) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp; ff = f.list(); 
&nbsp;&nbsp;&nbsp;&nbsp;int i = 0; 
&nbsp;&nbsp;&nbsp;&nbsp;while (i &lt; ff.length) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp; new ConverVideo(folderpath+ff[i]).beginConver(); 
&nbsp;&nbsp;&nbsp;&nbsp; i++; 
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;&nbsp;&nbsp;Conver.OutShowLog.append(&quot;---------------总共转换了&quot;+ff.length+&quot;-----------视频------------ &quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;ff = null; 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f = null; 
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(10000); 
&nbsp;&nbsp; &#125; catch (InterruptedException e) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;//如果失败重启线程 
&nbsp;&nbsp;&nbsp;&nbsp;this.start(); 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&#125; 
&#125; 
&#125; </textarea><br/><br/>ConverBegin.java 代码如下 <br/><textarea name="code" class="java" rows="15" cols="100">
package org.Conver; 
import java.io.File; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.Date; 
import java.util.List; 

/* 
* Title:FLV视频转换类 
* @author Heck
* ClassVer:0.1.001.2010.10.14 
*/ 

public class ConverVideo &#123; 
private Date dt; 
private long begintime; 
private String PATH; 
private String filerealname; // 文件名 不包括扩展名 
private String filename;&nbsp;&nbsp;&nbsp;&nbsp; // 包括扩展名 
private String videofolder = &quot;other/&quot;;&nbsp;&nbsp;//别的格式视频的目录 
private String flvfolder = &quot;flv/&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//flv视频的目录 
&nbsp;&nbsp;&nbsp;&nbsp;private String ffmpegpath=&quot;ffmpeg/ffmpeg.exe&quot;;&nbsp;&nbsp; //ffmpeg.exe的目录 
&nbsp;&nbsp;&nbsp;&nbsp;private String mencoderpath=&quot;ffmpeg/mencoder&quot;;&nbsp;&nbsp; //mencoder的目录 
&nbsp;&nbsp;&nbsp;&nbsp;private String videoRealPath=&quot;flv/&quot;;&nbsp;&nbsp;&nbsp;&nbsp;//截图的视频目录; 
&nbsp;&nbsp;&nbsp;&nbsp;private String imageRealPath =&quot;img/&quot;;&nbsp;&nbsp; //截图的存放目录 
&nbsp;&nbsp;&nbsp;&nbsp;//private String batrealpath=&quot;ffmpeg/ffmpeg.bat&quot;;&nbsp;&nbsp;//bat目录 
&nbsp;&nbsp;&nbsp;&nbsp;public ConverVideo()&#123;&#125; 
public ConverVideo(String path) &#123; 
&nbsp;&nbsp;PATH = path; 
&#125; 
&nbsp;&nbsp;&nbsp;&nbsp;public String getPATH() &#123; 
&nbsp;&nbsp;return PATH; 
&#125; 

public void setPATH(String path) &#123; 
&nbsp;&nbsp;PATH = path; 
&#125; 
public boolean beginConver()&#123; 
&nbsp;&nbsp;File fi = new File(PATH); 
&nbsp;&nbsp;filename = fi.getName(); 
&nbsp;&nbsp;filerealname = filename.substring(0, filename.lastIndexOf(&quot;.&quot;)) 
&nbsp;&nbsp;&nbsp;&nbsp;.toLowerCase(); 
&nbsp;&nbsp;Conver.OutShowLog.append(&quot;----接收到文件(&quot;+PATH+&quot;)需要转换-------------------------- &quot;); 
&nbsp;&nbsp;if (!checkfile(PATH)) &#123; 
&nbsp;&nbsp; Conver.OutShowLog.append(PATH + &quot;文件不存在&quot;+&quot; &quot;); 
&nbsp;&nbsp; return false; 
&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;dt = new Date(); 
&nbsp;&nbsp;begintime = dt.getTime(); 
&nbsp;&nbsp;Conver.OutShowLog.append(&quot;----开始转文件(&quot;+PATH+&quot;)-------------------------- &quot;); 
&nbsp;&nbsp;if (process()) &#123; 
&nbsp;&nbsp; Date dt2 = new Date(); 
&nbsp;&nbsp; Conver.OutShowLog.append(&quot;转换成功 &quot;); 
&nbsp;&nbsp; long endtime = dt2.getTime(); 
&nbsp;&nbsp; long timecha = (endtime - begintime); 
&nbsp;&nbsp; String totaltime = sumTime(timecha); 
&nbsp;&nbsp; Conver.OutShowLog.append(&quot;共用了:&quot; + totaltime+&quot; &quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(processImg()) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Conver.OutShowLog.append(&quot;截图成功了 &quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;else &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Conver.OutShowLog.append(&quot;截图不成功了 &quot;); 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PATH = null; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true; 
&nbsp;&nbsp;&#125;else &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PATH = null; 
&nbsp;&nbsp; return false; 
&nbsp;&nbsp;&#125; 
&#125; 
public boolean processImg() &#123; 
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(newfilename + &quot;-&gt;&quot; + newimg); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List commend = new java.util.ArrayList(); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(ffmpegpath); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;-i&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(videoRealPath+filerealname+&quot;.flv&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;-y&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;-f&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;image2&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;-ss&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;38&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;-t&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;0.001&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;-s&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(&quot;320x240&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commend.add(imageRealPath+filerealname+&quot;.jpg&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp; try &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProcessBuilder builder = new ProcessBuilder(); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;builder.command(commend); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;builder.start(); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; catch (Exception e) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace(); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
private boolean process() &#123; 
&nbsp;&nbsp;int type = checkContentType(); 
&nbsp;&nbsp;boolean status = false; 
&nbsp;&nbsp;if (type == 0) &#123; 

&nbsp;&nbsp; // status = processFLV(PATH);// 直接将文件转为flv文件 
&nbsp;&nbsp; status = processFLV(PATH); 
&nbsp;&nbsp;&#125; else if (type == 1) &#123; 
&nbsp;&nbsp; String avifilepath = processAVI(type); 
&nbsp;&nbsp; if (avifilepath == null) 
&nbsp;&nbsp;&nbsp;&nbsp;return false; 
&nbsp;&nbsp; // avi文件没有得到 
&nbsp;&nbsp; else &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;kaishizhuang&quot;); 
&nbsp;&nbsp;&nbsp;&nbsp;status = processFLV(avifilepath);// 将avi转为flv 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;return status; 
&#125; 

private int checkContentType() &#123; 
&nbsp;&nbsp;String type = PATH.substring(PATH.lastIndexOf(&quot;.&quot;) + 1, PATH.length()) 
&nbsp;&nbsp;&nbsp;&nbsp;.toLowerCase(); 
&nbsp;&nbsp;// ffmpeg能解析的格式：（asx，asf，mpg，wmv，3gp，mp4，mov，avi，flv等） 
&nbsp;&nbsp;if (type.equals(&quot;avi&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;mpg&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;wmv&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;3gp&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;mov&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;mp4&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;asf&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;asx&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;flv&quot;)) &#123; 
&nbsp;&nbsp; return 0; 
&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;// 对ffmpeg无法解析的文件格式(wmv9，rm，rmvb等), 
&nbsp;&nbsp;// 可以先用别的工具（mencoder）转换为avi(ffmpeg能解析的)格式. 
&nbsp;&nbsp;else if (type.equals(&quot;wmv9&quot;)) &#123; 
&nbsp;&nbsp; return 1; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;rm&quot;)) &#123; 
&nbsp;&nbsp; return 1; 
&nbsp;&nbsp;&#125; else if (type.equals(&quot;rmvb&quot;)) &#123; 
&nbsp;&nbsp; return 1; 
&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;return 9; 
&#125; 

private boolean checkfile(String path) &#123; 
&nbsp;&nbsp;File file = new File(path); 
&nbsp;&nbsp;if (!file.isFile()) &#123; 
&nbsp;&nbsp; return false; 
&nbsp;&nbsp;&#125;else &#123; 
&nbsp;&nbsp; return true; 
&nbsp;&nbsp;&#125; 
&#125; 

// 对ffmpeg无法解析的文件格式(wmv9，rm，rmvb等), 可以先用别的工具（mencoder）转换为avi(ffmpeg能解析的)格式. 
private String processAVI(int type) &#123; 
&nbsp;&nbsp;List commend = new java.util.ArrayList(); 
&nbsp;&nbsp;/* 
&nbsp;&nbsp; * commend.add(&quot;f:&#92;mencoder&quot;); commend.add(PATH); commend.add(&quot;-oac&quot;); 
&nbsp;&nbsp; * commend.add(&quot;lavc&quot;); commend.add(&quot;-lavcopts&quot;); 
&nbsp;&nbsp; * commend.add(&quot;acodec=mp3:abitrate=64&quot;); commend.add(&quot;-ovc&quot;); 
&nbsp;&nbsp; * commend.add(&quot;xvid&quot;); commend.add(&quot;-xvidencopts&quot;); 
&nbsp;&nbsp; * commend.add(&quot;bitrate=600&quot;); commend.add(&quot;-of&quot;); commend.add(&quot;avi&quot;); 
&nbsp;&nbsp; * commend.add(&quot;-o&quot;); commend.add(&quot;f:&#92;rmvb.avi&quot;); 
&nbsp;&nbsp; */ 
&nbsp;&nbsp;commend.add(mencoderpath); 
&nbsp;&nbsp;commend.add(PATH); 
&nbsp;&nbsp;commend.add(&quot;-oac&quot;); 
&nbsp;&nbsp;commend.add(&quot;mp3lame&quot;); 
&nbsp;&nbsp;commend.add(&quot;-lameopts&quot;); 
&nbsp;&nbsp;commend.add(&quot;preset=64&quot;); 
&nbsp;&nbsp;commend.add(&quot;-ovc&quot;); 
&nbsp;&nbsp;commend.add(&quot;xvid&quot;); 
&nbsp;&nbsp;commend.add(&quot;-xvidencopts&quot;); 
&nbsp;&nbsp;commend.add(&quot;bitrate=600&quot;); 
&nbsp;&nbsp;commend.add(&quot;-of&quot;); 
&nbsp;&nbsp;commend.add(&quot;avi&quot;); 
&nbsp;&nbsp;commend.add(&quot;-o&quot;); 
&nbsp;&nbsp;commend.add(videofolder + filerealname + &quot;.avi&quot;); 
&nbsp;&nbsp;// 命令类型：mencoder 1.rmvb -oac mp3lame -lameopts preset=64 -ovc xvid 
&nbsp;&nbsp;// -xvidencopts bitrate=600 -of avi -o rmvb.avi 
&nbsp;&nbsp;try &#123; 
&nbsp;&nbsp; ProcessBuilder builder = new ProcessBuilder(); 
&nbsp;&nbsp; builder.command(commend); 
&nbsp;&nbsp; Process p = builder.start(); 

&nbsp;&nbsp; doWaitFor(p); 
&nbsp;&nbsp; return videofolder + filerealname + &quot;.avi&quot;; 
&nbsp;&nbsp;&#125; catch (Exception e) &#123; 
&nbsp;&nbsp; e.printStackTrace(); 
&nbsp;&nbsp; return null; 
&nbsp;&nbsp;&#125; 
&#125; 

// ffmpeg能解析的格式：（asx，asf，mpg，wmv，3gp，mp4，mov，avi，flv等） 
private boolean processFLV(String oldfilepath) &#123; 

&nbsp;&nbsp;if (!checkfile(PATH)) &#123; 
&nbsp;&nbsp; System.out.println(oldfilepath + &quot; is not file&quot;); 
&nbsp;&nbsp; return false; 
&nbsp;&nbsp;&#125; 

&nbsp;&nbsp;List commend = new java.util.ArrayList(); 
&nbsp;&nbsp;commend.add(ffmpegpath); 
&nbsp;&nbsp;commend.add(&quot;-i&quot;); 
&nbsp;&nbsp;commend.add(oldfilepath); 
&nbsp;&nbsp;commend.add(&quot;-ab&quot;); 
&nbsp;&nbsp;commend.add(&quot;64&quot;); 
&nbsp;&nbsp;commend.add(&quot;-acodec&quot;); 
&nbsp;&nbsp;commend.add(&quot;mp3&quot;); 
&nbsp;&nbsp;commend.add(&quot;-ac&quot;); 
&nbsp;&nbsp;commend.add(&quot;2&quot;); 
&nbsp;&nbsp;commend.add(&quot;-ar&quot;); 
&nbsp;&nbsp;commend.add(&quot;22050&quot;); 
&nbsp;&nbsp;commend.add(&quot;-b&quot;); 
&nbsp;&nbsp;commend.add(&quot;230&quot;); 
&nbsp;&nbsp;commend.add(&quot;-r&quot;); 
&nbsp;&nbsp;commend.add(&quot;24&quot;); 
&nbsp;&nbsp;commend.add(&quot;-y&quot;); 
&nbsp;&nbsp;commend.add(flvfolder + filerealname + &quot;.flv&quot;); 
&nbsp;&nbsp;try &#123; 
&nbsp;&nbsp; ProcessBuilder builder = new ProcessBuilder(); 
&nbsp;&nbsp; String cmd = commend.toString(); 
&nbsp;&nbsp; builder.command(commend); 
&nbsp;&nbsp; // builder.redirectErrorStream(true); 
&nbsp;&nbsp; Process p = builder.start(); 
&nbsp;&nbsp; doWaitFor(p); 
&nbsp;&nbsp; p.destroy(); 
&nbsp;&nbsp; deleteFile(oldfilepath); 
&nbsp;&nbsp; return true; 
&nbsp;&nbsp;&#125; catch (Exception e) &#123; 
&nbsp;&nbsp; e.printStackTrace(); 
&nbsp;&nbsp; return false; 
&nbsp;&nbsp;&#125; 
&#125; 

public int doWaitFor(Process p) 

&#123; 
&nbsp;&nbsp;InputStream in = null; 
&nbsp;&nbsp;InputStream err=null; 
&nbsp;&nbsp;int exitValue = -1; // returned to caller when p is finished 
&nbsp;&nbsp;try &#123; 
&nbsp;&nbsp; System.out.println(&quot;comeing&quot;); 
&nbsp;&nbsp; in = p.getInputStream(); 
&nbsp;&nbsp; err = p.getErrorStream(); 
&nbsp;&nbsp; boolean finished = false; // Set to true when p is finished 

&nbsp;&nbsp; while (!finished) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;try &#123; 
&nbsp;&nbsp;&nbsp;&nbsp; while (in.available() &gt; 0) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Print the output of our system call 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Character c = new Character((char) in.read()); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(c); 
&nbsp;&nbsp;&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&nbsp;&nbsp; while (err.available() &gt; 0) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Print the output of our system call 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Character c = new Character((char) err.read()); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(c); 
&nbsp;&nbsp;&nbsp;&nbsp; &#125; 

&nbsp;&nbsp;&nbsp;&nbsp; // Ask the process for its exitValue. If the process 
&nbsp;&nbsp;&nbsp;&nbsp; // is not finished, an IllegalThreadStateException 
&nbsp;&nbsp;&nbsp;&nbsp; // is thrown. If it is finished, we fall through and 
&nbsp;&nbsp;&nbsp;&nbsp; // the variable finished is set to true. 
&nbsp;&nbsp;&nbsp;&nbsp; exitValue = p.exitValue(); 
&nbsp;&nbsp;&nbsp;&nbsp; finished = true; 

&nbsp;&nbsp;&nbsp;&nbsp;&#125; catch (IllegalThreadStateException e) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp; // Process is not finished yet; 
&nbsp;&nbsp;&nbsp;&nbsp; // Sleep a little to save on CPU cycles 
&nbsp;&nbsp;&nbsp;&nbsp; Thread.currentThread().sleep(500); 
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&#125; catch (Exception e) &#123; 
&nbsp;&nbsp; // unexpected exception! print it out for debugging... 
&nbsp;&nbsp; System.err.println(&quot;doWaitFor();: unexpected exception - &quot; 
&nbsp;&nbsp;&nbsp;&nbsp; + e.getMessage()); 
&nbsp;&nbsp;&#125; finally &#123; 
&nbsp;&nbsp; try &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;if(in!=null) 
&nbsp;&nbsp;&nbsp;&nbsp;&#123; 
&nbsp;&nbsp;&nbsp;&nbsp;in.close(); 
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &#125; catch (IOException e) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(e.getMessage()); 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp; if(err!=null) 
&nbsp;&nbsp; &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;try &#123; 
&nbsp;&nbsp;&nbsp;&nbsp; err.close(); 
&nbsp;&nbsp;&nbsp;&nbsp;&#125; catch (IOException e) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(e.getMessage()); 
&nbsp;&nbsp;&nbsp;&nbsp;&#125; 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&#125; 
&nbsp;&nbsp;// return completion status to caller 
&nbsp;&nbsp;return exitValue; 
&#125; 

public void deleteFile(String filepath) &#123; 
&nbsp;&nbsp;File file = new File(filepath); 
&nbsp;&nbsp;if (PATH.equals(filepath)) &#123; 
&nbsp;&nbsp; if (file.delete()) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;文件&quot; + filepath + &quot;已删除&quot;); 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&#125; else &#123; 
&nbsp;&nbsp; if (file.delete()) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;文件&quot; + filepath + &quot;已删除 &quot;); 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp; File filedelete2 = new File(PATH); 
&nbsp;&nbsp; if (filedelete2.delete()) &#123; 
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;文件&quot; + PATH + &quot;已删除&quot;); 
&nbsp;&nbsp; &#125; 
&nbsp;&nbsp;&#125; 
&#125; 

public String sumTime(long ms) &#123; 
&nbsp;&nbsp;int ss = 1000; 
&nbsp;&nbsp;long mi = ss * 60; 
&nbsp;&nbsp;long hh = mi * 60; 
&nbsp;&nbsp;long dd = hh * 24; 

&nbsp;&nbsp;long day = ms / dd; 
&nbsp;&nbsp;long hour = (ms - day * dd) / hh; 
&nbsp;&nbsp;long minute = (ms - day * dd - hour * hh) / mi; 
&nbsp;&nbsp;long second = (ms - day * dd - hour * hh - minute * mi) / ss; 
&nbsp;&nbsp;long milliSecond = ms - day * dd - hour * hh - minute * mi - second 
&nbsp;&nbsp;&nbsp;&nbsp;* ss; 

&nbsp;&nbsp;String strDay = day &lt; 10 ? &quot;0&quot; + day + &quot;天&quot; : &quot;&quot; + day + &quot;天&quot;; 
&nbsp;&nbsp;String strHour = hour &lt; 10 ? &quot;0&quot; + hour + &quot;小时&quot; : &quot;&quot; + hour + &quot;小时&quot;; 
&nbsp;&nbsp;String strMinute = minute &lt; 10 ? &quot;0&quot; + minute + &quot;分&quot; : &quot;&quot; + minute + &quot;分&quot;; 
&nbsp;&nbsp;String strSecond = second &lt; 10 ? &quot;0&quot; + second + &quot;秒&quot; : &quot;&quot; + second + &quot;秒&quot;; 
&nbsp;&nbsp;String strMilliSecond = milliSecond &lt; 10 ? &quot;0&quot; + milliSecond : &quot;&quot; 
&nbsp;&nbsp;&nbsp;&nbsp;+ milliSecond; 
&nbsp;&nbsp;strMilliSecond = milliSecond &lt; 100 ? &quot;0&quot; + strMilliSecond + &quot;毫秒&quot; : &quot;&quot; 
&nbsp;&nbsp;&nbsp;&nbsp;+ strMilliSecond + &quot; 毫秒&quot;; 
&nbsp;&nbsp;return strDay + &quot; &quot; + strHour + &quot;:&quot; + strMinute + &quot;:&quot; + strSecond + &quot; &quot; 
&nbsp;&nbsp;&nbsp;&nbsp;+ strMilliSecond; 

&#125; 
&#125; </textarea><br/><span style="font-family: 微软雅黑;"><strong><span style="color: #DC143C;">下载地址：</span></strong><a href="http://www.hecks.tk/images/others/download.gif" target="_blank"><img src="http://www.hecks.tk/images/others/download.gif" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><strong><u><span style="color: #DC143C;"><a href="http://good.gd/780167.htm" target="_blank">&gt;&gt;&gt;点击下载fmpeg的exe文件&lt;&lt;&lt;</a></span></u></strong><br/></span><br/>Tags - <a href="https://www.heckjj.com/tags/java/" rel="tag">java</a> , <a href="https://www.heckjj.com/tags/%25E8%25B0%2583%25E7%2594%25A8ffmpeg/" rel="tag">调用ffmpeg</a> , <a href="https://www.heckjj.com/tags/%25E8%25BD%25AC%25E6%258D%25A2/" rel="tag">转换</a> , <a href="https://www.heckjj.com/tags/%25E8%25A7%2586%25E9%25A2%2591%25E6%25A0%25BC%25E5%25BC%258F/" rel="tag">视频格式</a> , <a href="https://www.heckjj.com/tags/flv/" rel="tag">flv</a>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/java-call-ffmpeg-convert-to-flv/#blogcomment</link>
<title><![CDATA[[评论] java中调用ffmpeg转换视频格式为flv]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/java-call-ffmpeg-convert-to-flv/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>