I want to stream a file that is being uploaded to ffmpeg. I'm using node.js and it's not working!
I ended up testing piping an input to ffmpeg from a local file, and this doens't work either. Here's my code:
var processVideo = function(videoStream, resultPath) {
var cmdParams = [
'-i', '-',
'-y',
'-f', 'mp4',
'-vcodec', 'libx264',
'-vf', 'scale=-1:720',
'-f', 'mp4',
resultPath
];
var ffmpeg = child_process.spawn('ffmpeg', cmdParams);
var data = '';
ffmpeg.stdout
.on('data', function(chunk) { data += chunk; })
.on('end', function() { console.log('result', data); });
var err = '';
ffmpeg.stderr
.on('data', function(chunk) { err += chunk; })
.on('end', function() { console.log('error', err);});
videoStream.pipe(ffmpeg.stdin);
};
processVideo(fs.createReadStream(pathToLocalMP4File), localPathToResultFile);
The output I get is
error ffmpeg version 2.8 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 7.0.0 (clang-700.1.76)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8 --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-libvo-aacenc --enable-libxvid --enable-libtheora --enable-vda
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd1e2802a00] stream 0, offset 0x20: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd1e2802a00] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1920x1080, 16242 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:':
Metadata:
major_brand : mp42
minor_version : 537134592
compatible_brands: mp42
creation_time : 2015-12-26 12:47:49
Duration: 00:00:04.00, bitrate: N/A
Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 1920x1080, 16242 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 60k tbc (default)
Metadata:
creation_time : 2015-12-26 12:47:49
encoder : AVC Coding
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 46 kb/s (default)
Metadata:
creation_time : 2015-12-26 12:47:49
[buffer @ 0x7fd1e1c08e20] Unable to parse option value "-1" as pixel format
Last message repeated 1 times
[buffer @ 0x7fd1e1c08e20] Error setting option pix_fmt to value -1.
[graph 0 input from stream 0:0 @ 0x7fd1e1c08f60] Error applying options to the filter.
Error opening filters!
result
I tried to set the -pix_fmt
option, or -analyzeduration
and -probesize
as suggested by the error code and this question, to no avail.
However ffmpeg -i pathToLocalMP4File -y -f mp4 -pix_fmt yuv420p -vcodec libx264 -vf scale=-1:720 -f mp4 localPathToResultFile
works perfectly in the terminal...
Any idea??