[FFmpeg-user] Trouble with ffmpeg in bash script
Cortman
cortman at ubuntu.com
Fri May 2 15:13:39 CEST 2014
Hi,
I have written a Bash script to recursively convert files of <format> to
mp3. I originally wrote it using an avconv command, but as I have compiled
ffmpeg for other purposes on the machine I would like to use ffmpeg in the
script instead.
Here is the code of my script:
#! /bin/bash
set -e
extension=$1
if [ -z "$1" ] ; then
echo "You must provide the file extension as an argument"
fi
files=$(find . -type f -name "*.$extension")
while read -r line ; do
ffmpeg -i "$line" -c:a libmp3lame -q:a 0 "${line/%$extension/mp3}"
done <<< "$files"
find . -type f -name *.$extension -exec rm {} \;
The current problem (that I did not experience with avconv, but I'm not
sure is related to that fact) is that after passing the name of the first
file to ffmpeg (which works fine), it lops off the first character or
several of subsequent filenames, causing the script to stop with a "No such
file or directory". Here's the output of bash -x:
bash -x convert m4a
+ set -e
+ extension=m4a
+ '[' -z m4a ']'
++ find . -type f -name '*.m4a'
+ files='./12 Track 12.m4a
./13 Track 13.m4a
./14 Track 14.m4a
./15 Track 15.m4a
./16 Track 16.m4a
./17 Track 17.m4a
./18 Track 18.m4a
./19 Track 19.m4a
./20 Track 20.m4a
./21 Track 21.m4a'
+ read -r line
+ ffmpeg -i './12 Track 12.m4a' -c:a libmp3lame -q:a 0 './12 Track 12.mp3'
ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers
built on Apr 28 2014 09:19:02 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration: --prefix=/home/cortman/ffmpeg_build
--extra-cflags=-I/home/cortman/ffmpeg_build/include
--extra-ldflags=-L/home/cortman/ffmpeg_build/lib --bindir=/home/cortman/bin
--extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac
--enable-libfreetype --enable-libmp3lame --enable-libopus
--enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264
--enable-nonfree --enable-x11grab
libavutil 52. 79.100 / 52. 79.100
libavcodec 55. 59.100 / 55. 59.100
libavformat 55. 37.101 / 55. 37.101
libavdevice 55. 13.100 / 55. 13.100
libavfilter 4. 4.100 / 4. 4.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './12 Track 12.m4a':
Metadata:
major_brand : M4A
minor_version : 0
compatible_brands: M4A mp42isom
creation_time : 2010-07-16 22:15:10
title : Track 12
album : The Blight Way 5
track : 12/21
compilation : 0
gapless_playback: 0
encoder : iTunes 9.1.1.12, QuickTime 7.6.6
Encoding Params : vers
iTunNORM : 0000008E 0000008E 000011CF 000011CF 0000CDCE
0000CDCE 000058C7 000058C7 0000C1D5 0000C1D5
iTunes_CDDB_1 :
2B111015+327797+21+150+12157+24653+36842+52278+68519+84434+105266+126989+147722+159422+171658+187358+202802+225405+248028+270590+293981+300103+305878+316401
iTunes_CDDB_TrackNumber: 12
Duration: 00:03:29.40, start: 0.000000, bitrate: 209 kb/s
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo,
fltp, 207 kb/s (default)
Metadata:
creation_time : 2010-07-16 22:15:10
Output #0, mp3, to './12 Track 12.mp3':
Metadata:
major_brand : M4A
minor_version : 0
compatible_brands: M4A mp42isom
iTunes_CDDB_TrackNumber: 12
TIT2 : Track 12
TALB : The Blight Way 5
TRCK : 12/21
TCMP : 0
gapless_playback: 0
iTunes_CDDB_1 :
2B111015+327797+21+150+12157+24653+36842+52278+68519+84434+105266+126989+147722+159422+171658+187358+202802+225405+248028+270590+293981+300103+305878+316401
Encoding Params : vers
iTunNORM : 0000008E 0000008E 000011CF 000011CF 0000CDCE
0000CDCE 000058C7 000058C7 0000C1D5 0000C1D5
TSSE : Lavf55.37.101
Stream #0:0(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp
(default)
Metadata:
creation_time : 2010-07-16 22:15:10
Stream mapping:
Stream #0:0 -> #0:0 (aac -> libmp3lame)
Press [q] to stop, [?] for help
size= 539kB time=00:00:24.86 bitrate= 177.6kbits/s
Enter command: <target>|all <time>|-1 <command>[ <argument>]
Queing commands only on filters supporting the specific command is
unsupported
size= 1632kB time=00:01:15.02 bitrate= 178.2kbits/s
Enter command: <target>|all <time>|-1 <command>[ <argument>]
Queing commands only on filters supporting the specific command is
unsupported
size= 2738kB time=00:02:05.43 bitrate= 178.8kbits/s
Enter command: <target>|all <time>|-1 <command>[ <argument>]
Queing commands only on filters supporting the specific command is
unsupported
size= 3844kB time=00:02:55.74 bitrate= 179.2kbits/s
Enter command: <target>|all <time>|-1 <command>[ <argument>]
Queing commands only on filters supporting the specific command is
unsupported
size= 4574kB time=00:03:29.42 bitrate= 178.9kbits/s
video:0kB audio:4573kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.017084%
+ read -r line
+ ffmpeg -i 'rack 17.m4a' -c:a libmp3lame -q:a 0 'rack 17.mp3'
ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers
built on Apr 28 2014 09:19:02 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration: --prefix=/home/cortman/ffmpeg_build
--extra-cflags=-I/home/cortman/ffmpeg_build/include
--extra-ldflags=-L/home/cortman/ffmpeg_build/lib --bindir=/home/cortman/bin
--extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac
--enable-libfreetype --enable-libmp3lame --enable-libopus
--enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264
--enable-nonfree --enable-x11grab
libavutil 52. 79.100 / 52. 79.100
libavcodec 55. 59.100 / 55. 59.100
libavformat 55. 37.101 / 55. 37.101
libavdevice 55. 13.100 / 55. 13.100
libavfilter 4. 4.100 / 4. 4.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
rack 17.m4a: No such file or directory
You can see that it's trying to convert "rack 17.m4a" instead of "17 Track
17.m4a".
Can anyone give me some ideas on this?
Thanks!
Regards,
Cortman
More information about the ffmpeg-user
mailing list