Kagami / ffmpeg.js

Port of FFmpeg with Emscripten
Other
3.29k stars 335 forks source link

Are URL inputs supported? #178

Open connorbo97 opened 2 years ago

connorbo97 commented 2 years ago

In the CLI, ffmpeg can accept a URL as the input file

ffmpeg -i http://archive.org/download/athooPhahghookoaNg4o/A%20Life%20Among%20the%20Clouds%3A%20A%20NATURE%20Short%20Film-QI25c80h0WI-nomusic.mpeg4 -ss 8 -t 1 -vf fps=1 %d.jpg

However, when I try these arguments in ffmpeg.js, it doesn't recognize the protocol. Are URL inputs not supported? Am I inputting the arguments wrong?

const ffmpeg = require('ffmpeg.js');

ffmpeg({
  arguments: [
    '-i',
    'http://archive.org/download/athooPhahghookoaNg4o/A%20Life%20Among%20the%20Clouds%3A%20A%20NATURE%20Short%20Film-QI25c80h0WI-nomusic.mpeg4',
    '-ss',
    '8',
    '-t',
    '1',
    '-vf',
    'fps=1',
    '%d.jpg',
  ],
  print: function (data) {
    stdout += data + '\n';
  },
  printErr: function (data) {
    stderr += data + '\n';
  },
  onExit: function (code) {
    console.log('Process exited with code ' + code);
    console.log(stdout);
    console.log(stderr);
  },
});

The output is

Process exited with code 1

ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers

  built with emcc (Emscripten gcc/clang-like replacement) 1.39.11

  configuration: --cc=emcc --ranlib=emranlib --enable-cross-compile --target-os=none --arch=x86 --disable-runtime-cpudetect --disable-asm --disable-fast-unaligned --disable-pthreads --disable-w32threads --disable-os2threads --disable-debug --disable-stripping --disable-safe-bitstream-reader --disable-all --enable-ffmpeg --enable-avcodec --enable-avformat --enable-avfilter --enable-swresample --enable-swscale --disable-network --disable-d3d11va --disable-dxva2 --disable-vaapi --disable-vdpau --enable-decoder=vp8 --enable-decoder=h264 --enable-decoder=vorbis --enable-decoder=opus --enable-decoder=mp3 --enable-decoder=aac --enable-decoder=pcm_s16le --enable-decoder=mjpeg --enable-decoder=png --enable-demuxer=matroska --enable-demuxer=ogg --enable-demuxer=mov --enable-demuxer=mp3 --enable-demuxer=wav --enable-demuxer=image2 --enable-demuxer=concat --enable-protocol=file --enable-filter=aresample --enable-filter=scale --enable-filter=crop --enable-filter=overlay --enable-filter=hstack --enable-filter=vstack --disable-bzlib --disable-iconv --disable-libxcb --disable-lzma --disable-sdl2 --disable-securetransport --disable-xlib --enable-zlib --enable-encoder=libvpx_vp8 --enable-encoder=libopus --enable-muxer=webm --enable-muxer=ogg --enable-muxer=null --enable-libopus --enable-libvpx --extra-cflags='-s USE_ZLIB=1 -I../libvpx/dist/include' --extra-ldflags=-L../libvpx/dist/lib

  libavutil      56. 31.100 / 56. 31.100

  libavcodec     58. 54.100 / 58. 54.100

  libavformat    58. 29.100 / 58. 29.100

  libavfilter     7. 57.100 /  7. 57.100

  libswscale      5.  5.100 /  5.  5.100

  libswresample   3.  5.100 /  3.  5.100

http://archive.org/download/athooPhahghookoaNg4o/A%20Life%20Among%20the%20Clouds%3A%20A%20NATURE%20Short%20Film-QI25c80h0WI-nomusic.mpeg4: Protocol not found

Did you mean file:http://archive.org/download/athooPhahghookoaNg4o/A%20Life%20Among%20the%20Clouds%3A%20A%20NATURE%20Short%20Film-QI25c80h0WI-nomusic.mpeg4?

Run with node v16.14.2

Foosballfan commented 1 year ago

Hey, you need to convert the video into an array buffer before passing to ffmpeg.js, e.g.:

      const vid = await fetch(url);
      const buffer = await vid.arrayBuffer();

      ffmpeg({
        MEMFS: [{ name: 'test.mp4', data: buffer }],
        arguments: [
          '-i',
          'test.mp4',
          ...