2025年4月15日 星期二 乙巳(蛇)年 正月十六 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > Java

java MP4 解析 第一步 解析ftyp box

时间:06-29来源:作者:点击数:23

ftyp是MP4文件的第一个Box,包含了视频文件使用的编码格式、标准等,下面是一段定义和MP4文件头的解析

  • int len;
  • byte[] ftype = new byte[4];
  • byte[] majorBrand = new byte[4];
  • int fversion;
  • byte[] compatibleBrands = new byte[12];

初步解析实现:

  • public static void main(String[] args) throws Exception {
  • int len;
  • byte[] ftype = new byte[4];
  • byte[] majorBrand = new byte[4];
  • int fversion;
  • byte[] compatibleBrands = new byte[12];
  • InputStream in = new FileInputStream("F:\\测试文件\\video\\testKongBu.mp4");
  • //len
  • byte[] b = new byte[4];
  • in.read(b);
  • len = Array.bytesToInt(b);//byte[]转int 下同
  • //ftype
  • in.read(ftype);
  • //majorBrand
  • in.read(majorBrand);
  • //fversion
  • in.read(b);
  • fversion = Array.bytesToInt(b);
  • //compatibleBrands
  • in.read(compatibleBrands);
  • System.out.println("len\t\t=\t"+len);
  • System.out.println("ftyp\t\t=\t"+new String(ftype));
  • System.out.println("majorBrand\t=\t"+new String(majorBrand));
  • System.out.println("fversion\t=\t"+fversion);
  • System.out.println("compatibleBrands=\t"+new String(compatibleBrands));
  • in.close();
  • }

解析结果:

附:

byte[]转int代码    MP4默认是网络字节序(高字节序)

测试文件:

链接:https://pan.baidu.com/s/1lFrIJqI5TzQAhLH1SOGMDQ 

提取码:u98c 

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门