本来想自己根据mp4的结构自己创建mp4文件的,但。。。还是先去找现有的解决方案看是否更好。
找到了一篇:http://www.ahlinux.com/embed/6770.html
然后到这里:https://launchpad.net/ubuntu/+source/mp4v2/2.0.0~dfsg0-3
下载了mp4v2的源码。
(还有一篇说的是另一个库的:http://linux.die.net/man/3/mp4,没找到相应的代码)
参考上篇文章,写了如下的编译脚本:
#!/bin/bash
if [ "$1" == "" ]; then
INSTALL_PATH=`pwd`/_install
else
if [ -d $1 ]; then
INSTALL_PATH=$1
else
exit 1
fi
fi
if [ ! -d $INSTALL_PATH ]; then
mkdir -p $INSTALL_PATH
fi
if [ -f config.log ]; then
make distclean
fi
./configure --prefix=$INSTALL_PATH \
--host=arm-none-linux-gnueabi \
--build=i486-linux-gnu \
--disable-option-checking \
--enable-optimize \
--disable-fvivibility \
--disable-gch \
--disable-largefile \
--enable-util \
--disable-cygmin-win32 \
--disable-mingw-threads \
--disable-dependency-tracking \
--enable-shared=yes \
--enable-static=no \
--enable-fast-install=yes \
--disable-libtool-lock \
--with-gnu-ld
if [ $? -eq 0 ]; then
make
if [ $? -eq 0 ]; then
make install
exit 0
fi
fi
直接运行这个build.sh,编译成功。
测试一下编译出来的工具,可以看到跟前几篇的分析结果是一致的:
[@localhost mp4v2-2.0.0]$ ./mp4info /nfs/23M00S.mp4
/home/mp4v2-2.0.0/.libs/lt-mp4info version 2.0.0
/nfs/23M00S.mp4:
Track Type Info
1 video H264 High@3, 60.000 secs, 206 kbps, 640x360 @ 20.000000 fps
2 audio MPEG-4 AAC LC, 60.544 secs, 16 kbps, 8000 Hz
[@localhost mp4v2-2.0.0]$ ./mp4track –list /nfs/23M00S.mp4
track[0] id=1
type = video
enabled = true
inMovie = false
inPreview = false
layer = 0
alternateGroup = 0
volume = 0.0000
width = 640.00000000
height = 360.00000000
language = Undetermined
handlerName =
userDataName =
track[1] id=2
type = audio
enabled = true
inMovie = false
inPreview = false
layer = 0
alternateGroup = 0
volume = 1.0000
width = 0.00000000
height = 0.00000000
language = Undetermined
handlerName =
userDataName =
[gumh@localhost mp4v2-2.0.0]$ ./mp4file –dump /nfs/23M00S.mp4
“/nfs/23M00S.mp4”: Dumping meta-information…
“/nfs/23M00S.mp4”: type ftyp (ftyp)
“/nfs/23M00S.mp4”: majorBrand = mp42
“/nfs/23M00S.mp4”: minorVersion = 0 (0x00000000)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type free (free)
“/nfs/23M00S.mp4”: type mdat (mdat)
“/nfs/23M00S.mp4”: type moov (moov)
“/nfs/23M00S.mp4”: type mvhd (moov.mvhd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: creationTime = 3527749381 (0xd2452f05)
“/nfs/23M00S.mp4”: modificationTime = 3527749440 (0xd2452f40)
“/nfs/23M00S.mp4”: timeScale = 1000 (0x000003e8)
“/nfs/23M00S.mp4”: duration = 60544 (0x0000ec80)
“/nfs/23M00S.mp4”: rate = 1.000000
“/nfs/23M00S.mp4”: volume = 1.000000
“/nfs/23M00S.mp4”: reserved1 = <70 bytes>
“/nfs/23M00S.mp4”: nextTrackId = 3 (0x00000003)
“/nfs/23M00S.mp4”: type iods (moov.iods)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: objectDescriptorId = 1 (0x001) <10 bits>
“/nfs/23M00S.mp4”: URLFlag = 0 (0x0) <1 bits>
“/nfs/23M00S.mp4”: includeInlineProfileLevelFlag = 0 (0x0) <1 bits>
“/nfs/23M00S.mp4”: reserved = 15 (0xf) <4 bits>
“/nfs/23M00S.mp4”: ODProfileLevelId = 255 (0xff)
“/nfs/23M00S.mp4”: sceneProfileLevelId = 255 (0xff)
“/nfs/23M00S.mp4”: audioProfileLevelId = 255 (0xff)
“/nfs/23M00S.mp4”: visualProfileLevelId = 255 (0xff)
“/nfs/23M00S.mp4”: graphicsProfileLevelId = 255 (0xff)
“/nfs/23M00S.mp4”: esIds
“/nfs/23M00S.mp4”: ociDescr
“/nfs/23M00S.mp4”: ipmpDescrPtr
“/nfs/23M00S.mp4”: extDescr
“/nfs/23M00S.mp4”: type trak (moov.trak)
“/nfs/23M00S.mp4”: type tkhd (moov.trak.tkhd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 1 (0x000001)
“/nfs/23M00S.mp4”: creationTime = 3527749381 (0xd2452f05)
“/nfs/23M00S.mp4”: modificationTime = 3527749440 (0xd2452f40)
“/nfs/23M00S.mp4”: trackId = 1 (0x00000001)
“/nfs/23M00S.mp4”: reserved1 = <4 bytes> 00 00 00 00 |….|
“/nfs/23M00S.mp4”: duration = 60000 (0x0000ea60)
“/nfs/23M00S.mp4”: reserved2 = <8 bytes> 00 00 00 00 00 00 00 00 |……..|
“/nfs/23M00S.mp4”: layer = 0 (0x0000)
“/nfs/23M00S.mp4”: alternate_group = 0 (0x0000)
“/nfs/23M00S.mp4”: volume = 0.000000
“/nfs/23M00S.mp4”: reserved3 = <2 bytes> 00 00 |..|
“/nfs/23M00S.mp4”: matrix = <36 bytes>
“/nfs/23M00S.mp4”: width = 640.000000
“/nfs/23M00S.mp4”: height = 360.000000
“/nfs/23M00S.mp4”: type mdia (moov.trak.mdia)
“/nfs/23M00S.mp4”: type mdhd (moov.trak.mdia.mdhd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: creationTime = 3527749381 (0xd2452f05)
“/nfs/23M00S.mp4”: modificationTime = 3527749440 (0xd2452f40)
“/nfs/23M00S.mp4”: timeScale = 90000 (0x00015f90)
“/nfs/23M00S.mp4”: duration = 5400000 (0x005265c0)
“/nfs/23M00S.mp4”: language = Undetermined (0x55c4)
“/nfs/23M00S.mp4”: reserved = <2 bytes> 00 00 |..|
“/nfs/23M00S.mp4”: type hdlr (moov.trak.mdia.hdlr)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: reserved1 = <4 bytes> 00 00 00 00 |….|
“/nfs/23M00S.mp4”: handlerType = vide
“/nfs/23M00S.mp4”: reserved2 = <12 bytes> 00 00 00 00 00 00 00 00 00 00 00 00 |…………|
“/nfs/23M00S.mp4”: name =
“/nfs/23M00S.mp4”: type minf (moov.trak.mdia.minf)
“/nfs/23M00S.mp4”: type vmhd (moov.trak.mdia.minf.vmhd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 1 (0x000001)
“/nfs/23M00S.mp4”: reserved = <8 bytes> 00 00 00 00 00 00 00 00 |……..|
“/nfs/23M00S.mp4”: type dinf (moov.trak.mdia.minf.dinf)
“/nfs/23M00S.mp4”: type dref (moov.trak.mdia.minf.dinf.dref)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 1 (0x00000001)
“/nfs/23M00S.mp4”: type url (moov.trak.mdia.minf.dinf.dref.url )
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 1 (0x000001)
“/nfs/23M00S.mp4”: location = (null)
“/nfs/23M00S.mp4”: type stbl (moov.trak.mdia.minf.stbl)
“/nfs/23M00S.mp4”: type stsd (moov.trak.mdia.minf.stbl.stsd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 1 (0x00000001)
“/nfs/23M00S.mp4”: type avc1 (moov.trak.mdia.minf.stbl.stsd.avc1)
“/nfs/23M00S.mp4”: reserved1 = <6 bytes> 00 00 00 00 00 00 |……|
“/nfs/23M00S.mp4”: dataReferenceIndex = 1 (0x0001)
“/nfs/23M00S.mp4”: reserved2 = <16 bytes> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…………….|
“/nfs/23M00S.mp4”: width = 640 (0x0280)
“/nfs/23M00S.mp4”: height = 360 (0x0168)
“/nfs/23M00S.mp4”: reserved3 = <14 bytes> 00 48 00 00 00 48 00 00 00 00 00 00 00 01 |.H…H……..|
“/nfs/23M00S.mp4”: compressorName = JVT/AVC Coding
“/nfs/23M00S.mp4”: reserved4 = <4 bytes> 00 18 ff ff |….|
“/nfs/23M00S.mp4”: type avcC (moov.trak.mdia.minf.stbl.stsd.avc1.avcC)
“/nfs/23M00S.mp4”: configurationVersion = 1 (0x01)
“/nfs/23M00S.mp4”: AVCProfileIndication = 100 (0x64)
“/nfs/23M00S.mp4”: profile_compatibility = 0 (0x00)
“/nfs/23M00S.mp4”: AVCLevelIndication = 30 (0x1e)
“/nfs/23M00S.mp4”: reserved = 63 (0x3f) <6 bits>
“/nfs/23M00S.mp4”: lengthSizeMinusOne = 3 (0x3) <2 bits>
“/nfs/23M00S.mp4”: reserved1 = 7 (0x7) <3 bits>
“/nfs/23M00S.mp4”: numOfSequenceParameterSets = 1 (0x01) <5 bits>
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: numOfPictureParameterSets = 1 (0x01)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type stts (moov.trak.mdia.minf.stbl.stts)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 1 (0x00000001)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type stsz (moov.trak.mdia.minf.stbl.stsz)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: sampleSize = 0 (0x00000000)
“/nfs/23M00S.mp4”: sampleCount = 1200 (0x000004b0)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type stsc (moov.trak.mdia.minf.stbl.stsc)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 1 (0x00000001)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type stco (moov.trak.mdia.minf.stbl.stco)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 60 (0x0000003c)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type trak (moov.trak)
“/nfs/23M00S.mp4”: type tkhd (moov.trak.tkhd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 1 (0x000001)
“/nfs/23M00S.mp4”: creationTime = 3527749381 (0xd2452f05)
“/nfs/23M00S.mp4”: modificationTime = 3527749440 (0xd2452f40)
“/nfs/23M00S.mp4”: trackId = 2 (0x00000002)
“/nfs/23M00S.mp4”: reserved1 = <4 bytes> 00 00 00 00 |….|
“/nfs/23M00S.mp4”: duration = 60544 (0x0000ec80)
“/nfs/23M00S.mp4”: reserved2 = <8 bytes> 00 00 00 00 00 00 00 00 |……..|
“/nfs/23M00S.mp4”: layer = 0 (0x0000)
“/nfs/23M00S.mp4”: alternate_group = 0 (0x0000)
“/nfs/23M00S.mp4”: volume = 1.000000
“/nfs/23M00S.mp4”: reserved3 = <2 bytes> 00 00 |..|
“/nfs/23M00S.mp4”: matrix = <36 bytes>
“/nfs/23M00S.mp4”: width = 0.000000
“/nfs/23M00S.mp4”: height = 0.000000
“/nfs/23M00S.mp4”: type mdia (moov.trak.mdia)
“/nfs/23M00S.mp4”: type mdhd (moov.trak.mdia.mdhd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: creationTime = 3527749381 (0xd2452f05)
“/nfs/23M00S.mp4”: modificationTime = 3527749440 (0xd2452f40)
“/nfs/23M00S.mp4”: timeScale = 8000 (0x00001f40)
“/nfs/23M00S.mp4”: duration = 484352 (0x00076400)
“/nfs/23M00S.mp4”: language = Undetermined (0x55c4)
“/nfs/23M00S.mp4”: reserved = <2 bytes> 00 00 |..|
“/nfs/23M00S.mp4”: type hdlr (moov.trak.mdia.hdlr)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: reserved1 = <4 bytes> 00 00 00 00 |….|
“/nfs/23M00S.mp4”: handlerType = soun
“/nfs/23M00S.mp4”: reserved2 = <12 bytes> 00 00 00 00 00 00 00 00 00 00 00 00 |…………|
“/nfs/23M00S.mp4”: name =
“/nfs/23M00S.mp4”: type minf (moov.trak.mdia.minf)
“/nfs/23M00S.mp4”: type smhd (moov.trak.mdia.minf.smhd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: reserved = <4 bytes> 00 00 00 00 |….|
“/nfs/23M00S.mp4”: type dinf (moov.trak.mdia.minf.dinf)
“/nfs/23M00S.mp4”: type dref (moov.trak.mdia.minf.dinf.dref)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 1 (0x00000001)
“/nfs/23M00S.mp4”: type url (moov.trak.mdia.minf.dinf.dref.url )
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 1 (0x000001)
“/nfs/23M00S.mp4”: location = (null)
“/nfs/23M00S.mp4”: type stbl (moov.trak.mdia.minf.stbl)
“/nfs/23M00S.mp4”: type stsd (moov.trak.mdia.minf.stbl.stsd)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 1 (0x00000001)
“/nfs/23M00S.mp4”: type mp4a (moov.trak.mdia.minf.stbl.stsd.mp4a)
“/nfs/23M00S.mp4”: reserved1 = <6 bytes> 00 00 00 00 00 00 |……|
“/nfs/23M00S.mp4”: dataReferenceIndex = 1 (0x0001)
“/nfs/23M00S.mp4”: soundVersion = 0 (0x0000)
“/nfs/23M00S.mp4”: reserved2 = <6 bytes> 00 00 00 00 00 00 |……|
“/nfs/23M00S.mp4”: channels = 2 (0x0002)
“/nfs/23M00S.mp4”: sampleSize = 16 (0x0010)
“/nfs/23M00S.mp4”: compressionId = 0 (0x0000)
“/nfs/23M00S.mp4”: packetSize = 0 (0x0000)
“/nfs/23M00S.mp4”: timeScale = 524288000 (0x1f400000)
“/nfs/23M00S.mp4”: type esds (moov.trak.mdia.minf.stbl.stsd.mp4a.esds)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: ESID = 0 (0x0000)
“/nfs/23M00S.mp4”: streamDependenceFlag = 0 (0x0) <1 bits>
“/nfs/23M00S.mp4”: URLFlag = 0 (0x0) <1 bits>
“/nfs/23M00S.mp4”: OCRstreamFlag = 0 (0x0) <1 bits>
“/nfs/23M00S.mp4”: streamPriority = 0 (0x00) <5 bits>
“/nfs/23M00S.mp4”: decConfigDescr
“/nfs/23M00S.mp4”: objectTypeId = 64 (0x40)
“/nfs/23M00S.mp4”: streamType = 5 (0x05) <6 bits>
“/nfs/23M00S.mp4”: upStream = 0 (0x0) <1 bits>
“/nfs/23M00S.mp4”: reserved = 1 (0x1) <1 bits>
“/nfs/23M00S.mp4”: bufferSizeDB = 365 (0x00016d) <24 bits>
“/nfs/23M00S.mp4”: maxBitrate = 15616 (0x00003d00)
“/nfs/23M00S.mp4”: avgBitrate = 15578 (0x00003cda)
“/nfs/23M00S.mp4”: decSpecificInfo
“/nfs/23M00S.mp4”: info = <2 bytes> 15 90 |..|
“/nfs/23M00S.mp4”: profileLevelIndicationIndexDescr
“/nfs/23M00S.mp4”: slConfigDescr
“/nfs/23M00S.mp4”: predefined = 2 (0x02)
“/nfs/23M00S.mp4”: ipiPtr
“/nfs/23M00S.mp4”: ipIds
“/nfs/23M00S.mp4”: ipmpDescrPtr
“/nfs/23M00S.mp4”: langDescr
“/nfs/23M00S.mp4”: qosDescr
“/nfs/23M00S.mp4”: regDescr
“/nfs/23M00S.mp4”: extDescr
“/nfs/23M00S.mp4”: type stts (moov.trak.mdia.minf.stbl.stts)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 1 (0x00000001)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type stsz (moov.trak.mdia.minf.stbl.stsz)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: sampleSize = 0 (0x00000000)
“/nfs/23M00S.mp4”: sampleCount = 473 (0x000001d9)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type stsc (moov.trak.mdia.minf.stbl.stsc)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 2 (0x00000002)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type stco (moov.trak.mdia.minf.stbl.stco)
“/nfs/23M00S.mp4”: version = 0 (0x00)
“/nfs/23M00S.mp4”: flags = 0 (0x000000)
“/nfs/23M00S.mp4”: entryCount = 60 (0x0000003c)
“/nfs/23M00S.mp4”:
“/nfs/23M00S.mp4”: type free (free)