java MP4 解析 第一步 解析ftyp box

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 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章