我想将正在上传的文件流式传输到ffmpeg。我正在使用node.js而且它无法正常工作!
我最终测试了从本地文件输入到ffmpeg的输入,这也不起作用。这是我的代码:
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);
我得到的输出是
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
我尝试按照错误代码和this问题的建议设置-pix_fmt
选项或-analyzeduration
和-probesize
,但无济于事。
然而ffmpeg -i pathToLocalMP4File -y -f mp4 -pix_fmt yuv420p -vcodec libx264 -vf scale=-1:720 -f mp4 localPathToResultFile
在终端中完美运作......
任何想法??