2

I want to batch convert a directory of M4V video files to MP3 audio files using VLC. (I don't mind using ffmpeg alternatively.)

I found a bash script to get me started, but I don't know which VLC parameters to plug into the script.

I want to use either a variable bitrate or 64kb/s. The sample rate can be 44100 (or lower). I'm not outputting video so I'm not sure if VLC requires those parameters.

Can anyone help me fix up this script to meet my needs?

#!/bin/sh                                                                                                                                                     

vcodec="mp4v"
acodec="mp4a"
bitrate="1024"
arate="128"
mux="mp4"

vlc="/usr/bin/vlc"                                                                                                                                           

if [ ! -e "$vlc" ]; then
    echo "Command '$vlc' does not exist"
    exit 1
fi

for file in "$@"; do
    echo "=> Transcoding '$file'... "

    dst=`dirname "$file"`
    new=`basename "$file" | sed 's@\.[a-z][a-z][a-z]$@@'`.$mux

    $vlc -I dummy -q "$file" \
       --sout "#transcode{vcodec=mp4v,vb=1024,acodec=mp4a,ab=128}:standard{mux=mp4,dst=\"$dst/$new\",access=file}" \
       vlc://quit
    ls -lh "$file" "$dst/$new"
    echo
done
2

Here's how using ffmpeg:

$ ./ffmpeg -i testing.m4v -b:a 192K -vn testing.mp3

Or variable bit-rate:

$ ./ffmpeg -i testing.m4v -q:a 0 -map a testing.mp3

ffmpeg version

$ ./ffmpeg -version
ffmpeg version N-56896-ga927276
built on Oct  5 2013 05:42:36 with gcc 4.6 (Debian 4.6.3-1)
configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
libavutil      52. 46.100 / 52. 46.100
libavcodec     55. 34.100 / 55. 34.100
libavformat    55. 19.100 / 55. 19.100
libavdevice    55.  3.100 / 55.  3.100
libavfilter     3. 88.101 /  3. 88.101
libswscale      2.  5.100 /  2.  5.100
libswresample   0. 17.103 /  0. 17.103
libpostproc    52.  3.100 / 52.  3.100

References

0

Here's what I ended up using. Thanks to slm for the ffmpeg help. I put that code in a loop.

#!/bin/sh                                                                                                                                                     
arate="64K"
ext="mp3"                                                                                                                                              
app="/usr/bin/ffmpeg"                                                                                                                                           
if [ ! -e "$app" ]; then
    echo "Command '$app' does not exist"
    exit 1
fi

for file in "$@"; do
    echo "=> Transcoding '$file' ..."
    dst=`dirname "$file"`
    new=`basename "$file" | sed 's@\.[a-z][a-z][a-z]$@@'`.$ext
    $app -i "$file" -b:a $arate -vn "$dst/$new"
    ls -lh "$file" "$dst/$new"
    echo
done

It works. However, there's a bug in my file naming. I didn't fix it yet. The output files are named blahblah.m4v.mp3 instead of blahblah.mp3.

0

Works nicely, thanks

It works. However, there's a bug in my file naming. I didn't fix it yet. The output files are named blahblah.m4v.mp3 instead of blahblah.mp3.

#!/bin/sh                                                                                                                                                     
arate="64K"
ext="mp3"                                                                                                                                              
app="/usr/bin/ffmpeg"                                                                                                                                           
if [ ! -e "$app" ]; then
    echo "Command '$app' does not exist"
    exit 1
fi

for file in "$@"; do
    echo "=> Transcoding '$file' ..."
    dst=`dirname "$file"`
    new=`basename "$file" | sed 's@\.[a-z][a-z0-9][a-z0-9]$@@'`.$ext
    $app -i "$file" -b:a $arate -vn "$dst/$new"
    ls -lh "$file" "$dst/$new"
    echo
done

I'm sure there will be a better way but allowing 0-9 in the regex as well means .m4v and .mp4 etc. will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.