版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/Yasha009/article/details/52065581
需要處理部分由專業相機拍攝的演講視頻,由於碼率太高導致時長29分鐘的視頻大小爲16GB多, 必須轉碼才能進行剪輯合成!指定碼率854x480, 轉完後大概900多MB。
這裏使用ffepeg進行視頻轉碼,這裏爲了同時對多個視頻進行轉碼,在Java文件裏寫個循環.
把D:\before文件夾下的視頻轉碼到D:\after下:
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class For {
public static void main(String[] args) throws Exception {
File file = new File("D:/before");
File[] array = file.listFiles();
for(int i=0;i<array.length;i++){
System.out.println(array[i].getPath());
String a = array[i].getPath().substring(9, array[i].getPath().length());
System.out.println(a);
a = "D:\\after\\" + a;
new For().videoTransfer(array[i].getPath(),a.replace(".avi", "____.avi"),"854x480");
}
System.out.println("-------------------------視頻全部解碼完成-------------------------------------");
}
//進行轉碼
public void videoTransfer(String oldFilePath,String fileSavePath,String screenSize) throws IOException, InterruptedException {
String a = "D:\\windows-ffmpeg\\ffmpeg-latest-win64-static\\bin\\ffmpeg.exe -y -i " + oldFilePath + " -s " + screenSize +" -vcodec libx264 " + fileSavePath ;
Runtime r=Runtime.getRuntime();
Process p=null;
try{
p=r.exec(a);
System.out.println("*************************************************" + fileSavePath);
}catch(Exception e){
System.out.println("錯誤:"+e.getMessage());
e.printStackTrace();
}
}
}