fluent-ffmpeg / node-fluent-ffmpeg

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

Cannot pass readable stream from incoming HTTP request #839

Open viktorstaikov opened 6 years ago

viktorstaikov commented 6 years ago

Version information

Context

I'm trying to develop a service that puts watermark on videos. I have the logo locally on the server. I'm guaranteed that the videos will be mp4 and I must return mp4 as well.

Code to reproduce

app.post('/upload', (req, res, next) => {
  const form = new multiparty.Form();

  form.parse(req, function(err, fields, files) {});
  form.on('file', function(name, file) {
    const inputStream = fs.createReadStream(file.path);

    ffmpeg(inputStream)
      .inputFormat('mp4')
      .input('./logo.png')
      .complexFilter(['overlay=10:10'])
      .videoCodec('libx264')
      .outputFormat('mp4')
      .outputOptions('-movflags frag_keyframe+empty_moov')
      .on('start', commandLine => {
        console.log('Spawned Ffmpeg with command: ' + commandLine);
      })
      .on('progress', progress => {
        console.log('Processing: ' + progress.percent + '% done');
      })
      .on('error', (err, stdout, stderr) => {
        console.error(stderr, err);
      })
      .pipe(res, { end: true });
  });
});

Error

ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f928d000000] stream 1, offset 0x30: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f928d000000] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720, 2914 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.19.104
  Duration: 00:00:22.04, bitrate: N/A
    Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), none, 1280x720, 2914 kb/s, 29.06 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, png_pipe, from './logo.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 440x250, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 (h264) -> overlay:main (graph 0)
  Stream #1:0 (png) -> overlay:overlay (graph 0)
  overlay (graph 0) -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f928d000000] stream 1, offset 0x30: partial file
pipe:0: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
Conversion failed!

P. S.

I have also tried using local mp4 video to generate the input stream like so:

    const inputStream = fs.createReadStream('./dummy-video.mp4');

P. P. S.

The .videoCodec() and .outputOptions() lines are from similarly sounding issues I have found in this repo. They are NOT part of my requirements.

P. P. P. S.

Running the command ffmpeg -i video.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4 in the terminal successfully sets the watermark.

ahmed-sharief5 commented 6 years ago

s3 bucket signed url is not working its showing 'No such file or directory'

viktorstaikov commented 6 years ago

Hi,

The url itself is valid and I can open the video there. Where did you see this s3 error?

ahmed-sharief5 commented 6 years ago

Please refer this url https://stackoverflow.com/questions/51946375/ffmpeg-for-aws-s3-bucket-signed-url-not-working-in-node-js

mranosa commented 5 years ago

where you able to solve this?

federicocarboni commented 4 years ago

Same as #932