«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

VIDEOCUBE

[MP4] 분석 하기 | MPEG-4 파트 14 | MP4Box 설치 본문

분석

[MP4] 분석 하기 | MPEG-4 파트 14 | MP4Box 설치

라떼청년 2017. 11. 26. 21:50


Wiki 에 따르면

MP4 는 공식적으로 ISO/IEC 14496-14:2003 MPEG-4의 일부 규정된 멀티미디어 컨테이너 포맷이다.

ㄴ 디지털 비디오, 디지털 오디오 스트림을 저장 하기 위해서 사용함

ㄴ 자막, 스틸 이미지 따위의 기타 데이터 저장

ㄴ 인터넷을 통한 스트리밍 지원

스트리밍 정보 > hint track 이 존재

ㄴ 확장명 ( .mp4 )


압축된 영상의 데이터를 감싸 장치로 부터 압축된 영상의 정보를 가지고 재생을 할 수 있도록 그 정보를 담고 있다

해당 영상의 정보를 분석하여 압축된 영상 데이터를 FLV, TS 등으로 변환도 가능하다.


많은 비디어 영상 재생 기술 방식을 보면, 보통은 지원되는 포맷이 아닙니다. 라든지와 같은 .. 오류 정보를 볼 수 있다.

해당 기기에서 압축방식에 따라 재생이 지원이 되지 않는 경우도 있지만, 컨테이너만 가지고도 재생이 안되는 경우가 대부분이다.


하드웨어에서 영상의 압축 방식에 대한 디코딩만 지원이 된다면, 포맷의 구조는 그다지 중요한 문제가 되지 않을 수 있다.

최근에는 대부분의 기기에서 HLS 등의 재생이 지원이 되지만 기존에는 해당 기능은 Apple 의 산물이었다.

HLS 에서 지원이 되지 않는 기기에서도 M3U8 의 포맷 TS 분석 및 구조만을 가지고 

재생을 가능케 하는 플레이어들이 속속히 등장한다. 


해당기기의 영상압축 데이터를 이용하여 재생할 수 있음에도 컨테이너에 따라 재생이 되지 않는 다면, 해당 기기에서 

재생을 할 수 있도록 구현을 해야 한다면, 해당 영상의 컨테어니를 통해 Demuxing 을 이해 하는 것이 좋지 않을 까 한다.


물론 FFMPEG 등 많은 Open source 들이 이 기능들을 지원함에도 많은 개발자들은 자신만의 분석 기술을 이용하여, 영상 포맷을 

자유롭게 이동하는 라이브러리를 구현 개발하고 있다. 

압축 데이터만 가지고 많은 포맷으로 넘나 들수 있다면 이 또한 재미있지 않을까?


여기서는 대중적으로 많은 기기에서 지원되어지는 Mp4의 포맷에 대한 

ㄴ ATOM 헤더의 분석 

==>  Python 을 이용해 보는 것까지만 진행해 보도록 한다.


우선 일반적인 mp4 를 준비한다.

mp4 의 헤더는 앞 혹은 뒤에 존재 할 수 있는데, 앞에 있는 영상을 선택해 보았다.


vi {파일명}.mp4


이상한 문제열이 나열이 된다

HEX 코드로 변경

:%!xxd 


다시 바이너리 상태로 돌린다

:%!xxd -r

위 영상을 보면 첫번째 라인에 mdat 라는 문구가 보인다. 이 경우 헤더는 뒤에 있는 영상으로 파악이 된다.


mp4 파일 시스템 기본구조는 다음과 같다

Movie (moov) : meta data 시작

ㄴ Movie Header ( mvhd ) : movie 정보

ㄴ Object Descrptor (iods) : IOD

ㄴ Track ( track ) : 트랙 시작

ㄴ  Track Header (tkhd) : 트랙 헤더

ㄴ Track Reference  (tref) : 트랙 메타 처리시 참조할 트랙

Media (mdia) : 미디어 시작

ㄴMedia Header (mdhd) : 미디어와 관련한 일반적 내용

ㄴHandler (hdlr) : 미디어 타입

ㄴMedia Information (minf) : 미디어 정보, 샘플 데이터를 얻기 위한 정보

ㄴ Media Information Header (vmhd) : 미디어 타입

ㄴ Data Information (dinf) : 데이터 정보, 샘플 데이터의 위치를 얻기 위한 정보

ㄴ Data Reference (dref) : 파일 내의 존재 여부 및 파일명

ㄴSample Table (stbl) : 샘플 테이블

ㄴ Time To Sample (stts) : 샘플의 시간 정보

ㄴ Sample Description (stsd) : 샘플 디코딩을 위한 정보

ㄴ ES Description (esds) : h.263 es descriptor

ㄴ AVC Configuration Box(avcC)

ㄴ MPEG4 Extension Descriptor Box

ㄴ Sample Size (stsz)

ㄴ Sample To Chunk (stsc)

ㄴ Chunk Offset (stco)

ㄴ Sync Sample (stbl)

ㄴ Track

ㄴ Track ..

Media Data (mdat)


위와 같은 구조적으로 보았을 경우 해당 파일은 앞에 mdat가 있기 때문에 헤더는 뒤에 존재하는 것으로 보인다.

보통은 이런 경우 해당 파일은 인코딩을 통한 얻어지는 파일에 얻는 경우가 다수이다.


OFFLine 인 경우 위 영상은 재생이 가능하지만 Web 을 통한 Streaming 서비스를 하는 경우에는

이는 버퍼링이 심하게 걸리거나 또는 재생이 되지 않을 수 있다.


이 경우는 MP4Box hint 를 이용하여  Hint Track 을 만들어 헤더를 앞으로 이동시켜 줘야 한다.

헤더 정보를 읽기 위해 모든 데이터를 다 받아야 하기 때문이지 않을까..


물론 분석하려고 해도 .. 파일의 마지막에 있기 때문에 mdat 를 전부 읽어야 한다.


Mp4Box 를 설치해 보자

git clone https://github.com/gpac/gpac


git branch -a


* master

  remotes/origin/HEAD -> origin/master

  remotes/origin/buildbot-cachedir

  remotes/origin/buildbot-dashsrd

  remotes/origin/buildbot-idatparsing

  remotes/origin/buildbot-play-faad2

  remotes/origin/buildbot-ssl11

  remotes/origin/buildbot-winmb

  remotes/origin/dash_relax_ar_in_as

  remotes/origin/edit_list_timescale

  remotes/origin/master

  remotes/origin/mmt

  remotes/origin/mux2mem

  remotes/origin/openssl-1.1

  remotes/origin/vladimir-kazakov-dash-if-iop-profiles


./configure

error: zlib not found on system or in local libs


에러 발생 시 ...


yum install zlib*



빌드

root@linux-01:/data/source/gpac> make all



배포


root@linux-01:/data/source/gpac> make install

install -d "/usr/local"

install -d "/usr/local/lib"

install -d "/usr/local/bin"

if [ -f bin/gcc/MP4Box ] ; then \

install  -m 755 bin/gcc/MP4Box "/usr/local/bin" ; \

fi

if [ -f bin/gcc/MP42TS ] ; then \

install  -m 755 bin/gcc/MP42TS "/usr/local/bin" ; \

fi

if [ -f bin/gcc/MP4Client ] ; then \

install  -m 755 bin/gcc/MP4Client "/usr/local/bin" ; \

fi

if [ -d /usr/local/lib/pkgconfig ] ; then \

install  -m 644 gpac.pc "/usr/local/lib/pkgconfig" ; \

fi

install -d "/usr/local/lib/gpac"

install bin/gcc/*.so "/usr/local/lib/gpac"

rm -f /usr/local/lib/gpac/libgpac.so

rm -f /usr/local/lib/gpac/nposmozilla.so

make installdylib

make[1]: Entering directory `/data/source/gpac'

install  -m 755 bin/gcc/libgpac.so.7.6.0 /usr/local/lib/libgpac.so.7.6.0

ln -sf libgpac.so.7.6.0 /usr/local/lib/libgpac.so.7

ln -sf libgpac.so.7.6.0 /usr/local/lib/libgpac.so

ldconfig || true

make[1]: Leaving directory `/data/source/gpac'

install -d "/usr/local/man"

install -d "/usr/local/man/man1"

install  -m 644 /data/source/gpac/doc/man/mp4box.1 /usr/local/man/man1/ 

install  -m 644 /data/source/gpac/doc/man/mp4client.1 /usr/local/man/man1/ 

install  -m 644 /data/source/gpac/doc/man/gpac.1 /usr/local/man/man1/

install -d "/usr/local/share/gpac"

install  -m 644 /data/source/gpac/doc/gpac.mp4 /usr/local/share/gpac/  

install -d "/usr/local/share/gpac/gui"

install  -m 644 /data/source/gpac/gui/gui.bt "/usr/local/share/gpac/gui/" 

install  -m 644 /data/source/gpac/gui/gui.js "/usr/local/share/gpac/gui/" 

install  -m 644 /data/source/gpac/gui/gwlib.js "/usr/local/share/gpac/gui/" 

install  -m 644 /data/source/gpac/gui/mpegu-core.js "/usr/local/share/gpac/gui/"

install  -m 644 /data/source/gpac/gui/webvtt-renderer.js "/usr/local/share/gpac/gui/"

install -d "/usr/local/share/gpac/gui/icons"

install -d "/usr/local/share/gpac/gui/extensions"

install -d "/usr/local/share/gpac/shaders/"

install -d "/usr/local/include"

cp --no-preserve=mode,ownership,timestamp /data/source/gpac/gui/icons/* /usr/local/share/gpac/gui/icons/

cp -R --no-preserve=mode,ownership,timestamp /data/source/gpac/gui/extensions/* /usr/local/share/gpac/gui/extensions/

cp --no-preserve=mode,ownership,timestamp /data/source/gpac/shaders/* /usr/local/share/gpac/shaders/

cp -R --no-preserve=mode,ownership,timestamp /data/source/gpac/include/* /usr/local/include/



실행


root@linux-01:/data/source/gpac> MP4Box

MP4Box: error while loading shared libraries: libgpac.so.7: cannot open shared object file: No such file or directory




에러 발생 > 라이브러리가 로드되지 않았다


install  -m 755 bin/gcc/libgpac.so.7.6.0 /usr/local/lib/libgpac.so.7.6.0

ln -sf libgpac.so.7.6.0 /usr/local/lib/libgpac.so.7

ln -sf libgpac.so.7.6.0 /usr/local/lib/libgpac.so



cd /etc/ld.so.conf.d/


-r--r--r--. 1 root root 324 2012-06-22 21:45 kernel-2.6.32-279.el6.x86_64.conf

-rw-r--r--. 1 root root  17 2012-06-22 21:58 mysql-x86_64.conf




echo "/usr/local/lib" > /etc/ld.so.conf.d/local-lib.conf


root@linux-01:/etc/ld.so.conf.d> ldconfig



root@linux-01:/etc/ld.so.conf.d> ldconfig -v

/usr/local/lib:

libgpac.so.7 -> libgpac.so.7.6.0



root@linux-01:/etc/ld.so.conf.d> MP4Box 


MP4Box [option] input [option]

 -h general           general options help

 -h hint              hinting options help

 -h dash              DASH segmenter help

 -h import            import options help

 -h encode            encode options help

 -h meta              meta handling options help

 -h extract           extraction options help

 -h dump              dump options help

 -h swf               Flash (SWF) options help

 -h crypt             ISMA E&A options help

 -h format            supported formats help

 -h rtp               file streamer help

 -h live              BIFS streamer help

 -h all               all options are printed


 -nodes               lists supported MPEG4 nodes

 -node NodeName       gets MPEG4 node syntax and QP info

 -xnodes              lists supported X3D nodes

 -xnode NodeName      gets X3D node syntax

 -snodes              lists supported SVG nodes

 -languages           lists supported ISO 639 languages

 -boxes               lists all supported ISOBMF boxes and their syntax


 -quiet                quiet mode

 -noprog               disables progress

 -v                   verbose mode

 -logs                set log tools and levels, formatted as a ':'-separated list of toolX[:toolZ]@levelX

 -log-file FILE       sets output log file. Also works with -lf FILE

 -log-clock or -lc    logs time in micro sec since start time of GPAC before each log line.

 -log-utc or -lu      logs UTC time in ms before each log line.

 -version             gets build version

 -- INPUT             escape option if INPUT starts with - character




root@linux-01:/data/source/mp4parser> MP4Box -hint {파일명}.mp4


Hinting file with Path-MTU 1450 Bytes

Hinting track ID 1 - Type "mp4v:mp4v" (MP4V-ES) - BW 1006 kbps

Hinting track ID 2 - Type "mp4a:mp4a" (MPA) - BW 64 kbps

Saving {파일명}.mp4: 0.500 secs Interleaving



vi {파일명}.mp4




:%!xxd



0000000: 0000 0014 6674 7970 6973 6f6d 0000 0200  ....ftypisom....

0000010: 6d70 3431 0000 452c 6d6f 6f76 0000 006c  mp41..E,moov...l

0000020: 6d76 6864 0000 0000 7c25 b080 7c25 b080  mvhd....|%..|%..

0000030: 0000 03e8 0000 50d0 0001 0000 0100 0000  ......P.........

0000040: 0000 0000 0000 0000 0001 0000 0000 0000  ................

0000050: 0000 0000 0000 0000 0001 0000 0000 0000  ................

0000060: 0000 0000 0000 0000 4000 0000 0000 0000  ........@.......

0000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................

0000080: 0000 0000 0001 0002 0000 16ee 7472 616b  ............trak

0000090: 0000 005c 746b 6864 0000 000f 7c25 b080  ...\tkhd....|%..

00000a0: d640 90bc 0000 0001 0000 0000 0000 4df7  .@............M.

00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................

00000c0: 0001 0000 0000 0000 0000 0000 0000 0000  ................

00000d0: 0001 0000 0000 0000 0000 0000 0000 0000  ................

00000e0: 4000 0000 0140 0000 00f0 0000 0000 168a  @....@..........

00000f0: 6d64 6961 0000 0020 6d64 6864 0000 0000  mdia... mdhd....

0000100: 7c25 b080 7c25 b080 0000 7931 0009 72dc  |%..|%....y1..r.

0000110: 55c4 0000 0000 002d 6864 6c72 0000 0000  U......-hdlr....

0000120: 0000 0000 7669 6465 0000 0000 0000 0000  ....vide........

0000130: 0000 0000 5669 6465 6f48 616e 646c 6572  ....VideoHandler

0000140: 0000 0016 356d 696e 6600 0000 1476 6d68  ....5minf....vmh

0000150: 6400 0000 0100 0000 0000 0000 0000 0000  d...............

0000160: 2464 696e 6600 0000 1c64 7265 6600 0000  $dinf....dref...

0000170: 0000 0000 0100 0000 0c75 726c 2000 0000  .........url ...

0000180: 0100 0015 f573 7462 6c00 0000 b973 7473  .....stbl....sts

0000190: 6400 0000 0000 0000 0100 0000 a96d 7034  d............mp4

00001a0: 7600 0000 0000 0000 0100 0000 0000 0000  v...............

00001b0: 0000 0000 0000 0000 0001 4000 f000 4800  ..........@...H.

00001c0: 0000 4800 0000 0000 0000 0100 0000 0000  ..H.............

00001d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................

00001e0: 0000 0000 0000 0000 0000 0000 18ff ff00  ................

00001f0: 0000 5365 7364 7300 0000 0003 4500 0100  ..Sesds.....E...

0000200: 043d 2011 0000 0000 2625 a000 0000 0005  .= .....&%......

0000210: 2e00 0001 b001 0000 01b5 8913 0000 0100  ................

0000220: 0000 0120 00c4 8d8b c98d 0a04 1e14 6300  ... ..........c.

0000230: 0001 b24c 6176 6335 322e 3130 382e 3006  ...Lavc52.108.0.

0000240: 0102 0000 0a88 7374 7473 0000 0000 0000  ......stts......

0000250: 014f 0000 0001 0000 04f8 0000 0002 0000  .O..............

0000260: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

0000270: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

0000280: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

0000290: 0517 0000 0001 0000 04f9 0000 0002 0000  ................

00002a0: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

00002b0: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

00002c0: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

00002d0: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

00002e0: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

00002f0: 0517 0000 0001 0000 04f8 0000 0002 0000  ................

0000300: 0517 0000 0001 0000 04f8 0000 0001 0000  ................

0000310: 0517 0000 0001 0000 0518 0000 0001 0000  ................

0000320: 04f8 0000 0002 0000 0517 0000 0001 0000  ................

0000330: 04f8 0000 0002 0000 0517 0000 0001 0000  ................

0000340: 04f8 0000 0002 0000 0517 0000 0001 0000  ................

0000350: 04f8 0000 0002 0000 0517 0000 0001 0000  ................

0000360: 04f8 0000 0002 0000 0517 0000 0001 0000  ................

0000370: 04f8 0000 0002 0000 0517 0000 0001 0000  ................

0000380: 04f8 0000 0002 0000 0517 0000 0001 0000  ................



앞으로 이동 되어 있는 것을 볼 수 있다. 


단, 주의 할 점은 %!xxd 한 후에 저장하면 안된다.


root@linux-01:/data/source/mp4parser> file R.mp4

R.mp4: ASCII text


만약 수정하고 저장하고 싶으면 %!xxd -r 을 꼭 하고 저장해야 한다.

파일이 깨졌다고 원망하지 말고 반드시 저장한다면 바이너리로 전환후 전환 해야 한다.


root@linux-01:/data/source/mp4parser> file Robotica.mp4 

Robotica.mp4: ISO Media, MPEG v4 system, version 1




Python 을 이용하여 

> 각 파트로 데이터 형태를 분석된 내용을 나열해 보자.

file : mp4parser.py 를 생성한다


vi mp4parser.py 


#!/usr/bin/env python

#coding : utf-8



import sys

import time

from io import BytesIO


def main(argv):

        FH = open('Robotica.mp4', 'rb')


        size = 4

        s = FH.read(size)                    //헤더 길이 [ 4 byte ]

        l = int(s.encode('hex'), 16)         //4Byte 16진수를 > 10 진수로 변환 사이즈를 구한다.


        while True:

                s = FH.read(l-size)

                head = s[:4].decode('utf-8')


                print '##################################'

                print 'Total %s : %d' % (head, l)

                s = FH.read(size)

                if s == '': break

                l = int(s[:4].encode('hex'), 16)


        FH.close()


if __name__ == '__main__':

        main(sys.argv[1:])


root@linux-01:/data/source/mp4parser> ./mp4parser.py 


##################################

Total ftyp : 20

##################################

Total moov : 17708                    >> 이 부분을 분석한다

##################################

Total mdat : 2771337

##################################

Total free : 8

##################################

Total free : 76




 Size

 32Bits

 Size 정보 ( 4byte )

 Type

 32Bits

 Type 정보 ( 4byte)



Movie Atom : moov

ㄴMovie (moov) : meta data 시작

 Size

32Bits 

Movie Atom Size 

 Type

32Bits 

"moov" 


Movie Header Atom : mvhd

ㄴ Movie Header ( mvhd ) : movie 정보

 Size

32Bits 

Movie Header Atom의 사이즈

 Type

32bits

"mvhd"

 Version

8bits

Movie Header Atom 의 버전

1: 64bits 0: 32: bits ( 시간 )

 Flags

24bits

0

 Creation-time

64bits | 32Bits

File이 만들어진 시간

 Modification-time

64bits | 32bits

File이 수정된 시간

 Timescale

64bits | 32bits

File의 timescale

 Duration

64bits | 32bits

File의 Play시간 (timescale 기준)

 Reserved

32bits

0x00010000

 Reserved

16bits

0x0100

 Reserved

16bits

0

 Reserved

32bits * 2

0

 Reserved

32bits * 9

0x00010000, 0, 0, 0, 0, 0x00010000, 0, 0, 0, 0x4000000

 Reserved

32bits * 6

0

 Next-track-ID

32bits

사용가능한 다음 track-ID 번호


ObjectDescriptor  : iods

ㄴ Object Descrptor (iods) : IOD

Size 

 32bits

IOD Atom의 사이즈

Type

 32bits

"iods"

Version

 8bits

0

Flag

 24bits

0

ObjectDescriptor

 Variable

 Initial Object Descriptor


Tag

8bits

0x10

Length

32bits

0x80808019

ObjectDescriptorID

10bits

1

URL_Flag

1bit 

0

IncludeInlineProfile

LevelFlag

1bit

0

Reserved

4bits

0xF

ODProfile

LevelIndication

8bits

0xFF

SceneProfile

LevelIndication

8bits

0xFF

AudioProfile

LevelIndication

8bits 

0x01

VisualProfile

LevelIndication

8bits 

0x03

GraphicsProfile

LevelIndication

8bits 

0xFF

Tag

8bits

0x0E

Length

32bits

0x80808004

ES_ID

32bits 

0D 혹은 BIFS Track의 ID

Tag

8bits

0x0E

Length

32bits

0x80808004

ES_ID

32bits

0D 혹은 BIFS Track의 ID


Video Track : track

ㄴ Track ( track ) : 트랙 시작

Size 

32bits 

Track Atom 의 size

Type

32bits

"trak"


Track Header Atom : tkhd

ㄴ  Track Header (tkhd) : 트랙 헤더

Size

32bits

Track Header Atom의 사이즈

Type

32bits

"tkhd"

Version

8bits

Track Header Atom의 버전

1: 64bits, 0: 32bits (시간)

Flags

24bits

0x000001

Creation-time

64bits | 32bits

Track이 만들어진 시간

Modification-time

64bits | 32bits

Track이 수정된 시간

Track-ID

32bits

Track의 ID값

Reserved

32bits

0

Duration

32bits

Track의 play 시간 (movie timescale 기준)

Reserved

32bits * 3

0

Reserved

16bits

0

Reserved

16bits

0

Reserved

32bits * 9

0x00010000, 0, 0, 0, 0x00010000, 0, 0, 0,

0x40000000

Reserved

32bits

 0x01400000

Reserved

32bits

 0x00F00000



- Track Reference  (tref) : 트랙 메타 처리시 참조할 트랙

Track Reference Atoms

Track reference atoms define relationships between tracks. Track reference atoms allow one track to specify how it is related to other tracks. For example, if a movie has three video tracks and three sound tracks, track references allow you to identify the related sound and video tracks. Track reference atoms have an atom type value of 'tref'.

Track references are unidirectional and point from the recipient track to the source track. For example, a video track may reference a time code track to indicate where its time code is stored, but the time code track would not reference the video track. The time code track is the source of time information for the video track.

A single track may reference multiple tracks. For example, a video track could reference a sound track to indicate that the two are synchronized and a time code track to indicate where its time code is stored.

A single track may also be referenced by multiple tracks. For example, both a sound and video track could reference the same time code track if they share the same timing information.

If this atom is not present, the track is not referencing any other track in any way. Note that the array of track reference type atoms is sized to fill the track reference atom. Track references with a reference index of 0 are permitted. This indicates no reference.

For more information about Track References, see Track References.

Figure 2-18 shows the layout of a track reference atom.

Figure 2-18  The layout of a track reference atom
The layout of a track reference atom

A track reference atom contains the following data elements.

Size

A 32-bit integer that specifies the number of bytes in this track reference atom.

Type

A 32-bit integer that identifies the atom type; this field must be set to 'tref'.

Track reference type atoms

A list of track reference type atoms containing the track reference information. These atoms are described next.

Each track reference atom defines relationships with tracks of a specific type. The reference type implies a track type. Table 2-2 shows the track reference types and their descriptions.

Table 2-2  Track reference types

Reference type

Description

'cdsc'

The track reference is contained in a timed metadata track (see Timed Metadata Media for more detail) and provides links to the tracks for which it contains descriptive characteristics.

Note: If the timed metadata track describes characteristics of the entire movie, there will be no track reference of type ‘cdsc’ between it and another track.

'chap'

Chapter or scene list. Usually references a text track.

'clcp'

Closed caption. In any track, this identifies a closed captioning track that contains text that is appropriate for the referring track. See Closed Captioning Media for more information.

'fall'

In a sound track, this references a track in a different format but with identical content, if one exists; for example, an AC3 track might reference an AAC track with identical content. See Alternate Sound Tracks.

'folw'

In a sound track, this references a subtitle track that is to be used as the sound track’s default subtitle track. If the subtitle track is part of a subtitle track pair, this should reference the the forced subtitle track of the pair. This is needed only if language tagging cannot be used. See Relationships Across Alternate Groups.

'forc'

Forced subtitle track. In the regular track of a subtitle track pair, this references the forced track. See Subtitle Sample Data for more information.

'hint'

The referenced tracks contain the original media for this hint track.

'scpt'

Transcript. Usually references a text track.

'ssrc'

Non-primary source. Indicates that the referenced track should send its data to this track, rather than presenting it. The referencing track will use the data to modify how it presents its data. See Track Input Map Atoms for more information.

'sync'

Synchronization. Usually between a video and sound track. Indicates that the two tracks are synchronized. The reference can be from either track to the other, or there may be two references.

'tmcd'

Time code. Usually references a time code track.

Each track reference type atom contains the following data elements.

Size

A 32-bit integer that specifies the number of bytes in this track reference type atom.

Type

A 32-bit integer that identifies the atom type; this field must be set to one of the values shown in Table 2-2.

Track IDs

A list of track ID values (32-bit integers) specifying the related tracks. Note that this is one case where track ID values can be set to 0. Unused entries in the atom may have a track ID value of 0. Setting the track ID to 0 may be more convenient than deleting the reference.

You can determine the number of track references stored in a track reference type atom by subtracting its header size from its overall size and then dividing by the size, in bytes, of a track ID.



Media Atom : mdia

ㄴ Media (mdia) : 미디어 시작

Size 

32bits

Media Atom의 사이즈

Type

32bits

"mdia"


Media Header Atom : mdhd

ㄴMedia Header (mdhd) : 미디어와 관련한 일반적 내용

Size 

32bits

Media Header Atom의 사이즈

Type

32bits

"mdhd"

Version

8bits

Track Header Atom의 version

1: 64bits 0: 32: bits ( 시간 )

Flags

24bits

0

Creation-time

64bits | 32bits

Media가 만들어진 시간

Modification-time

64bits | 32bits

Media가 수정된 시간

Timescale

64bits | 32bits

Media의 timescale

Duration

64bits | 32bits

Media의  play 시간 (media timescale 기준)

Pad

1bit

0

language

5bits * 3

packed ISO-639-2/T language code

reserved

16bits

0


Handler Atom : hdlr

ㄴHandler (hdlr) : 미디어 타입

Size

32bits

Handler Atom의 사이즈

Type

32bits

"hdlr"

Version

8bits

0

Flags

24bits

0

Reserved

32bits

0

Handler-type

32bits

"vide"

Reserved

8bits * 12

0

String

var

"vide"


Media Information Atom : minf

ㄴMedia Information (minf) : 미디어 정보, 샘플 데이터를 얻기 위한 정보

Size 

32bits

Media Information Atom의 사이즈

Type

32bits

"minf"


Media Information Header Atom : vmhd

ㄴ Media Information Header (vmhd) : 미디어 타입

Size 

32bits

Media Information Header Atom의 사이즈

Type

32bits

"vmhd"

Version

8bits

0

Flags

24bits

1

Reserved

64bits

0


Data Information Atom : dinf

ㄴ Data Information (dinf) : 데이터 정보, 샘플 데이터의 위치를 얻기 위한 정보

Size

32bits

Data Information Atom의 사이즈

Type

32bits

"dinf"


Data Reference Atom : dref

ㄴ Data Reference (dref) : 파일 내의 존재 여부 및 파일명

Size 

32bits

Data Reference Atom의 사이즈

Type

32bits

"dref"

Version

8bits

0

Flags

24bits

0

Entry-count

32bits

1

Size

32bits

Data Entry Atom의 사이즈

Type

32bits

"url"

Version

8bits

0

Flags

24bits

0x000001


Sample Table Atom : stbl

ㄴSample Table (stbl) : 샘플 테이블

Size 

32bits

Sample Table Atom의 사이즈

Type

32bits

"stbl"


Time To Sampe Atom : stts

ㄴ Time To Sample (stts) : 샘플의 시간 정보

Size

32bits

Time To Sample Atom의 사이즈

Type

32bits

"stts"

Version

8bits

0

Flags

24bits

0

Entry-count

32bits

Sample-count와 Sample-delta pair의 전체 개수

Sample-count

32bits

같은 delta값을 가지는 연속된 sample 개수

Sample-delta

32bits

Sample의 duration (media timescale 기준)

<계속>

Sample-count

32bits

같은 delta값을 가지는 연속된 sample 개수

Sample-delta

32bits

Sample의 duration (media timescale 기준)


Sample Description Atom : stsd

ㄴ Sample Description (stsd) : 샘플 디코딩을 위한 정보

Size 

 32bits

Sample Description Atom의 사이즈

Type

 32bits

"stsd"

Version

 8bits

0

Flag

 24bits

0

Entry-count

32bits 

1

Size

32bits 

Sample Entry Atom의 사이즈

Type

 32bits

"mp4v"

Reserved

 8bits * 6

0

Data-reference-index

16bits

1

Reserved

32bits * 4

0

Reserved

32bits

0x014000F0

Reserved

32bits

0x00480000

Reserved

32bits

0x00480000

Reserved

32bits

0

Reserved

16bits

1

Reserved

8bits * 32

0

Reserved

16bits

24

Reserved

16bits

-1

ESDAtom

Variable

ES Descriptor


- ES Description (esds) : h.263 es descriptor [ 생략 ]

- AVC Configuration Box(avcC) [ 생략 ]

- MPEG4 Extension Descriptor Box [ 생략 ]


Sample Size Atom : stsz

ㄴ Sample Size (stsz)

Size

32bits

Sample Size Atom의 size

Type

32bits

"stsz"

Version

8bits

0

Flags

24bits

0

Sample-size

32bits

0

Sample-count

32bits

전체 Sample의 개수

Entry-size

32bits

첫번째 Sample의 size

<계속>

Entry-size

32bits

마지막 Sample의 size


Sampe To Chunk Atom : stsc

ㄴ Sample To Chunk (stsc)

Size

32bits

Sample To Chunk Atom의 사이즈

Type

32bits

"stsc"

Version

8bits

0

Flags

24bits

0

Entry-count

32bits

first-chunk, sample-per-chunk, sample-description-index의 전체 개수

First-chunk

32bits

Chunk당 sample개수와 sample description index가 같은 연속된 chunk중 첫번째 chunk의 index

Sample-per-chunk

32bits

Chunk당 sample의 개수

Sample-description-index

32bits

1

<계속>

First-chunk

32bits

Chunk당 sample개수와 sample description index가 같은 연속된 chunk중 첫번째 chunk의 index

Sample-per-chunk

32bits

Chunk당 sample의 개수

Sample-description-index

32bits

1


Chunk Offset Atom : stco

ㄴ Chunk Offset (stco)

Size 

32bits

Chunk Offset Atom의 size

Type

32bits

"stco"

Version

8bits

0

Flags

24bits

0

Entry-count

32bits

전체 Chunk의 개수

Chunk-offset

32bits

File의 처음으로 부터 첫번째 chunk까지의 offset

<계속>

Chunk-offset

32bits

File의 처음으로 부터 첫번째 chunk까지의 offset


Sample Table Atom : stbl

ㄴ Sync Sample (stbl)

Size 

32bits

Sample Table Atom의 사이즈

Type

32bits

"stbl"


Track은 Video 외 Audio 의 정보로 구성이 되어 있다.

Track 안에는 Sample 의 정보가 있고, Sample 내에는 Data 의 Offset 위치 정보를 포함하고 있다.

Sample 의 정보를 참조로 mdat에서 데이터를 추출하면 압축된 영상을 뽑아낼 수 있다.


다음 블로그 에서 샘플 정보를 뽑아보도록 할 예정이다. ( 곧 Open 예정 현재 작성 중 )

[MP4] 파일 미디어 샘플과 시간 정보를 구하는 방법

출처: http://videocube.tistory.com/entry/MPEG4-파일-시스템의-미디어-샘플과-시간-정보를-구하는-방법 [VIDEOCUBE]




반응형
Comments