简体   繁体   中英

ffmpeg error "output file #0 does not contain any stream" with FORFILE on command prompt

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:

  • it is slow (particularly because it cannot run internal commands of the hosting command prompt);
  • it handles wildcards differently than most other commands, hence /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;
  • it applies backslash-escaping, which is particularly annoying with paths ending in \ , 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 /PD:\ , though this exposes whitespaces or special characters to the parser;
  • all of the special @ -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;
  • iterates over both files and directories that match the given mask; to distinguish between them you could use the special @isdir variable, but you will need an if statement for this, which is an internal cmd.exe command, requiring its explicit instantiation even when you would not need it else;
  • handling of the command behind /C is terribly implemented, leading to the problem that directly running external commands (so without cmd /C ) fails, unless you are aware of the mostly working fix by stating the command name twice (like /C "command.exe command.exe --parameter argument" );
  • even its basically nice /D option 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 this 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 ):

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"
)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM