如何使用MP4SetTrackESConfiguration
来源:互联网 发布:汉化 知乎 编辑:程序博客网 时间:2024/05/14 08:01
在使用MP4v2制作.mp4档案时,如果你要使用的Audio编码格式是AAC,那么你就需要使用MP4SetTrackESConfiguration这个函式来设定解码需要的资料。在网路上看到的例子都是以FAAC编码为居多,大多都可以参考需要的设定,设定MP4SetTrackESConfiguration的方式,都是先利用FAAC里的 faacEncGetDecoderSpecificInfo得到想要的资料,再传给 MP4SetTrackESConfiguration
像这样
faacEncGetDecoderSpecificInfo(hEnc, &Config, &ConfigLen);
MP4SetTrackESConfiguration(hFile, AudioTrack, Config, ConfigLen);
这是刚好你用的是FAAC library,但如果你用的是别的library该怎么办呢?
5 bits | 4 bits | 4 bits | 3 bits
第一欄 第二欄 第三欄 第四欄
第一欄:AAC Object Type
第二欄:Sample Rate Index
第三欄:Channel Number
第四欄:Don't care,設 0
int 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, 5);
PutBit(pBitStream, hEncoder->sampleRateIdx, 4);
PutBit(pBitStream, hEncoder->numChannels, 4);
CloseBitStream(pBitStream);
return 0;
} else {
return -3;
}
}
接著,要知道怎麼決定每個欄位的值,第三和第四就不用看了,只要找出第一和第二欄位就行了。從原始碼裡找出下面的資料:
/* AAC object types */
#defineMAIN 1
#defineLOW 2
#defineSSR 3
#defineLTP 4
/* Returns the sample rate index */
intGetSRIndex(unsignedint sampleRate)
{
if (92017 <= sampleRate)return 0;
if (75132 <= sampleRate)return 1;
if (55426 <= sampleRate)return 2;
if (46009 <= sampleRate)return 3;
if (37566 <= sampleRate)return 4;
if (27713 <= sampleRate)return 5;
if (23004 <= sampleRate)return 6;
if (18783 <= sampleRate)return 7;
if (13856 <= sampleRate)return 8;
if (11502 <= sampleRate)return 9;
if (9391 <= sampleRate)return 10;
return 11;
}
現在,對於你自己要設定的參數值,就知道要怎麼設了吧!舉個例子,我使用的 AAC 是 LOW,44100 hz,Stereo,那麼從上面的資料來看
第一欄:00010
第二欄:0100
第三欄:0010
第四欄:000
合起來: 00010010 00010000 => 0x12 0x10
這樣就能找出你的選擇,需要對映什麼參數值了!
像这样
faacEncGetDecoderSpecificInfo(hEnc, &Config, &ConfigLen);
MP4SetTrackESConfiguration(hFile, AudioTrack, Config, ConfigLen);
这是刚好你用的是FAAC library,但如果你用的是别的library该怎么办呢?
起初我也是试着去Google看看有没有人有提供这样的资料,后来在这一篇看到了有人说了大概的方式,但是我看了之后,并不了解它所说的格式怎么决定?我使用的参数不一定和它用的是一样的,所以我不能肯定要如何设定这个值。我也去Google了这个栏位的格式,但是没有找到,还去查了一下Apple Qiucktime档案格式的文件,也没发现什么。最后,我直接去看了FAAC的原始码,才了解怎么设定。(我应该一开始就看的...)
5 bits | 4 bits | 4 bits | 3 bits
第一欄 第二欄 第三欄 第四欄
第一欄:AAC Object Type
第二欄:Sample Rate Index
第三欄:Channel Number
第四欄:Don't care,設 0
int 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, 5);
PutBit(pBitStream, hEncoder->sampleRateIdx, 4);
PutBit(pBitStream, hEncoder->numChannels, 4);
CloseBitStream(pBitStream);
return 0;
} else {
return -3;
}
}
接著,要知道怎麼決定每個欄位的值,第三和第四就不用看了,只要找出第一和第二欄位就行了。從原始碼裡找出下面的資料:
/* AAC object types */
#defineMAIN 1
#defineLOW 2
#defineSSR 3
#defineLTP 4
/* Returns the sample rate index */
intGetSRIndex(unsignedint sampleRate)
{
if (92017 <= sampleRate)return 0;
if (75132 <= sampleRate)return 1;
if (55426 <= sampleRate)return 2;
if (46009 <= sampleRate)return 3;
if (37566 <= sampleRate)return 4;
if (27713 <= sampleRate)return 5;
if (23004 <= sampleRate)return 6;
if (18783 <= sampleRate)return 7;
if (13856 <= sampleRate)return 8;
if (11502 <= sampleRate)return 9;
if (9391 <= sampleRate)return 10;
return 11;
}
現在,對於你自己要設定的參數值,就知道要怎麼設了吧!舉個例子,我使用的 AAC 是 LOW,44100 hz,Stereo,那麼從上面的資料來看
第一欄:00010
第二欄:0100
第三欄:0010
第四欄:000
合起來: 00010010 00010000 => 0x12 0x10
這樣就能找出你的選擇,需要對映什麼參數值了!
阅读全文
0 0
- MP4V2--如何使用 MP4SetTrackESConfiguration
- 如何使用 MP4SetTrackESConfiguration
- MP4V2--如何使用 MP4SetTrackESConfiguration .
- MP4V2--如何使用 MP4SetTrackESConfiguration
- 如何使用MP4SetTrackESConfiguration
- Android 如何使用使用数据库
- 如何安装使用Oracle10g
- 如何使用csdn blog
- 如何使用Log4j?
- 如何使用NetMeeting
- 如何使用 URLScan
- 如何使用线程
- 如何使用make
- 如何使用万用表
- 如何使用SQL*Loader?
- 如何使用 Quota
- 如何使用 gcc 编译程序
- 如何使用全局变量
- Cookbook for R-基础(翻译笔记3)
- 替换字符串中的空格&求字符串最后一个单词的长度
- .net mvc 利用NPOI导入导出excel
- Python3之socket实现并发
- SVM和softmax的区别
- 如何使用MP4SetTrackESConfiguration
- 从Google人工智能DeepMind团队的AlphaGo的论文算法提取的学习方法:大脑逻辑结构图
- 命令行
- 关于小米6.0以上系统手机动态获取权限问题
- (博弈)Fliping game--HDOJ
- sql关键字过滤C#方法
- ssh框架中遇到的问题
- 云课堂入门整理---计算机网络-传输层(一)
- 图论总结(4)有向图的强连通分量