英文:
Converted video is not played in Firefox
问题
我有一个接受来自客户端的视频文件并将其转换为.mp4
扩展名后保存在服务器上的代码。视频处理使用fluent-ffmpeg
进行。以下是代码:
ffmpeg(<SOURCE_FILE>)
.size('360x?')
.videoCodec('libx264')
.output(<TARGET_FILE>)
.on("end", () => {
console.log(`Video saved with resolution 360`);
res.json('Uploaded')
})
.on("error", (error) => {
console.error(
`Error saving video with resolution 360:`,
error
);
res.status(500).json({ message: "Conversion error" });
})
.run();
问题是生成的文件在Firefox浏览器中无法播放(但在Microsoft Edge和Google Chrome中可以播放)。是否可以更改参数以使生成的文件与Firefox浏览器兼容?
英文:
I have a code that accepts the video file from the client converts it and saves it on the server with .mp4
extension. Video processing is made using fluent-ffmpeg
. Here is the code:
ffmpeg(<SOURCE_FILE>)
.size('360x?')
.videoCodec('libx264')
.output(<TARGET_FILE>)
.on("end", () => {
console.log(`Video saved with resolution 360`);
res.json('Uploaded')
})
.on("error", (error) => {
console.error(
`Error saving video with resolution 360:`,
error
);
res.status(500).json({ message: "Conversion error" });
})
.run();
The problem is that the resulting files are not played in the Firefox browser (but work in Microsoft Edge and Google Chrome).
Is it possible to change the parameters so that the resulting files are compatible with Firefox browser?
答案1
得分: 1
你的代码在Firefox 115.0.2上对我有效。然而,显然有一个通用解决方法,使用-pix_fmt yuv420p
:
ffmpeg(<SOURCE_FILE>)
.size('360x?')
.videoCodec('libx264')
.outputOptions('-pix_fmt yuv420p')
.output(<TARGET_FILE>)
// ...
英文:
Your code works for me on Firefox 115.0.2. <br>
However, apparently there is a general workaround by using -pix_fmt yuv420p
:
ffmpeg(<SOURCE_FILE>)
.size('360x?')
.videoCodec('libx264')
.outputOptions('-pix_fmt yuv420p')
.output(<TARGET_FILE>)
// ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论