Jac*_*Guy 3 ffmpeg stream node.js
完全遵循文档,我正在尝试使用流将视频转换写入文件.
var FFmpeg = require('fluent-ffmpeg');
var fs = require('fs');
var outStream = fs.createWriteStream('C:/Users/Jack/Videos/test.mp4');
new FFmpeg({ source: 'C:/Users/Jack/Videos/video.mp4' })
.withVideoCodec('libx264')
.withAudioCodec('libmp3lame')
.withSize('320x240')
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function() {
console.log('Processing finished !');
})
.writeToStream(outStream, { end: true });
Run Code Online (Sandbox Code Playgroud)
当我使用.saveToFile()时,这种转换非常有效,但会返回
发生错误:ffmpeg退出代码1
当我运行此代码时.我在Windows上使用的是64位的ffmpeg构建从8.1 64位在这里.
我今天遇到了同样的问题(也在同一平台上)
就像你在流式传输时必须指定一种格式但是你不能指定mp4因为它无效
我最终得到了这个,我认为这是一个很好的解决方法,我希望它有所帮助:
var input_file = fs.createReadStream(path);
input_file.on('error', function(err) {
console.log(err);
});
var output_path = 'tmp/output.mp4';
var output_stream = fs.createWriteStream('tmp/output.mp4');
var ffmpeg = child_process.spawn('ffmpeg', ['-i', 'pipe:0', '-f', 'mp4', '-movflags', 'frag_keyframe', 'pipe:1']);
input_file.pipe(ffmpeg.stdin);
ffmpeg.stdout.pipe(output_stream);
ffmpeg.stderr.on('data', function (data) {
console.log(data.toString());
});
ffmpeg.stderr.on('end', function () {
console.log('file has been converted succesfully');
});
ffmpeg.stderr.on('exit', function () {
console.log('child process exited');
});
ffmpeg.stderr.on('close', function() {
console.log('...closing time! bye');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7201 次 |
| 最近记录: |