How do I programmatically convert mp3 to an itunes-playable aac/m4a file?

前端 未结 7 1655
无人及你
无人及你 2021-01-06 01:38

I\'ve been looking for a way to convert an mp3 to aac programmatically or via the command line with no luck. Ideally, I\'d have a snippet of code that I could call from my

7条回答
  •  长情又很酷
    2021-01-06 01:57

    I've had good luck using mplayer (which I believe uses ffmpeg...) and lame. To the point that I've wrapped it up in a script:

    #!/bin/sh
    
    TARGET=$1
    
    BASE=`basename "${TARGET}"`
    echo TARGET: "${TARGET}"
    echo BASE:   "${BASE}" .m4a
    
    # Warning! Race condition vulnerability here! Should use a mktemp
    # variant or something...
    mkfifo encode
    mplayer -quiet -ao pcm -aofile encode "${TARGET}" &
    lame --silent encode "${BASE}".mp3
    rm encode
    

    Sorry for the security issues, I banged this out on the train one day...

    My mplayer and lame come from fink

提交回复
热议问题