How do I use afconvert to convert all the files in a directory from wav to caf?

别说谁变了你拦得住时间么 提交于 2019-12-02 16:24:55
lavinio

On Windows, use the %~ni syntax.

for %i in (*.wav) do afconvert -f caff -d LEI16@44100 -c 1 %i %~ni.caf
Randall

Similar approach for bash: for i in *.wav; do afconvert -f caff -d LEI16@44100 -c 1 $i ${i%.wav}.caf; done

Ward

found this:

##
## Shell script to batch convert all files in a directory to caf sound format for iPhone
## Place this shell script a directory with sound files and run it: 'sh converttocaf.sh'
## Any comments to 'support@ezone.com'
##

for f in *; do
    if  [ "$f" != "converttocaf.sh" ]
    then
        /usr/bin/afconvert -f caff -d LEI16 "$f"
        echo "$f converted"
    fi
done

Customize the aconvert options then save it as a text file called 'converttocaf.sh', place it in the directory of files you want to convert and run it from Terminal.

It works with files with spaces in their names.

AABSTRKT
for file in *.wav; do afconvert -f caff -d LEI16@44100 -c 1 "$file"; done

Hit the Return key directly after done.

Simple :)

For the people who are using OSX and are a bit afraid of Terminal scripts I created a little application with Automator, this application converts the files you select.

Download here

If you are dealing with filenames that contain spaces on Linux, try the following code:

SAVEIFS=$IFS 
IFS=$(echo -en "\n\b"); for i in *.wav; do afconvert -f caff -d LEI16@44100 -c 1 $i ${i%.wav}.caf; done

Python script on OSX. Default data format of the .caf is ima4. Default directory is '.'

Make a file called wav2caf.py, put it in your path, make it executable, fill it with:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import argparse
import glob

def main():
    # handle command line args
    parser = argparse.ArgumentParser(description='A program that converts .wav to .caf files.', formatter_class=argparse.RawTextHelpFormatter)
    parser.add_help = True
    parser.add_argument('-f', '--folder', dest='folder', type=str, default='.', help='folder of files to convert')
    parser.add_argument('-d', '--data', dest='data', type=str, default='ima4', help='data format of .caf')
    args = parser.parse_args()

    # process files in folder
    os.chdir(args.folder)
    for filename in glob.glob("*.wav"):
        name, ext = os.path.splitext(filename)
        command = 'afconvert -f caff -d ' + args.data + ' ' + filename + ' ' + name + '.caf'
        os.system(command)

if __name__ == "__main__":
    main()

Converts all .wav to .caf in current directory:

wav2caf.py

Converts all .wav to .caf in specified directory:

wav2caf.py -f Desktop/wavs/

Converts all .wav to .caf with data type 'aac ':

wav2caf.py -d 'aac '
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!