gpt4 book ai didi

node.js - node fluent-ffmpeg流输出错误码1

转载 作者:搜寻专家 更新时间:2023-10-31 23:30:53 25 4
gpt4 key购买 nike

完全按照文档,我尝试使用流将视频转换写入文件。

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 });

当我使用 .saveToFile() 时,此转换工作完美,但返回

An error occurred: ffmpeg exited with code 1

当我运行这段代码时。我在 Windows 8.1 64 位上使用来自 here 的 64 位 ffmpeg 构建.

最佳答案

我今天遇到了同样的问题(也是在同一个平台上)

这就像当你流式传输时你必须指定一种格式但你不能指定 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');
});

关于node.js - node fluent-ffmpeg流输出错误码1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23188782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com