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 

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