fluent-ffmpeg / node-fluent-ffmpeg

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

streamBuffers input/output #704

Closed pawanvivekananda closed 6 years ago

pawanvivekananda commented 7 years ago

Version information

Code to reproduce

    const request = require('request');
    let requestSettings = {
        url: 'http://techslides.com/demos/sample-videos/small.mp4',
        encoding: null
    };
    const streamBuffers = require('stream-buffers');
    let myReadableStreamBuffer = new streamBuffers.ReadableStreamBuffer({
        frequency: 10,       // in milliseconds.
        chunkSize: 2048     // in bytes.
    });

    let myWritableStreamBuffer = new streamBuffers.WritableStreamBuffer({
        initialSize: (100 * 1024),   // start at 100 kilobytes.
        incrementAmount: (10 * 1024) // grow by 10 kilobytes each time buffer overflows.
    });

    request(requestSettings, function (error, response, body) {

        if (!error && response.statusCode == 200) {
            let data = new Buffer(body, 'binary');
            myReadableStreamBuffer.put(data);
            myReadableStreamBuffer.stop();
            console.log(data);
            save()
            // callback(null, data);
        } else {
            console.log(error, response.statusCode)
            // callback(error)
        }
    });
    save = (data) => {
        ffmpeg()
        .input(myReadableStreamBuffer)
        .on('start', function(commandLine) {
            console.log('Spawned Ffmpeg with command: ' + commandLine);
        })
        .on('error', function(err, stdout, stderr) {
        //   console.log('ffmpeg stdout: ' + stdout);
          console.log('ffmpeg stderr: ' + stderr);
        })
        .on('end', function() {
            let buffer = myWritableStreamBuffer.getContents();
            myWritableStreamBuffer.end();
            console.log('ended', buffer);
          })
        // .audioCodec('libfaac')
        // .videoCodec('libx264')
        // .on('stderr', function(stderrLine) {
        // console.log('Stderr output: ' + stderrLine);
        // })
        // .on('codecData', function(data) {
        // console.log('Input is ' + data.audio + ' audio ' +
        //   'with ' + data.video + ' video');
        // })
        .toFormat('mp4')
        .writeToStream(myWritableStreamBuffer);;
    }

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

Expected results

 Need to get buffer output 

Observed results

ffmpeg stderr: ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 7.0.2 (clang-700.1.81)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-vda
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fa8a6000000] stream 0, offset 0xa8: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fa8a6000000] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none(bt709), 560x320, 465 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     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.57, bitrate: N/A
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none(bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : JVT/AVC Coding
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
[buffer @ 0x7fa8a54113c0] Unable to parse option value "-1" as pixel format
    Last message repeated 1 times
[buffer @ 0x7fa8a54113c0] Error setting option pix_fmt to value -1.
[graph 0 input from stream 0:0 @ 0x7fa8a54114c0] Error applying options to the filter.
Error opening filters!

Checklist

njoyard commented 7 years ago
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fa8a6000000] stream 0, offset 0xa8: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fa8a6000000] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none(bt709), 560x320, 465 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options

Ffmpeg seems unable to find codec information in your stream. Maybe try passing the input format and codec.

rhodgkins commented 7 years ago

@pawanvivekananda to output mp4 as a stream you'll need to add the flags for fast start:

.outputOptions([
    '-movflags frag_keyframe+empty_moov',
    '-movflags +faststart'
])
.toFormat('mp4')
ip commented 7 years ago

The problem is probably with how MP4 container is arranged. This answer helped me: https://stackoverflow.com/a/40028894/4027465

njoyard commented 6 years ago

@rhodgkins gave the correct answer I think, reopen if needed.