必威体育Betway必威体育官网
当前位置:首页 > IT技术

3GP文件格式分析

时间:2019-07-10 17:41:17来源:IT技术作者:seo实验室小编阅读:70次「手机版」
 

3gp格式

原文地址  http://blog.csdn.net/dinggo/archive/2007/12/29/2003425.aspx

1.      概述

现在很多智能手机都支持多媒体功能,特别是音频和视频播放功能,而3GP文件格式是手机端普遍支持的视频文件格式。

目前很多手机都支持h263视频编码格式的视频文件播放,还有些手机支持h264。音频文件格式普遍支持amr,有些手机还支持AAC音频格式。

鉴于凤凰卫视节目主要以新闻类为主,音频压缩采用AMR标准,视频压缩采用H263和H264标准。

编号

文件名

文件长度

时长

1

news_h263.3gp

1.38MB

01:21.90

2

zbc1217_h263.3gp

1.92MB

02:37.98

3

zbc1217_h264.3gp

2.44MB

02:37.98

2. 3GP文件结构分析示例

AtomicParsley是一个开源的多媒体文件结构分析器。

下面是用该程序分析的两个3GP文件结构:

news_h263.3gp

Atom ftyp @ 0 of size: 28, ends @ 28

Atom mdat @ 28 of size: 65, ends @ 93

Atom mdat @ 93 of size: 130856, ends @ 130949

Atom mdat @ 130949 of size: 1312119, ends @ 1443068

Atom moov @ 1443068 of size: 7136, ends @ 1450204

Atom mvhd @ 1443076 of size: 108, ends @ 1443184

Atom trak @ 1443184 of size: 1546, ends @ 1444730

Atom tkhd @ 1443192 of size: 92, ends @ 1443284

Atom udta @ 1443284 of size: 48, ends @ 1443332

Atom uuid=484d496e-6354-7261-636b-496e666f2020 @ 1443292 of size: 40, ends @ 1443332

Atom mdia @ 1443332 of size: 1398, ends @ 1444730

Atom mdhd @ 1443340 of size: 32, ends @ 1443372

Atom hdlr @ 1443372 of size: 37, ends @ 1443409

Atom minf @ 1443409 of size: 1321, ends @ 1444730

    Atom smhd @ 1443417 of size: 16, ends @ 1443433

    Atom dinf @ 1443433 of size: 36, ends @ 1443469

        Atom dref @ 1443441 of size: 28, ends @ 1443469

    Atom stbl @ 1443469 of size: 1261, ends @ 1444730

        Atom stts @ 1443477 of size: 24, ends @ 1443501

        Atom stsd @ 1443501 of size: 69, ends @ 1443570

            Atom samr @ 1443517 of size: 53, ends @ 1443570

                Atom damr @ 1443553 of size: 17, ends @ 1443570

        Atom stsz @ 1443570 of size: 1112, ends @ 1444682

        Atom stsc @ 1444682 of size: 28, ends @ 1444710

                Atom stco @ 1444710 of size: 20, ends @ 1444730

Atom trak @ 1444730 of size: 5474, ends @ 1450204

Atom tkhd @ 1444738 of size: 92, ends @ 1444830

Atom tref @ 1444830 of size: 20, ends @ 1444850

Atom sync @ 1444838 of size: 12, ends @ 1444850

Atom udta @ 1444850 of size: 48, ends @ 1444898

Atom uuid=484d496e-6354-7261-636b-496e666f2020 @ 1444858 of size: 40, ends @ 1444898

Atom mdia @ 1444898 of size: 5306, ends @ 1450204

        Atom mdhd @ 1444906 of size: 32, ends @ 1444938

Atom hdlr @ 1444938 of size: 37, ends @ 1444975

Atom minf @ 1444975 of size: 5229, ends @ 1450204

    Atom vmhd @ 1444983 of size: 20, ends @ 1445003

    Atom dinf @ 1445003 of size: 36, ends @ 1445039

        Atom dref @ 1445011 of size: 28, ends @ 1445039

    Atom stbl @ 1445039 of size: 5165, ends @ 1450204

        Atom stts @ 1445047 of size: 24, ends @ 1445071

        Atom stsd @ 1445071 of size: 117, ends @ 1445188

            Atom s263 @ 1445087 of size: 101, ends @ 1445188

                Atom d263 @ 1445173 of size: 15, ends @ 1445188

        Atom stsz @ 1445188 of size: 4920, ends @ 1450108

        Atom stss @ 1450108 of size: 48, ends @ 1450156

        Atom stsc @ 1450156 of size: 28, ends @ 1450184

        Atom stco @ 1450184 of size: 20, ends @ 1450204

------------------------------------------------------

Total size: 1450204 bytes; 46 atoms total. AtomicParsley version: 0.9.0 (utf16)

Media data: 1442975 bytes; 7229 bytes all other atoms (0.498% atom overhead).

Total free atom space: 0 bytes; 0.000% waste.

------------------------------------------------------

Movie duration: 81.900 seconds (01:21.90) - 140.95* kbp/sec bitrate (*=APProximate)

Low-level details. Total tracks: 2

Trk Type handler                    Kind Lang Bytes

1    soun soun                       samr eng   130848   Encoder: NXTR

12.78* kbp/s 81.900 sec AMR Narrow-Band. Modes: 0, 1, 2, 3, 4, 5, 6, 7, 8. Encoder vendor code: NXTR

2    vide vide                       s263 eng   1312111   Encoder: NXTR

128.41* kbp/s 81.748 sec H.263 Baseline profile, Level 10. Encoder vendor code: NXTR

  该3GP文件结构如下:

zbc1217_h263.3gp

Atom ftyp @ 0 of size: 24, ends @ 24

Atom mdat @ 24 of size: 1989236, ends @ 1989260

Atom moov @ 1989260 of size: 14951, ends @ 2004211

Atom mvhd @ 1989268 of size: 108, ends @ 1989376

Atom iods @ 1989376 of size: 33, ends @ 1989409

Atom udta @ 1989409 of size: 1069, ends @ 1990478

Atom rtng [eng] @ 1989417 of size: 29, ends @ 1989446

Atom uuid=f78caa0c-36be-4ce9-88d2-03c256dabeb2 @ 1989446 of size: 1032, ends @ 1990478

Atom trak @ 1990478 of size: 9978, ends @ 2000456

Atom tkhd @ 1990486 of size: 92, ends @ 1990578

Atom mdia @ 1990578 of size: 9842, ends @ 2000420

Atom mdhd @ 1990586 of size: 32, ends @ 1990618

Atom hdlr @ 1990618 of size: 33, ends @ 1990651

Atom minf @ 1990651 of size: 9769, ends @ 2000420

    Atom vmhd @ 1990659 of size: 20, ends @ 1990679

    Atom dinf @ 1990679 of size: 36, ends @ 1990715

        Atom dref @ 1990687 of size: 28, ends @ 1990715

    Atom stbl @ 1990715 of size: 9705, ends @ 2000420

        Atom stsd @ 1990723 of size: 117, ends @ 1990840

            Atom s263 @ 1990739 of size: 101, ends @ 1990840

                Atom d263 @ 1990825 of size: 15, ends @ 1990840

        Atom stts @ 1990840 of size: 32, ends @ 1990872

        Atom stsc @ 1990872 of size: 1900, ends @ 1992772

        Atom stsz @ 1992772 of size: 6300, ends @ 1999072

        Atom stco @ 1999072 of size: 644, ends @ 1999716

        Atom stss @ 1999716 of size: 704, ends @ 2000420

Atom udta @ 2000420 of size: 36, ends @ 2000456

Atom uuid=f78caa0c-36be-4ce9-87d2-03c256dabeb2 @ 2000428 of size: 28, ends @ 2000456

Atom trak @ 2000456 of size: 2934, ends @ 2003390

Atom tkhd @ 2000464 of size: 92, ends @ 2000556

Atom mdia @ 2000556 of size: 2798, ends @ 2003354

Atom mdhd @ 2000564 of size: 32, ends @ 2000596

Atom hdlr @ 2000596 of size: 33, ends @ 2000629

Atom minf @ 2000629 of size: 2725, ends @ 2003354

    Atom smhd @ 2000637 of size: 16, ends @ 2000653

    Atom dinf @ 2000653 of size: 36, ends @ 2000689

        Atom dref @ 2000661 of size: 28, ends @ 2000689

    Atom stbl @ 2000689 of size: 2665, ends @ 2003354

        Atom stsd @ 2000697 of size: 69, ends @ 2000766

            Atom samr @ 2000713 of size: 53, ends @ 2000766

                Atom damr @ 2000749 of size: 17, ends @ 2000766

        Atom stts @ 2000766 of size: 24, ends @ 2000790

        Atom stsc @ 2000790 of size: 1900, ends @ 2002690

        Atom stsz @ 2002690 of size: 20, ends @ 2002710

        Atom stco @ 2002710 of size: 644, ends @ 2003354

Atom udta @ 2003354 of size: 36, ends @ 2003390

Atom uuid=f78caa0c-36be-4ce9-87d2-03c256dabeb2 @ 2003362 of size: 28, ends @ 2003390

Atom trak @ 2003390 of size: 420, ends @ 2003810

Atom tkhd @ 2003398 of size: 92, ends @ 2003490

Atom mdia @ 2003490 of size: 296, ends @ 2003786

Atom mdhd @ 2003498 of size: 32, ends @ 2003530

Atom hdlr @ 2003530 of size: 33, ends @ 2003563

Atom minf @ 2003563 of size: 223, ends @ 2003786

    Atom nmhd @ 2003571 of size: 12, ends @ 2003583

    Atom dinf @ 2003583 of size: 36, ends @ 2003619

        Atom dref @ 2003591 of size: 28, ends @ 2003619

    Atom stbl @ 2003619 of size: 167, ends @ 2003786

        Atom stsd @ 2003627 of size: 67, ends @ 2003694

            Atom mp4s @ 2003643 of size: 51, ends @ 2003694

                Atom esds @ 2003659 of size: 35, ends @ 2003694

        Atom stts @ 2003694 of size: 24, ends @ 2003718

        Atom stsc @ 2003718 of size: 28, ends @ 2003746

        Atom stsz @ 2003746 of size: 20, ends @ 2003766

        Atom stco @ 2003766 of size: 20, ends @ 2003786

Atom tref @ 2003786 of size: 24, ends @ 2003810

Atom mpod @ 2003794 of size: 16, ends @ 2003810

Atom trak @ 2003810 of size: 401, ends @ 2004211

Atom tkhd @ 2003818 of size: 92, ends @ 2003910

Atom mdia @ 2003910 of size: 301, ends @ 2004211

Atom mdhd @ 2003918 of size: 32, ends @ 2003950

Atom hdlr @ 2003950 of size: 33, ends @ 2003983

Atom minf @ 2003983 of size: 228, ends @ 2004211

    Atom nmhd @ 2003991 of size: 12, ends @ 2004003

    Atom dinf @ 2004003 of size: 36, ends @ 2004039

        Atom dref @ 2004011 of size: 28, ends @ 2004039

    Atom stbl @ 2004039 of size: 172, ends @ 2004211

        Atom stsd @ 2004047 of size: 72, ends @ 2004119

                    Atom mp4s @ 2004063 of size: 56, ends @ 2004119

                Atom esds @ 2004079 of size: 40, ends @ 2004119

        Atom stts @ 2004119 of size: 24, ends @ 2004143

        Atom stsc @ 2004143 of size: 28, ends @ 2004171

        Atom stsz @ 2004171 of size: 20, ends @ 2004191

        Atom stco @ 2004191 of size: 20, ends @ 2004211

------------------------------------------------------

Total size: 2004211 bytes; 82 atoms total. AtomicParsley version: 0.9.0 (utf16)

Media data: 1989236 bytes; 14975 bytes all other atoms (0.747% atom overhead).

Total free atom space: 0 bytes; 0.000% waste.

------------------------------------------------------

Movie duration: 156.980 seconds (02:36.98) - 101.38* kbp/sec bitrate (*=approximate)

Low-level details. Total tracks: 4

Trk Type Handler                    Kind Lang Bytes

1    vide [none listed]              s263 und   1738018   Encoder: ViVi

88.58* kbp/s 156.960 sec H.263 Baseline Profile, Level 20. Encoder vendor code: ViVi

2    soun [none listed]              samr und   251168   Encoder: ViVi

12.80* kbp/s 156.980 sec AMR Narrow-Band. Modes: 7. Encoder vendor code: ViVi

3    odsm [none listed]              mp4s und   18

4    sdsm [none listed]              mp4s und   24

该3GP文件结构如下:

 

其实3GP文件就是一个对象(box)容器,对象还允许包含子对象。

对象格式如下:

struct

{

UINT32          size;       // 对象大小

char                     type;      // 对象类型

void*             data;      // 对象数据(属性),大小为(size-8)

};

ISO base media file format》说明不同box对象的结构定义细节。

3. 3GP文件对象实例分析

l         ftype

File Type(该对象仅有一个)

记录该文件使用的规范和版本等信息。

属性

大小

说明

size

4

0x0000001c = 28

ftyp

4

ftyp

major_brand

4

3gp4

主类型

minor_version

4

最小版本号

compatible_brands[]

string

3gp4 | 3gp5 | 3g2a

兼容类型

l         mdat

Media Data

mdat 存放媒体数据(media data)。一般包括文字、音频和视频等。这些mdat的顺序不固定。

当前mdat对象包含的是纯文字。

大小

其他说明

size

4

0x00000041 = 65

mdat

4

string

这个box可以忽略。

l         mdat

音频数据块

大小

其他说明

size

4

0x0001FF28 = 130856

mdat

4

32*N

3C打头

每个音频帧32字节

amr音频数据以32字节一帧,每帧20毫秒。所以根据amr数据包大小就能估算出语音的时间长度。

(130856 – 8) / 32 = 4089 * 20 = 81780 ms = 817.80秒 = 01:21.90

这个时间与播放器上显示的时间基本相同。

注意:这里真实的视频数据起始位置为0x000005D。

在音频trak里面的stso对象里面的chunk_offset记录的就是这个值。

在RFC3267中有如下描述:

The sampling frequency used in AMR is 8000 Hz and the speech encoding is

performed on 20 ms speech frames. Therefore, each encoded AMR speech

frame represents 160 samples of the original speech.

AMR语音采样频率为8Khz,每帧对应20ms。

l         mdat

视频数据块

大小

其他说明

size

4

0x004946F1 = 4802289

mdat

4

4

H263视频数据

实际视频数据大小:4802289 – 8 = 4802281

《H263协议中文版》第8页 5.1图象层中描述:

每帧图象的数据包含一个图象头,并紧跟着块组数据,最后是一个end-of-sequence码和填塞位。

图象开始码 (PSC) (22 bits)

PSC是一个22比特的字。它的值是0000 0000 0000 0000 1000 00- (00 00 80 00 …z)

时域参考 (TR) (8 bits) 00-00 0000 00-

类型信息 (PTYPE) (13 bits)  00-10 0000 1000 000-0

位6-8:010 :表示图像为QCIF。

位9 :图象编码类型,“0” INTRA (I-picture),“1” INTER (P-picture)。关键帧标志位,0:关键帧,1:p帧。

l         moov

Movie Box

该对象保留了3GP视频的metadata,即该3GP的全部描述信息。

这个对象一般在文件开始或者末尾。

下面详细分析moov的各个子对象。

l         mvhd

Movie Head Box

大小

其他说明

size

4

0x0000006C = 108

mvhd

4

version

1

0

flag

3

0

creation_time

4

modification_time

4

timescale

4

0x000003E8 = 1000

时间缩放因子

duration

4

0x00013FEC = 81900 = 81.9s

持续时间

rate

4

0x00010000 1.0(即全速播放)

播放比率

volume

2

0x0100 1.0 (音量)

音量

reserved

保留

reserved

保留

matrix

视频转换矩阵

pre_defined

预定义(全0)

next_track_ID

4

0x000000CA = 202

下一个track_id

trak(音频)

Track Box

l         tkhd

Track Header Box

定义了该track的属性。

大小

其他说明

size

4

0x0000005C = 92

tkhd

4

version

1

0

flag

3

1

creation_time

4

modification_time

4

track_id

4

0x00000065 = 101

reserved

4

全0

duration

4

0x00013FEC = 81900 = 81.9s

音频播放时间

reserved

8

layer

2

alternate_group

2

volume

2

0x0100

如果track是音频则为0x0100,视频则为0x0000。

reserved

2

0

matrix

4 * 9

视频转换矩阵

width

4

0

音频的w和h为0

height

4

0

注意:如果track是音频volume则为0x0100,视频volume则为0x0000。

l         mdhd

Media Header Box

大小

其他说明

size

4

32

mdhd

4

version

1

flag

3

creation_time

4

modification_time

4

timescale

4

0x00001F40 = 8000

时间缩放因子

duration

4

0x0009FF60 = 655200/8000=81.9

音频播放时长

pad

1bit

language

15bit

0x15c7 ISO-639-2/T language code

pre_defined

2

l         hdlr

Handler Reference Box

大小

其他说明

size

4

0x00000025 = 37

hdlr

4

version

1

flag

3

pre_defined

4

0

handler_type

4

soun

vide:Video  track

soun:Audio  track

reserved

4 * 3

0

handler_type

string

(4+1)

soun

以’/0’结束

l         stbl

Sample Table Box

l         stts

Decoding Time to Sample Box

大小

其他说明

size

4

0x00000018 = 24

stts

4

version

1

flag

3

entry_count

4

1

sample_count

4

0x00000111 = 273

sample_delta

4

0x00000960 = 2400

说明:该amr音频数据里面有273个sample,每个sample的时间为2400,而音频的时间因子为8000(见5.2.3.1 mdhd的timescale),所以每个sample的时长 = 2400 / 8000s = 0.3s。

l         stsd

Sample Description Box

大小

其他说明

size

4

0x00000045 = 69

stsd

4

version

相关阅读

.3gp是什么文件 .3gp用什么播放器打开

 相信很多网友对于.3gp格式文件还不是很清楚,更不知道打开方式了,那么.3gp用什么播放器打开呢?一起跟着小编看看吧! .3gp是什么格式?.

3gp是什么格式文件?

3gp文件想必大家都不会陌生,因为在功能机时代3gp几乎称霸了功能机视频平台,那么3gp究竟是什么呢?3gp文件又如何打开呢?3gp是什么文件3

WMV转3GP完美解决方案

WMV转3GP,可实现将微软的流媒体WMV格式转换成手机常用的3GP格式,WMV格式的视频体积非常小,画质清晰,因此很适合在网上播放和传输,由于

分享到:

栏目导航

推荐阅读

热门阅读