转换后的视频在Firefox中无法播放。

huangapple go评论86阅读模式
英文:

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(&lt;SOURCE_FILE&gt;)
  .size(&#39;360x?&#39;)
  .videoCodec(&#39;libx264&#39;)
  .output(&lt;TARGET_FILE&gt;)
  .on(&quot;end&quot;, () =&gt; {
    console.log(`Video saved with resolution 360`);
    res.json(&#39;Uploaded&#39;)
  })
  .on(&quot;error&quot;, (error) =&gt; {
    console.error(
      `Error saving video with resolution 360:`,
      error
    );
    res.status(500).json({ message: &quot;Conversion error&quot; });
  })
  .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(&lt;SOURCE_FILE&gt;)
  .size(&#39;360x?&#39;)
  .videoCodec(&#39;libx264&#39;)
  .outputOptions(&#39;-pix_fmt yuv420p&#39;)
  .output(&lt;TARGET_FILE&gt;)
  // ...
英文:

Your code works for me on Firefox 115.0.2. <br>
However, apparently there is a general workaround by using -pix_fmt yuv420p:

ffmpeg(&lt;SOURCE_FILE&gt;)
  .size(&#39;360x?&#39;)
  .videoCodec(&#39;libx264&#39;)
  .outputOptions(&#39;-pix_fmt yuv420p&#39;)
  .output(&lt;TARGET_FILE&gt;)
  // ...

huangapple
  • 本文由 发表于 2023年7月20日 15:00:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76727395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定