이것은 지원되는 오디오 형식을 AAC 로 변환하기 위해 ffmpeg를 래핑하는 스크립트입니다 (ffmpeg Wiki에서 권장하는 aac 인코더 인 libfdk-aac 인코더 사용).
#!/usr/bin/env python2.7
from optparse import OptionParser
from subprocess import call
from os.path import splitext
import sys, os
def ffaac(filename, opts):
cmd = ['ffmpeg', '-hide_banner', '-y', '-i', filename,
'-vn', '-c:a', 'libfdk_aac']
profile = {'lc':'aac_low', 'he':'aac_he', 'he2':'aac_he_v2',
'ld':'aac_ld', 'eld':'aac_eld'}
if not opts.br and not opts.vbr:
cmd.extend(['-b:a', '320k'])
if opts.br:
cmd.extend(['-b:a', str(opts.br)+'k'])
if opts.vbr:
cmd.extend(['-vbr', opts.vbr])
if opts.ar:
cmd.extend(['-ar', opts.ar])
if opts.ch:
cmd.extend(['-ac', opts.ch])
cmd.extend(['-profile:a', profile[opts.prof]])
if opts.prof == 'eld' and opts.sbr:
cmd.extend(['-eld_sbr', '1'])
cmd.extend(['-f', 'adts'])
if filename.lower().endswith('.aac'):
return
outfile = splitext(filename)[0] + '.aac'
cmd.append(outfile)
return call(cmd)
if __name__=='__main__':
parser = OptionParser(sys.argv[0]+' [OPTIONS] FILE ...')
parser.add_option('-b', metavar='NUM', type=int, dest='br', help='bitrate')
parser.add_option('-r', metavar='NUM', choices=['8000','11025','16000','22050','32000', '44100', '48000'], dest='ar', help='sample rate: 8000/11025/22050/32000/44100/48000')
parser.add_option('-c', metavar='NUM', choices=['1','2'],dest='ch', help='channels: 1/2')
parser.add_option('-p', metavar='TYPE',choices=['lc', 'he', 'he2', 'ld', 'eld'], default='lc', dest='prof', help='profile: lc/he/he2/ld/eld')
parser.add_option('-v', metavar='QUAL', choices=['1', '2', '3', '4', '5'], dest='vbr', help='vbr quality: 1/2/3/4/5')
parser.add_option('-s', action='store_true', dest='sbr', help='use SBR for ELD')
parser.add_option('-d', action='store_true', dest='delete',help='delete source after converting')
opts, args = parser.parse_args()
for f in args:
if ffaac(f, opts) == 0 and opts.delete :
try:
os.remove(f)
except OSError:
pass
명령 행 도움말 메시지 :
Usage: /Users/leon/bin/ffaac.py [OPTIONS] FILE ...
Options:
-h, --help show this help message and exit
-b NUM bitrate
-r NUM sample rate: 8000/11025/22050/32000/44100/48000
-c NUM channels: 1/2
-p TYPE profile: lc/he/he2/ld/eld
-v QUAL vbr quality: 1/2/3/4/5
-s use SBR for ELD
-d delete source after converting