我想在 iOS 中支持 webm 文件,但 iOS 不支持这种格式播放视频。我什至尝试通过 HTML5 视频标签播放它,但 safari 不支持 HTML5 视频标签中的 webm 格式,这意味着我也无法通过 UIWebView 使其工作。但我已经看到一个应用程序在他们的媒体播放器中支持这种格式,这意味着应该有某种方法。
提前感谢您的帮助!
以编程方式,您必须使用后端将 webm 转换为 mp4。使用一些 ffmpeg 库。在 Node.js 中,最好使用 Fluent-ffmpeg。以下是示例代码。
const ffmpegPath = require("@ffmpeg-installer/ffmpeg").path;
const ffmpeg = require("fluent-ffmpeg");
const fs = require("fs");
ffmpeg.setFfmpegPath(ffmpegPath);
// Input and output file paths
const inputFilePath =
"input/file/path/or/url.mp4";
const outputFilePath = "output/file/path";
// Create a FFmpeg command
const command = ffmpeg();
// Set input file
command.input(inputFilePath);
// Set video codec to libx264 (MP4)
command.videoCodec("libx264");
// Set fps (30 makes the conversion fast)
ommand.outputFPS(30);
// Set output file
command.output(outputFilePath);
// Run the conversion
command
.on("end", () => {
console.log("Conversion finished.");
})
.on("error", (err, stdout, stderr) => {
console.error("Error:", err);
console.error("ffmpeg stdout:", stdout);
console.error("ffmpeg stderr:", stderr);
})
.run();