m3u8需要生产win的bat进行视频文件的批处理(ts有加密)
效果是把上万个文件夹,文件夹中有几百个ts,进行解密同时合并,献给懂java,懂视频,懂bat批处理的人
步骤 | 方法名统计 |
---|---|
遍历放资料的文件夹获取放List,把命令写入List,再写入文档 | produceBatFile |
你的file | checkExist |
写出 | writeOut |
produceBatFile
/**
* path 你放入文件的路径 eg:---- G:\MV\ts\ts1
* 生成bat文件的总的方法
*/
public static void produceBatFile(String path) throws Exception {
ArrayList<String> order = Lists.newArrayList();
order.add("cd "+ path);
File file = checkExist(path);
String[] list = file.list();
for (int i = 0; i < list.length; i++) {
String s = list[i];
String newPath = path + "\\"+ s;
File file1 = checkExist(newPath);
if (file1.isDirectory()) {
order.add("cd " + s);
order.add("ffmpeg -allowed_extensions ALL -i local.m3u8 -c copy -bsf:a aac_adtstoasc " + UUID.randomUUID().toString()+".mp4");
order.add("cd ..");
}
}
order.add("pause");
writeOut(null,order);
}
checkExist
public static File checkExist(String filepath) throws Exception{
File file=new File(filepath);
if (file.exists()) {//判断文件目录的存在
// System.out.println("文件夹存在!");
if(file.isDirectory()){//判断文件的存在性
// System.out.println("文件存在!");
}else{
file.createNewFile();//创建文件
// System.out.println("文件不存在,创建文件成功!" );
}
}else {
// System.out.println("文件夹不存在!");
File file2=new File(file.getParent());
file2.mkdirs();
// System.out.println("创建文件夹成功!");
if(file.isDirectory()){
// System.out.println("文件存在!");
}else{
file.createNewFile();//创建文件
// System.out.println("文件不存在,创建文件成功!" );
}
}
return file;
}
writeOut
/**
* 顺序写出
* @param path 写入文件的位置和名称,可以是虚值,我的方法会帮助创建
* @param li
* @throws Exception
* path可以填,不填写是我自己的默认值
*/
public static void writeOut(String path, List<String> li) throws Exception {
String pathDefault = "g:\\mv\\ts\\last.bat";
File file;
if (null == path) {
file = checkExist(pathDefault);
} else {
file = checkExist(path);
}
FileOutputStream s = new FileOutputStream(file);
//给win用,所以为GBK
OutputStreamWriter w = new OutputStreamWriter(s,"GBK");
BufferedWriter bw = new BufferedWriter(w);
for (int i = 0; i < li.size(); i++) {
bw.write(li.get(i));
bw.write("\r\n");
}
//先打开的后关闭
bw.close();
w.close();
s.close();
}
生成批处理文件
你需要有m3u8文件,和key.key文件。
注意:本文是视频玩法的高阶策略,不懂的玩家先了解ffmpeg m3n8 bat 等知识。还有,不懂可以私聊我,我看到会尽量回复。