fluent-ffmpeg / node-fluent-ffmpeg

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

`pipe:0: Input/output error` when input is a `Buffer` and resizing gif #1157

Closed DetachHead closed 2 years ago

DetachHead commented 2 years ago

the gif: https://i.stack.imgur.com/kNTGR.gif

Version information

Code to reproduce

import ffmpeg from 'fluent-ffmpeg'
import fs from 'fs'
import { Readable } from 'stream'

const inputBuffer = fs.readFileSync('test/input.gif')
const outputPath = 'test/output.gif'

//pipe:0: Input/output error:
ffmpeg(Readable.from(inputBuffer))
//no error (uncomment this line):
// ffmpeg(outputPath)
    .output(outputPath)
    .addInputOptions('-hide_banner', '-v', 'warning')
    //https://superuser.com/a/1362406
    .complexFilter([
        '[0:v] scale=320:-1:flags=lanczos,split [a][b]',
        '[a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]',
        '[b][p] paletteuse',
    ])
    .on('error', console.error)
    .on('start', console.log)
    .on('stderr', console.error)
    .on('end', console.log)
    .run()

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

Expected results

no error and gif is resized successfully

Observed results

the following error in stderr

pipe:0: Input/output error

the gif is resized but no longer animated

Checklist

federicocarboni commented 2 years ago

When streaming images to ffmpeg you must specify the format: try to add -f gif_pipe to input arguments.

DetachHead commented 2 years ago

@FedericoCarboni doesn't work, i get this error: Unknown input format: 'gif_pipe'

root@7f6faec91604:/workspace/test# curl https://i.stack.imgur.com/kNTGR.gif | ffmpeg -f gif_pipe -i pipe:0 output.gif
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0ffmpeg version 4.1.6-1~deb10u1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Unknown input format: 'gif_pipe'
  0  699k    0  5350    0     0   4300      0  0:02:46  0:00:01  0:02:45  4297
curl: (23) Failed writing body (157 != 1411)

though this may not actually be a fluent-ffmpeg issue as i previously thought, i thought i hadthis working on the command line yesterday when i raised this but now it's doing the same thing, so perhaps this issue can be closed

regardless, any idea what i'm doing wrong? i'm pretty new to ffmpeg so forgive me if i'm doing something obviously wrong but i couldn't find any info on google

federicocarboni commented 2 years ago

curl https://i.stack.imgur.com/kNTGR.gif | ffmpeg -f gif_pipe -i pipe:0 output.gif actually works as intended on my machine... I guess the issue could be the build of ffmpeg you're using (though I'm not an expert in ffmpeg's compile options). However, I think it's clear this is not an issue with fluent-ffmpeg.