2024年3月12日发(作者:)

Java实现批量视频格式转换

实现原理,是通过java调用ffmpeg实现视频格式的转换,所以你要下载一个

文件,以下是源码:

import .*;

import ist;

import ;

/**

* java

实现视频格式的转化

*

*/

public class ConvertVideo {

//ffmpeg所在目录

public static final String ffmpegPath =

"E:";

//源视频目录

public static String SRC_DIR = "D:video";

//输出视频目录

public static String DES_DIR = "E:";

public static int INDEX = 0;

public static int COUNT = 0;

public static List allFiles = new ArrayList();

public static void main(String[] args) {

getAllFile(SRC_DIR, DES_DIR);

startConvertVideo();

}

public static void getAllFile(String srcDir, String desDir) {

File file = new File(srcDir);

if (ctory()) {

File desFile = new File(desDir + tor + e());

if (!()) {

();

}

File[] fs = les();

for (File f : fs) {

if (ctory()) {

getAllFile(olutePath(), olutePath());

} else {

if (e().endsWith(".flv")) {

String tempDir = olutePath() +

tor + e().replace(".flv", ".mp4");

if (!new File(tempDir).exists()) {

String[] strArray = new String[]{olutePath(),

tempDir};

(strArray);

}

}

}

}

} else {

if (e().endsWith(".flv")) {

String tempDir = desDir + tor +

e().replace(".flv", ".mp4");

if (!new File(tempDir).exists()) {

String[] strArray = new String[]{olutePath(),

tempDir};

(strArray);

}

}

}

}

public static void startConvertVideo() {

COUNT = ();

INDEX = 0;

next();

}

public static void next() {

if (() == 0) {

n("===========全部转换完成================>");

return;

}

String[] arr = (0);

convert(arr[0], arr[1]);

}