fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.96k stars 881 forks source link

Error: Input format lavfi is not available #1282

Open fa0311 opened 5 months ago

fa0311 commented 5 months ago

Version information

Code to reproduce

import { default as ffmpeg, default as ffprobe } from "fluent-ffmpeg";
const command = ffmpeg();
command.input("anullsrc=channel_layout=mono:sample_rate=44100");
command.inputFormat("lavfi");
command.addOption("-t", "20");
command.output("test.mp4")
command.run();

(note: if the problem only happens with some inputs, include a link to such an input file)

Expected results

Observed results

Error: Input format lavfi is not available

Temporary workaround

// TypeScript
const bypass = (command: ffmpeg.FfmpegCommand) => {
    const bk = command.availableFormats;
    command.availableFormats = (cb: (err: any, data: any) => void) => {
      bk.bind(command)((err, data) => {
        const lavfi = {
          canDemux: true,
          canMux: true,
          description: "Lavfi",
        };
        cb(err, { ...data, lavfi });
      });
    };
  }

Checklist

stepin commented 1 month ago

capabilities.js parses formats from ffmpeg -formats output. It uses regexp https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/lib/capabilities.js#L18 :

var formatRegexp = /^\s*([D ])([E ])\s+([^ ]+)\s+(.*)$/;

So, it skips all device related formats including lavfi:

~$ ffmpeg -formats|egrep '[E ]d '
ffmpeg version 7.1 Copyright (c) 2000-2024 the FFmpeg developers
  built with Apple clang version 15.0.0 (clang-1500.3.9.4)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/7.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  libavutil      59. 39.100 / 59. 39.100
  libavcodec     61. 19.100 / 61. 19.100
  libavformat    61.  7.100 / 61.  7.100
  libavdevice    61.  3.100 / 61.  3.100
  libavfilter    10.  4.100 / 10.  4.100
  libswscale      8.  3.100 /  8.  3.100
  libswresample   5.  3.100 /  5.  3.100
  libpostproc    58.  3.100 / 58.  3.100
  Ed audiotoolbox    AudioToolbox output device
 D d avfoundation    AVFoundation input device
 D d lavfi           Libavfilter virtual input device
  Ed sdl,sdl2        SDL2 output device
 D d x11grab         X11 screen capture, using XCB

It's quite easy to fix regexp:

var formatRegexp = /^\s*([D ])([E ])([d ])\s+([^ ]+)\s+(.*)$/;

but I don't know idea behind current behaviour: if it's just a bug or way to filter out some formats.

PS. About workaround above: lavfi can demux but can't mux. So, it's better to use:

        const lavfi = {
          canDemux: true,
          canMux: false,
          description: "Libavfilter virtual input device",
        };
stepin commented 1 month ago

Some more device formats (from Linux):

stepin commented 1 month ago

Looks like it's related to ffmpeg 7 changes and in latest release of this library there were try to fix but a bit incorrect (current code skips all device formats).

A better solution: https://github.com/alexger/node-fluent-ffmpeg/commit/bca837e2577d760089e94ca3fc85f1e158e0b77d

And there is MR: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/pull/1276

tokenosopher commented 1 month ago

Can this be merged?

Looks like it's related to ffmpeg 7 changes and in latest release of this library there were try to fix but a bit incorrect (current code skips all device formats).

A better solution: alexger@bca837e

And there is MR: #1276

Can this be merged? This fixed my issue, which weirdly enough started sporadically

JamieS1211 commented 1 month ago

Bypass worked for me but would be great if this could be merged and sort the issue out long term

LorDisturbia commented 2 weeks ago

The same problem prevents you from setting x11grab and pulse as inputs, but it can be fixed with the same workaround.

I'd love to see https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/pull/1276 merged and released.