ios - 蹩脚 - 将比特率提高到 320
<p><p>首先我想展示我通过 Lame 库将源 .wav 文件转换为 .mp3 的方法:</p>
<pre><code>- (void)convertFromWav:(NSString *)sourceFilePath ToMp3:(NSString *)resultName {
NSString *mp3FileName = ;
NSString *mp3FilePath = ;
@try {
int read, write;
FILE *pcm = fopen(, "rb");//source
if (pcm == NULL) {
perror("fopen");
return;
}
fseek(pcm, 4*1024, SEEK_CUR); //skip file header
FILE *mp3 = fopen(, "wb");//output
const int sampleRate = 44100;
const int bitsPerSample = 16;
const int numberOfChannels = 2;
const int PCM_SIZE = 8192*2;
const int MP3_SIZE = 8192*2;
short int pcm_buffer;
unsigned char mp3_buffer;
lame_t lame = lame_init();
lame_set_in_samplerate(lame, sampleRate);
lame_set_VBR(lame, vbr_default);
lame_init_params(lame);
lame_get_num_samples(lame);
long long fileSize = [[[ attributesOfItemAtPath:sourceFilePath error:nil] objectForKey:NSFileSize] longLongValue];
long duration = fileSize / (sampleRate * numberOfChannels * bitsPerSample / 8);//(fileSize * 8.0f) / (sampleRate * 2);
lame_set_num_samples(lame, (duration * sampleRate));
lame_get_num_samples(lame);
float percent = 0.0;
int totalframes = lame_get_totalframes(lame);
do {
read = fread(pcm_buffer, 2*sizeof(short int), PCM_SIZE, pcm);
if (read == 0)
write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);
else
write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE);
fwrite(mp3_buffer, write, 1, mp3);
int frameNum = lame_get_frameNum(lame);
if (frameNum < totalframes)
percent = (100. * frameNum / totalframes + 0.5);
else
percent = 100;
if ()
{
;
}
} while (read != 0);
lame_close(lame);
fclose(mp3);
fclose(pcm);
}
@catch (NSException *exception) {
NSLog(@"%@",);
}
@finally {
if ()
{
;
}
}
}
</code></pre>
<p>没关系,它正在工作。结果,我有 .mp3 每秒有 152000 位。但我想让它每秒 320000 位。我怎样才能改变它?我在理论上对这些东西不好,所以我不知道哪些值会改变。谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你想使用 <code>lame_set_VBR (lame_t, vbr_off);</code> 然后你可以使用 <code>lame_set_brate</code> 在那里你可以设置所需的比特率量。使用 <code>vbr_off</code> 可为您提供 CBR 模式,如文档中所确认(请参阅 <strong> <a href="https://github.com/wuqiong/mp3lame-for-iOS/blob/master/lame.framework/Headers/lame.h" rel="noreferrer noopener nofollow">headers.h</a> </strong>):</p>
<blockquote>
<p>*********************************************************************<br/>
VBR control<br/>
************************************************************************<br/> /* Types of VBR.default = <strong>vbr_off = CBR</strong> */<br/> int CDECL
lame_set_VBR(lame_global_flags *, vbr_mode); <br/>vbr_mode CDECL
lame_get_VBR(const lame_global_flags *);</p>
</blockquote>
<p>试试这个:</p>
<pre><code>//# for constants of settings
const int sampleRate = 44100;
const int bitsPerSample = 16;
const int numberOfChannels = 2;
const int myBitRate = 320;
//# for Lame settings
lame_t lame = lame_init();
lame_set_in_samplerate(lame_t, sampleRate); //is 44100
lame_set_VBR (lame_t, vbr_off); //force CBR mode
lame_set_brate (lame_t, myBitRate); //is 320
lame_init_params (lame_t);
</code></pre>
<p>你也可以像这样设置Lame:<br/>
<code>lame_t lame = lame_init();</code> 反而变成这样:<code>lame_t = lame_init();</code><br/><br/>
只是说如果您定义了一个 <code>lame_t</code> 我希望它需要该名称用于其余设置。你知道像 <code>lame_init_params (lame_t);</code> 等等。</p></p>
<p style="font-size: 20px;">关于ios - 蹩脚 - 将比特率提高到 320,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35151284/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35151284/
</a>
</p>
页:
[1]