MP4格式解析文档

上传:李天Mars 浏览: 65 推荐: 0 文件:PDF 大小:1013.49KB 上传时间:2020-07-30 23:10:14 版权申诉
这个是目前我见过的最清晰的描述了MP4文件格式的文档。Elements of the H. 264 Video/ AAC Audio MP4 MovieConstruction of the MP4 Movie ContainerThe present application note describes the core elements of a canonically constructed MPEG-4 movie usingH. 264 video and AAC-LC audio encapsulated in a media container commonly termed a MP 4 movie. TheMP4 movie elements described here were generated by the rtP a/ Streaming Client/Server Applicationsavailable as part of the Cimarron Systems Digital Media Software Development Kits(DMSDK-and, whilevisual objects Part 12: /506 omp/ies with ISO/IEC 14496-12 Information technology- Coding of audio-the mP4 movie container case media file format and the Quick Time movie file Format Specification appleAugust, 2010, the discussion here focuses on a subset of the container elements defined in bothspecificationsDMSDK Development EnvironmentFigure 1 shows a context diagram of the typical development environment in which the DMSDK operatesincluding: the TM320DM36X DVEVM running a number of the DMSDK components, a Ubuntu Linux Hostcomputer, an audio/video source, and a video display/audio output deviceDMSDK Development ContextTMS320DM36X DVEVMSerial I/OEthernetUbuntu Linux HostA/VI/O DevicesFigure 1: DMSDK Development Context DiagramMP4 Atom DescriptionsAs illustrated in Figure 2, the MP4 movie container file format has a very specific hierarchy of elements called Atomsin MPEG-4 terminology, they are called Boxes). Using Apple's naming convention, each of these moviecontainer elements are described briefly below(Color Code for atom Description Figures: blue representsthe 'atom size; green represents the atom content' yellow represents the NAL Unit Size ' and watermelonrepresents the nal unit byte sequenceo 2012-2014 Cimarron Systems, LLC-all rights reservedElements of the H. 264 Video/ AAC Audio MP4 MoviesampleMovie m4vQ Atom TypeV File root- entire fileftyp- file typefree- free spacemdat-Media datav moov- Movimhd- Moyie headerv trak- trackthd track headerv mdia- Mediamdhd- Media headerhd r- Handler descriptionV minf-Media Informationvmd- Video media headerv dinf- data informationdref - Data referenceV stbl- Sample tablestsd- Sample descriptionstts Sample to Timetss Sync Samplestsc - Sample to Chunktsz- Sample sizesstco- chunk offset tabletrak- trackthd- track headerdia- mediamdhd- Media headerinf- media Informatismhd- Sound media headery dinf -data Informationdref- Data referencev stbl- sample tablestsd -Sample descriptionsstts -Sample to timesample to Chunktco - Chunk offset tablev udta-User-Datameta- Metadata0 resultFigure 2: MP4 Movie Container OverviewFile Type, Free, and Media Data atomsFigure 3 illustrates the general structure of the MP4 movie container file structure, specifically the: ' ftypatom; free' atom; 'mdat' A/V media data block; and two full (plus one partial) H. 264 NAL Unitsftyp contains the following fieldsSize--A 32-bit unsigned integer that specifies the number of bytes in this file Type atom; set heret0'0x0000001CType-A 32-bit unsigned integer that identifies the atom type, represented as a four-charactercode; this field must be set to ' ftypMajor Brand-A 32-bit unsigned integer that identifies the movie file type, represented as a four-character code; is set to 'm4v '(note the trailing ASCll space character)o 2012-2014 Cimarron Systems, LLC-all rights reservedElements of the H. 264 Video/ AAC Audio MP4 MovieMinor Version-A 32-bit unsigned integer that identifies the movie file type minor version,represented as a four- byte number represented in binary coded decimal (bcd)form; is set to"O×00000200.Compatible Brands-A series of unsigned 32-bit integers listing compatible file formats; set hereto isom,iso2 and 'avc1a free contains the following fieldsSize--A 32-bit unsigned integer that specifies the number of bytes in this Free atom; set here to0×00000008Type-A 32-bit unsigned integer that identifies the atom type, represented as a four-charactercode: this field must be set to 'freeFree Space-The number of bytes of Free Space; a place holder not allocated heresampleMovie m4vQ ftypv file root entire file68666681C667479784D3456286668typE+v1669736F669736F326176633166讠sms02vc126672656544047416064617400875 free,@Ghmdat,u48876482AD84B54562B8AC547428242Bgd*:, Eblr'tt来15c562A3矗刚1518AE88姓18帕8E848545628BAC54742E2A2B15a8ETW+B中士56aA31248521393C927E4FE4FC9F2W*:$!9點0.012193016B4B2D0B0B“(件:15:0 out of 71503073 bytesftyp-File Typefree- Free spaceO out of 8 bytesmdat- Media data4447416D6461746675676482A.@ Jamdat…gd*16ADB4历5462BA42822150562A,Ebt米+,32A姓1518AE2B151008的的07158A8E8°,+…,唱妩4454562B5474202A2BL5C562A3416TW+iGBW642485213930927E4FE4F9F279B9834D92,yTB124299c94F93F227E4F93DCD9.Bei0."t"96始648282DD8AA4B昭丽B466E解,-,1F181姓1E348866FF2F7EE1784420A.r+.".B1250886468EE33681+66875..,h,,AA∠ 300 32 4 R236 i人A少O out of 71321409 bytesl resultFigure 3: MP4 Movie Container'ftyp', free, and mdat Structuresmdat contains the following fieldsSize--A 32-bit unsigned integer that specifies the number of bytes in this Media Data portion ofthe mP4 movie file set here to 0x04404741o 2012-2014 Cimarron Systems, LLC-all rights reservedElements of the H. 264 Video /AAC Audio MP4 Moviefield must be set to '!. Note: ' mdat is technically not an atom ra ther it is the actualan isType-A 32-bit unsigned integer that identifies the type, represented as a four-character code; thiMedia data that other atoms may reference via a byte offset into the data blockMovie and movie header atomsFigure 4 shows the structure of the 'moov'and'mvhd' atomsmoov contains the following fieldsSize-A 32-bit unsigned integer that specifies the number of bytes in this movie atom set here to0x0002C57CType- A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to 'moov■ sampleMovie m4vamooV- MoviemmDm西mmBF6B2m32857BC8B81818pgga6488888B81888g8096的gg的的∴120的67姓685128阵6B的的CC85CCF85Ctkd1 14RN AR Ar 1nR r A AI r三匚RRR0 out of 181628 bytesmohd- Movie headerf lags 1xo6661time念cale1EEEduration 359368rate 1.awoLume 1.1reated Wednesday, December 19, 2012 11: 9: 13 PM Mountain standard timenodif ied Wednesday, December 19, 2012 11: 09: 13 PM Mountain standard timerEs已 TED EreservedFxEExE6EB6F38Ex88016886ExE888E886xAEAFFFEF日 XFETFAFE区Epredef inedFt track id 3l resultsFigure 4: MP4 Movie Container 'mooy' and ' mhd structuresmhd contains the following fieldsA 32-bit unsigned integer that specifies the number of bytes in this movie Header atom; sethere to 0x0000006CType-A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to ' mhdVersion-A 1-byte specification of the version of this Movie Header atom; set here to 0x00Flags--Three bytes of space for future movie header flags set here to 0x000000Creation Time-A 32-bit integer that specifies the calendar date and time(in seconds sinceo 2012-2014 Cimarron Systems, LLC-all rights reservedElements of the H. 264 Video/ AAC Audio MP4 Moviemidnight, January 1 1904)when the movie atom was created in coordinated universal time(UTC) set here to'OXCCF85C09Modification Time-A 32-bit integer that specifies the calendar date and time (in seconds sincemidnight, January 1, 1904)when the movie atom was created in coordinated universal time(UTC); set here to ' OXCCF85C09Time Scale-A time value that indicates the time scale for this movie that is the number of timeunits that pass per second in its time coordinate system; set here to 0X000003E8Duration-A time value that indicates the duration of the movie in time scale units, derived fromthe movie's tracks, corresponding to the duration of the longest track in the movie; set here to"O×00057BC0Preferred Rate-A 32-bit fixed-point number that specifies the rate at which to play this movie(avalue of 1.0 indicates normal rate); set here to 0x00010000Preferred Volume-A 16-bit fixed-point number that specifies how loud to play this movies sound(a value of 1.0 indicates full volume); set here to 0x0100Reserved--Ten reserved bytes set to zeroMatrix-A transformation matrix that defines how to map points from one coordinate space intoanother coordinate space (please reference to the QuickTime File Format Specification for details)Predefines--Media Header predefines; set to zero (please refer to the Quick Time File FormatSpecification for details)Next track idthe number of the next track id set heTrack and Track header AtomsFigure 5 shows the structure of the ' trak and ' atomsa trak contains the following fieldsSize-A 32-bit unsigned integer that specifies the number of bytes in this first movie track atomset here to 0x00016408Type-A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to 'traka tkhd contains the following fieldsSize--A 32-bit unsigned integer that specifies the number of bytes in this first Movie Track Headeratom set here to 0x0000005Cype--A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to ' tkhd'Version-A 1-byte specification of the version of this first Movie Track Header atom; set here to0x00Flags--Three bytes specification of the version of this first Movie Track Header atom; set here to0x0000oF (please refer to the Quick Time File Format Specitication for details)Creation Time-A 32-bit integer that specifies the calendar date and time (in seconds sincemidnight, January 1, 1904)when the movie atom was created in coordinated universal time(UTC) set here to 'OXCCF85C09Modification Time-A 32-bit integer that specifies the calendar date and time (in seconds sincemidnight, January 1, 1904)when the movie atom was created in coordinated universal time(UTC); set here to ' OXCCF85C09Track ID-A 32-bit integer that uniquely identifies the track; the value o cannot be usedReserved--A 32-bit integer that is reserved; this field is set to 0X00000000Duration-A time value that indicates the duration of this track (in the movie s time coordinatesystem). Note that this property is derived from the track's edits: the value of this field is equal tothe sum of the durations of all of the track 's edits and that if there is no edit list, the duration is theo 2012-2014 Cimarron Systems, LLC-all rights reservedElements of the H. 264 Video/ AAC Audio MP4 Moviesum of the sample durations converted into the movie timescale; set here to 0x00057AFEsampleMovie m4vQ trakv trak- TrackBE164472616丽B5746B6864. dtrak∴tkhd16 BE 00 BE OF CC F8 5C 89 CC F8 5C 89 BE 00 00 aE0 05 TA FE OE EE F5 Ea E0 E0 0.…,z,…a962D000168460646961909021ma112 6D 64 68 64 00 00 00 0a CC F8 5C a9 CC F8 5C 09 mdhd..A-\A128正E的的2A17554的的m20…*.山…-0 out of 91144 bytestkhd- Track headerT Lags x]101E↑Lumme F,区durat ion 359166with128E日height 720.Ecreated Wednesday, december 19, 2012 11: 09: 13 PM Mountain Standard timeodif ied Wednesday, December 19, 2012 11: 09: 13 PM Mountain standardalternate group Ereserved (2)gmatr讠AxB9010195区 1FExB93E11H5ExEE61FB6Ex 6UF811BxFEE6FEEx4EFF188E2 resultFigure 5: MP4 Movie Container trak'andtkhd' StructuresReserved--An 8-byte value that is reserved; this field is set to oLayer-A 16-bit integer that indicates this tracks spatial priority in its movie(the QuickTimeovie Toolbox uses this value to determine how tracks over lay one another). tracks with lowerlayer values are displayed in front of tracks with higher layer valuesAlternative Group-A 16-bit integer that specifies a collection of movie tracks that containalternate data for one another: set here to 0x0000Volume-A 16-bit fixed-point value that indicates how loudly this track 's audio is to be played; avalue of 1. o indicates normal volumeReserved-A 1 6-bit integer that is reserved; this field is set to.Matrix Structure-The matrix structure associated with this track (please refer to the Quick TimeFile Format Specification for details)Track Width--A 32-bit fixed-point number that specifies the width of this track in pixels; set hereto"0x05000000Track Height-A 32-bit fixed-point number that specifies the height of this track in pixels; set hereto"Ox02D00000o 2012-2014 Cimarron Systems, LLC-all rights reservedElements of the H. 264 Video /AAC Audio MP4 MovieMovie media. movie media header. and media handler reference atomsFigure 6 shows the structure of the 'mdia, 'mdhd, and'hdir' atomsmdia contains the following fields:Size--A 32-bit unsigned integer that specifies the number of bytes in this first Movie Media atomset here to 0x000163A4Type-A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to 'mdiaa sample Movie. m4vQ mdiaindia- Media3B163A6D64696186626⑥D646064, cAndia,,mhd16 B0 08 00 a0 CC F8 5C 09 CC F8 5C B9 00 Be 0a 1E ..A\A-\32B8662A1755c4666666682D68646c?24的8丽6666D6672%6696465B86B866e4B8BBB8B5669646GF48616E∴,deodar646672616346D69∈E666666dler, COmint,,9614766D6864869888188688868hd12886882469666B8661647265ddin126686668B8姓1668scv726cfur Ldd n nn nn nn n nn nd c弓匚Ac刁 CR二LL0 out of 91044 bytesmchd- media headerversion gT LarJ66F61duration 1875edef inec区created Wednesday, December 19, 2012 11: 09: 13 PM Mountain Standard timemodified Wednesday, December 19, 2012 11: 09: 13 PM Mountain Standard TimiehdIr-Handler DescriptionEtaLonf Lags Ex66EE66predef ined mhlrhand ler type vidname VideoHandlereservedresultsFigure 6: MP4 Movie Container 'mdia, 'mdhd, and hdlr'Structuresmdhd contains the following fields:Size 32-bit ansithat specifies the number of bytes in this first movie mediaHeader atom set here to 0x00000020Type-A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to 'mdhdVersion-A 1-byte specification of the version of this first Movie Track Header atom; set here to0×00"Flags--Three bytes specification of the version of this first Movie Media Header atom; set here to0x000000(please refer to the Quick Time File Format Specification for details)Creation Time-A 32-bit integer that specifies the calendar date and time(in seconds sincemidnight, January 1, 1904)when the movie atom was created in coordinated universal time(UTC; set here to OXCCF85 C09Modification Time-A 32-bit integer that specifies the calendar date and time (in seconds sinceo 2012-2014 Cimarron Systems, LLC-all rights reservedElements of the H. 264 Video/ AAC Audio MP4 Moviemidnight, January 1 1904)when the movie atom was created in coordinated universal time(UTC) set here to ' C09Time scale-a time value that indicates the time scale for this media- that is, the number of timeunits that pass per second in its time coordinate system set here to 0x0000001E whichrepresents 30 tpsDuration--Duration of the media in Time Scale units; set here to 0X00002A17'which represents10, 775 frames (or 323, 250 seconds)Language-A 16-bit integer that specifies the language code for this media; set here to 0x55C4'Predefined-Set here to 0x0000hdir contains the following fieldsSize-A 32-bit unsigned integer that specifies the number of bytes in this first movie mediaHandler reference atom set here to 0x0000002D'ype--A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to 'hdlr'Version- A 1-byte specification of the version of this first Movie track header atom; set here to0x00Flags--Three bytes specification of the version of this first Movie Media Header atom; set here to0x0000oo'(please refer to the Quick Time file format Specification for details)Component Type-A four-character code that identifies the type of the handler(normally only twovalues are valid for this field: 'mhIr for media handlers and 'dhlr' for data handlers) set here to0×6D686C721Component Subtype-A four-character code that identifies the type of the media handler or datahandler. For media handlers, this field defines the type of data--for example, 'vide' for video dataor soun' for sound data. set here to 0x76696465Component Name-A (counted) string that specifies the name of the component; set here toVideo handlerMedia Information media Information Header, media data Information and media data reference atomsFigure 7 shows the structure of the 'minf, 'vmhd, 'dinf, and 'dref atomsminf contains the following fieldsSize-A 32-bit unsigned integer that specifies the number of bytes in this Video Media Informationatom set here to 0x0001634FIType-A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to 'minfvmhd contains the following fieldsSize A 32-bit unsigned integer that specifies the number of bytes in this video Media InformationHeader atom, set here to 0x00000014ype--A 32-bit unsigned integer that identifies the type, represented as a four-character code; thisfield must be set to ymhd'Version-A 1-byte specification of the version of this Video Media Information Header; set here to"O×00Flags--A 3-byte space for video media information flags; set here to 0x000001Graphics Mode-A 16-bit integer that specifies the transfer mode; set here to '00000Opcolor--Three 16-bit values that specify the red, green, and blue colors for the transfer modeoperation indicated in the graphics mode field; all set here to 0X0000dinf contains the following fieldsSize--A 32-bit unsigned integer that specifies the number of bytes in this video media datao 2012-2014 Cimarron Systems, LLC-all rights reserved
上传资源
用户评论