iOS系统默认支持的音效格式有以下几种:
音频格式 | 硬件解码 | 软件解码 |
---|---|---|
ACC | YES | YES |
ALAC | YES | YES |
MP3 | YES | YES |
CAF | YES | YES |
HE-AAC | YES | NO |
iLBC | NO | YES |
IMA4 | NO | YES |
Linea PCM | NO | YES |
u-law and a-law | NO | YES |
音频的播放需要经过解码,解码方式有两种:硬件解码和软件解码;其中软件解码更消耗手机性能,例如:费电.硬件解码虽然省电,但是硬件解码器一次只能对一个音频文件解码;如果同时播放两个音效,一个进行了硬件解码,另一个只能进行软件解码;
在实际的应用中通常使用非压缩的音频格式AIFF或者CAF音频格式,从而降低系统在音频解码上的消耗,达到省电的目的.
上表中列举了各个音频格式对应支持的解码方式,最好选用支持硬件解码的音频文件格式.
下面我们就来看看怎么转换为我们需要的音频格式:
使用系统自带的终端即可实现音频的转换
afconvert -h 查看指令的帮助信息
Audio File Convert
Version: 2.0
Copyright 2003-2013, Apple Inc. All Rights Reserved.
Specify -h (-help) for command options
Usage:
afconvert [option...] input_file [output_file]
Options may appear before or after the direct arguments. If output_file
is not specified, a name is generated programmatically and the file
is written into the same directory as input_file.
afconvert input_file [-o output_file [option...]]...
Output file options apply to the previous output_file. Other options
may appear anywhere.
...
afconvert -hf 查看支持的音频文件转换格式
Audio file and data formats:
'3gpp' = 3GP Audio (.3gp)
data_formats: 'Qclp' 'aac ' 'aace' 'aacf' 'aach' 'aacl'
'aacp' 'samr'
'3gp2' = 3GPP-2 Audio (.3g2)
data_formats: 'Qclp' 'aac ' 'aace' 'aacf' 'aach' 'aacl'
'aacp' 'samr'
'adts' = AAC ADTS (.aac, .adts)
data_formats: 'aac ' 'aach' 'aacp'
'ac-3' = AC3 (.ac3)
data_formats: 'ac-3'
'AIFC' = AIFC (.aifc, .aiff, .aif)
data_formats: I8 BEI16 BEI24 BEI32 BEF32 BEF64 UI8 'ulaw'
'alaw' 'MAC3' 'MAC6' 'ima4' 'QDMC' 'QDM2'
'Qclp' 'agsm'
'AIFF' = AIFF (.aiff, .aif)
data_formats: I8 BEI16 BEI24 BEI32
'amrf' = AMR (.amr)
data_formats: 'samr' 'sawb'
'm4af' = Apple MPEG-4 Audio (.m4a, .m4r)
data_formats: 'aac ' 'aace' 'aacf' 'aach' 'aacl' 'aacp'
'ac-3' 'alac' 'ec-3' 'paac' 'pac3' 'qec3'
'zec3'
'm4bf' = Apple MPEG-4 AudioBooks (.m4b)
data_formats: 'aac ' 'aace' 'aacf' 'aach' 'aacl' 'aacp'
'paac'
'caff' = CAF (.caf)
data_formats: '.mp1' '.mp2' '.mp3' 'QDM2' 'QDMC' 'Qclp'
'Qclq' 'aac ' 'aace' 'aacf' 'aach' 'aacl'
'aacp' 'ac-3' 'alac' 'alaw' 'dvi8' 'ec-3'
'ilbc' 'ima4' I8 BEI16 BEI24 BEI32 BEF32
BEF64 LEI16 LEI24 LEI32 LEF32 LEF64 'ms\x00\x02'
'ms\x00\x11' 'ms\x001' 'paac' 'pac3' 'pec3'
'qaac' 'qac3' 'qach' 'qacp' 'qec3' 'samr'
'ulaw' 'zaac' 'zac3' 'zach' 'zacp' 'zec3'
'ec-3' = EC3 (.ec3)
data_formats: 'ec-3'
'MPG1' = MPEG Layer 1 (.mp1, .mpeg, .mpa)
data_formats: '.mp1'
'MPG2' = MPEG Layer 2 (.mp2, .mpeg, .mpa)
data_formats: '.mp2'
'MPG3' = MPEG Layer 3 (.mp3, .mpeg, .mpa)
data_formats: '.mp3'
'mp4f' = MPEG-4 Audio (.mp4)
data_formats: 'aac ' 'aace' 'aacf' 'aach' 'aacl' 'aacp'
'ac-3' 'ec-3' 'qec3' 'zec3'
'NeXT' = NeXT/Sun (.snd, .au)
data_formats: I8 BEI16 BEI24 BEI32 BEF32 BEF64 'ulaw'
'Sd2f' = Sound Designer II (.sd2)
data_formats: I8 BEI16 BEI24 BEI32
'WAVE' = WAVE (.wav)
data_formats: UI8 LEI16 LEI24 LEI32 LEF32 LEF64 'ulaw'
'alaw'
下面以将input.wav格式音频转换为output.acc格式音频为例讲解afconvert指令的使用:
首先,cd到待转换文件目录:
cd /Users/mac/Desktop/voice
然后输入指令:
afconvert -f adts -d aac input.wav
afconvert -f adts -d aac input.wav
- afconvert 音频转换指令
- -f adts 指定文件格式:acc格式音频需要指定为adts(文件与格式化格式见上面帮助信息)
- -d acc 指定数据格式
- input.wav 待转换文件名称
回车,即可发现目录下多了个与待转换文件同名的input.aac文件,如果需要指定文件的输出名称,可将指令做如下修改:
afconvert -f adts -d aac input.wav output.aac
回车,可发现目录下多了个output.aac文件;
下面将刚刚转换的input.aac文件转换为output.caf文件:
afconvert -f caff -d aac -b 32000 input.aac output.caf
PS:这里的-b 用于指定文件字节数
帮助信息里的介绍如下:
{ -b | --bitrate } total_bit_rate_bps
e.g. 256000 will give you roughly:
for stereo source: 128000 bits per channel
for 5.1 source: 51000 bits per channel
(the .1 channel consumes few bits and can be discounted in the
total bit rate calculation)
回车后,即可生成一个output.caf文件;
最后,介绍一个批量转换的指令:
find . -name '*.aac' -exec afconvert -f caff -d aac -b 32000 {} \;
将所有的.aac文件格式音频转换为.caf文件格式;
注意:指令最后有一分号(;),\与{}之间有一个空格
(完)
Github | LQQZYY |
CSDN博客 | 流火绯瞳 |
新浪微博 | 杯水_沧海 |
302934443 |
网友评论