So I have an almost working script for FFMPEG that merges an .aif and an .mp4 file with the same name into a single filename_output.mp4 but when I execute it I get a weird error saying that a file is non exsistent but it the file it is searching for has two file extensions. The script is executed in the same folder as the files are.

The script that is executed in the folder:


cd "`dirname "$0"`"

for file in *.aif
filename=$(basename "$file")
# do something on "$file"
                ffmpeg -i "${filename}.aif" -i "${filename}.mp4" -map 0:0 -map 1:0 -acodec libfdk_aac -b:a 192k -vcodec copy -shortest "${filename}_output.mp4"

The output that i'm getting from the log:

++ dirname replace_audio_aif2mp4.bash
+ cd .
+ for file in '*.aif'
++ basename audio.aif
+ filename=audio.aif
+ ffmpeg -i audio.aif.aif -i audio.aif.mp4 -map 0:0 -map 1:0 -acodec libfdk_aac -b:a 192k -vcodec copy -shortest audio.aif_output.mp4
ffmpeg version 3.1.2-1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 6.1.1 (Debian 6.1.1-11) 20160802
  configuration: --prefix=/usr --extra-version=1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-chromaprint --enable-libopencv --enable-libx264
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
audio.aif.aif: No such file or directory

1 Answer 1


You have a double extension because you start off with

for file in *.aif

followed by

filename=$(basename "$file")

which will give you $filename with an .aif suffix. Then you do

ffmpeg -i "${filename}.aif" -i "${filename}.mp4"

So you end up with filenames with a .aif.aif and .aif.mp4 suffixes.

Instead, use basename like this:

filename="$( basename "$file" .aif )"

This will strip off the original .aif suffix from $file (see the manual for basename).

Notice that you need to double-quote all variable expansions to cope with filenames with spaces (it's a very good habit).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .