如何使用 mp4settracksuit set箱子esconfiguration

视频流使用h264进行编码后怎样写入MP4文件中看了相关资料说涉及到&Ftyp&box、Moov&box、Mdat&box,其中这三个box的大小是怎么得到的?希望各位指点,谢谢!file_mp4_recorder.cpp文件写一个录制MP4的。创建文件并生成流信息如下(我生成的是h264+aac的mp4文件)
m_Mp4File&=&MP4Create(fileName,&9);
if(m_Mp4File&==&MP4_INVALID_FILE_HANDLE)&
hr&=&E_FAIL;
if(!MP4SetTimeScale(m_Mp4File,&90000))
MP4Close(m_Mp4File);
m_Mp4File&=&MP4_INVALID_FILE_HANDLE;
hr&=&E_FAIL;
MP4SetVideoProfileLevel(m_Mp4File,&0x0F);
MP4SetAudioProfileLevel(m_Mp4File,&0x0F);
m_Mp4VideoId&=&MP4AddH264VideoTrack(m_Mp4File,&90000,&MP4_INVALID_DURATION,&mEncodeX264Width,&mEncodeX264Height,&0,&0,&0,&0);
if(m_Mp4VideoId&==&MP4_INVALID_TRACK_ID&)&
MP4Close(m_Mp4File);
m_Mp4File&=&MP4_INVALID_FILE_HANDLE;
hr&=&E_FAIL;
m_Mp4AudioId&=&MP4AddAudioTrack(m_Mp4File,&USE_SAMPLE_RATE,&MP4_INVALID_DURATION);
if(m_Mp4AudioId&==&MP4_INVALID_TRACK_ID&)&
MP4Close(m_Mp4File);
m_Mp4File&=&MP4_INVALID_FILE_HANDLE;
hr&=&E_FAIL;
} &&&&unsigned&char*&faacDecoderInfo&=&NULL;&&&&
unsigned&long&&faacDecoderInfoSize&=&0;&&&&
if(&faacEncGetDecoderSpecificInfo(mMyOutPut.hEncoder,&&faacDecoderInfo,&&faacDecoderInfoSize&))&
MP4Close(m_Mp4File);
m_Mp4File&=&MP4_INVALID_FILE_HANDLE;
hr&=&E_FAIL;
return&&&&
if(!MP4SetTrackESConfiguration(m_Mp4File,&m_Mp4AudioId,&faacDecoderInfo,&faacDecoderInfoSize&))
free(faacDecoderInfo);
MP4Close(m_Mp4File);
m_Mp4File&=&MP4_INVALID_FILE_HANDLE;
hr&=&E_FAIL;
return&&&&
free(&faacDecoderInfo&);写数据就是:MP4WriteSample(m_Mp4File,&m_Mp4VideoId,&&mux_buffer[0],&pos,&dur&*&90000&/&1E7,&0,&true);MP4WriteSample(m_Mp4File,&m_Mp4AudioId,&mMyOutPut.bitbuf&+&totalbytesWritten,&bytesWritten,&dur&*&USE_SAMPLE_RATE&/&1E7,&0,&true);
无相关信息1558人阅读
android多媒体(33)
所以为(20,8)//关于这几个参数获取,参考
《如何使用 MP4SetTrackESConfiguration》
4、规定时间刻度问题,一般网上都是设置90000,这个90000是指1秒的tick数,其实也就是把1秒中分为90000份,在添加音视频的函数中
durationMP4_INVALID_DURATION
其中duration这个参数是指视频帧存在的时间,在90000这个刻度上存在的时间,如果用户确定录像时的音频视频帧是按固定速率的,那么在这里可以设置MP4_INVALID_DURATION,这时mp4v2就会使用下面的函数中的时间刻度
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:686638次
积分:7697
积分:7697
排名:第2875名
原创:54篇
转载:276篇
评论:171条
(10)(14)(8)(5)(2)(2)(1)(1)(2)(4)(12)(2)(1)(5)(15)(1)(3)(1)(2)(1)(8)(15)(1)(1)(2)(8)(1)(7)(3)(2)(13)(1)(7)(4)(1)(14)(7)(2)(6)(7)(14)(5)(14)(3)(9)(21)(4)(14)(15)(9)(3)(9)(19)(1)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'如何使用 MP4SetTrackESConfiguration
在使用 MP4v2 製作 .mp4 檔案時,如果你要使用的 Audio 編碼格式是 AAC,那麼你就需要使用&MP4SetTrackESConfiguration 這個函式來設定解碼需要的資料。在網路上看到的例子都是以 FAAC 編碼為居多,大多都可以參考需要的設定,設定&MP4SetTrackESConfiguration 的方式,都是先利用 FAAC 裡的&faacEncGetDecoderSpecificInfo
得到想要的資料,再傳給&MP4SetTrackESConfiguration
faacEncGetDecoderSpecificInfo(hEnc, &Config, &ConfigLen);
MP4SetTrackESConfiguration(hFile, AudioTrack, Config, ConfigLen);
這是剛好你用的是 FAAC library,但如果你用的是別的 library 該怎麼辦呢?
起初我也是試著去 Google 看看有沒有人有提供這樣的資料,後來在看到了有人說了大概的方式,但是我看了之後,並不了解它所說的格式怎麼決定?我使用的參數不一定和它用的是一樣的,所以我不能肯定要如何設定這個值。我也去
Google 了這個欄位的格式,但是沒有找到,還去查了一下 Apple Qiucktime 檔案格式的文件,也沒發現什麼。最後,我直接去看了 FAAC 的原始碼,才了解怎麼設定。(我應該一開始就看的...)
faacEncGetDecoderSpecificInfo
的程式碼如下,可以看出我們要的格式是
5 bits | 4 bits | 4 bits | 3 bits
第一欄 第二欄 第三欄 第四欄
第一欄:AAC Object Type
第二欄:Sample Rate Index
第三欄:Channel Number
第四欄:Don't care,設 0
FAACAPI faacEncGetDecoderSpecificInfo(faacEncHandle hEncoder,unsignedchar**
ppBuffer,unsignedlong*
pSizeOfDecoderSpecificInfo)
&&&BitStream*
&pBitStream = NULL;
&&&if((hEncoder == NULL) || (ppBuffer == NULL)
|| (pSizeOfDecoderSpecificInfo == NULL)) {
&&&&&&&return -1;
&&&if(hEncoder-&config.mpegVersion
== MPEG2){
&&&&&&&return -2; /* not supported */
&&&*pSizeOfDecoderSpecificInfo = 2;
&&&*ppBuffer =
&malloc(2);
&&&if(*ppBuffer != NULL){
&&&&&&&memset(*ppBuffer,0,*pSizeOfDecoderSpecificInfo);
&&&&&&&pBitStream =OpenBitStream(*pSizeOfDecoderSpecificInfo,
*ppBuffer);
&&&&&&&PutBit(pBitStream,
hEncoder-&config.aacObjectType,
&&&&&&&PutBit(pBitStream,
hEncoder-&sampleRateIdx, 4);
&&&&&&&PutBit(pBitStream,
hEncoder-&numChannels, 4);
&&&&&&&CloseBitStream(pBitStream);
&&&&&&&return 0;
&&&} else {
&&&&&&&return -3;
接著,要知道怎麼決定每個欄位的值,第三和第四就不用看了,只要找出第一和第二欄位就行了。從原始碼裡找出下面的資料:
/* AAC object types
#defineMAIN
#defineLOW
#defineSSR
#defineLTP
/* Returns
the sample rate index */
intGetSRIndex(unsignedint
sampleRate)
&&&if (92017 &= sampleRate)return
&&&if (75132 &= sampleRate)return
&&&if (55426 &= sampleRate)return
&&&if (46009 &= sampleRate)return
&&&if (37566 &= sampleRate)return
&&&if (27713 &= sampleRate)return
&&&if (23004 &= sampleRate)return
&&&if (18783 &= sampleRate)return
&&&if (13856 &= sampleRate)return
&&&if (11502 &= sampleRate)return
&&&if (9391 &= sampleRate)return
&&&return 11;
現在,對於你自己要設定的參數值,就知道要怎麼設了吧!舉個例子,我使用的 AAC 是 LOW,44100 hz,Stereo,那麼從上面的資料來看
第一欄:00010
第二欄:0100
第三欄:0010
第四欄:000
合起來: 10000 => 0x12 0x10
這樣就能找出你的選擇,需要對映什麼參數值了!
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:15182次
排名:千里之外
原创:14篇
转载:63篇
(3)(8)(10)(3)(5)(5)(9)(18)(4)(10)(4)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'当前位置: &
& 查看源码
mp4settrackesconfiguration.3
mp4settrackesconfiguration.3:源码内容
.TH&&MP4&&&3&&&Version&0.9&&&Cisco&Systems&Inc.&&&MP4&File&Format&Library&
.SH&&NAME&
fBMP4SetTrackESConfigurationfR&-&Set&the&elementary&stream&(ES)&configuration&of&a&track
.SH&&SYNTAX&
#include&&mp4.h&
bool&fBMP4SetTrackESConfigurationfR(
MP4FileHandle&fIhFilefP,
MP4TrackId&fItrackIdfP
const&u_int8_t*&fIpConfigfP,
u_int32_t&fIconfigSizefP
.SH&&ARGUMENTS&
Specifies&the&mp4&file&to&which&the&operation&applies.
fItrackIdfP
Specifies&the&track&to&which&the&operation&applies.
fIpConfigfP
Specifies&a&pointer&to&the&ES&configuration&information.
fIconfigSizefP
Specifies&the&size&of&the&ES&configuration&information.
.SH&&RETURN&VALUES&
Upon&success,&true&(1).&Upon&an&error,&false&(0).
.SH&&DESCRIPTION&
fBMP4SetTrackESConfigurationfR&sets&the&elementary&stream&(ES)&configuration&of&the&specified&track&in&the&mp4&file.&This&information&is&codec&specific&and&contains&the&configuration&necessary&for&the&given&codec&to&decode&the&samples&in&the&track.&
.SH&&SEE&ALSO&
CopyRight & 2008- All Rights reserved.  京公网安备:95}

我要回帖

更多关于 track suit set 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信