1 Star 0 Fork 0

ws/javm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
FileInfoExecutor.java 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
YCKJ2817 提交于 4年前 . video encode tool
package cn.angs;
import java.io.*;
import java.util.Arrays;
/**
* ClassName: FileInfoExecutor.java
* Description:
*
* @author wangshun@cloudwalk.cn
* @version 1.0.0
* @date 2021/07/23 18:26
*/
public class FileInfoExecutor {
private static final byte[] MPG_4 = new byte[]{0x66, 0x74, 0x79, 0x70, 0x4D, 0x53, 0x4E, 0x56};
private static final byte[] MPG_4_V1 = new byte[]{0x66, 0x74, 0x79, 0x70, 0x69, 0x73, 0x6F, 0x6D};
private static final byte[] AVI_HEAD = new byte[]{0x52, 0x49, 0x46, 0x46};
private static final byte[] AVI_TAIL = new byte[]{0x41, 0x56, 0x49, 0x20, 0x4C, 0x49, 0x53, 0x54};
public static boolean isMp4(String path) {
byte[] read = read(path, 4, 11);
return Arrays.equals(read, MPG_4) || Arrays.equals(read, MPG_4_V1);
}
public static boolean isAvi(String path) {
byte[] head = read(path, 0, 3);
if (Arrays.equals(head, AVI_HEAD)) {
byte[] tail = read(path, 8, 15);
return Arrays.equals(tail, AVI_TAIL);
}
return false;
}
private static byte[] read(String path, int from, int to) {
byte[] result = new byte[to - from + 1];
try {
FileInputStream fis = new FileInputStream(path);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.skip(from);
bis.read(result, 0, to - from + 1);
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
System.out.println(isAvi("C:\\Users\\YCKJ2817\\Desktop\\测试\\1.avi"));
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ws410/javm.git
git@gitee.com:ws410/javm.git
ws410
javm
javm
master

搜索帮助