I'm trying to convert all the songs in a folder from flac to alac. All the files in the folder are flac.
What I'm writing:
FORFILES /M *.* /C "ffmpeg -i @fname.flac -c:v copy -c:a alac @fname.m4a"
And the error:
ffmpeg version 2022-01-13-git-c936c319bd-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11.2.0 (Rev5, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 57. 18.100 / 57. 18.100
libavcodec 59. 20.100 / 59. 20.100
libavformat 59. 17.100 / 59. 17.100
libavdevice 59. 5.100 / 59. 5.100
libavfilter 8. 25.100 / 8. 25.100
libswscale 6. 5.100 / 6. 5.100
libswresample 4. 4.100 / 4. 4.100
libpostproc 56. 4.100 / 56. 4.100
Output #0, flac, to '01 リビングデッド・ユース.flac':
Output file #0 does not contain any stream
The forfiles
command is a nasty beast, because there are several caveats:
/M *.*
does not match all files but only such with an extension; to really match all files, use /M *
or skip it since it is the default anyway;\
, like the root directory of a drive /P "D:\"
, which causes a syntax error since the closing quotation mark is considered as escaped; to work around that, preferably append a .
like /P "D:\."
, or remove the quotation marks like /P D:\
, though this exposes potential whitespaces or special characters to the parser;@
-variables that return the path and/or name of iterated items provide the values in quoted manner, which is particularly frustrating when it comes to concatenation;@isdir
variable, but you will need an if
statement for this (like if @isdir==FALSE
or if @isdir==TRUE
), which is an internal cmd.exe
command, requiring its explicit instantiation even when you would not need it else;/C
and its arguments is terribly implemented, leading to the problem that directly running external commands (so without cmd /C
) may fail, unless you are aware of the mostly working fix by stating the command name twice (like /C "command.exe command.exe --parameter argument"
);/D
option (which is the only reason why forfiles
might suit better than for
) to filter for the relative last modification date (but not time) is badly implemented when a positive number (like /D +1
) is used, because this uselessly points to the future;All of these issues lead me to the point that I suggest not to use forfiles
and to use a standard for
loop instead, like this (note also the changed mask *.flac
):
In a batch-file:
rem // Loop through all `*.flac` files in the current working directory:
for %%I in ("*.flac") do (
rem // The `~`-modifiers remove quotes and extract path/name parts:
ffmpeg -i "%%~I" -c:v copy -c:a alac "%%~nI.m4a"
)
In cmd:
for %I in ("*.flac") do @ffmpeg -i "%~I" -c:v copy -c:a alac "%~nI.m4a"
The ~n
-modifier expands to the base name with the extension .flac
removed.
If you do insist in using forfiles
, then apply it like this:
forfiles /M "*.flac" /C "ffmpeg ffmpeg -i @file -c:v copy -c:a alac @fname.m4a"
This actually specifies for the output file a quoted base name followed by the new extension, like "video".m4a
, for example, though there seems to be some kind of auto-correction involved so that such a name is accepted.