UNPKG

1.15 kBJavaScriptView Raw
1import path from "node:path";
2
3import request from "./request.js";
4
5/**
6 * Download community FFmpeg binary from `https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt`.
7 *
8 * @param {string} downloadUrl - Download server
9 * @param {string} version - Runtime version
10 * @param {string} platform - NW supported platform
11 * @param {string} arch - NW supported architecture
12 * @param {string} cacheDir - Directory to store FFmpeg binary
13 * @return {Promise<string>} Path of compressed file which containscommunity FFmpeg binary.
14 */
15export default async function ffmpeg(downloadUrl, version, platform, arch, cacheDir) {
16
17 /**
18 * URL to download specific FFmpeg binary from.
19 *
20 * @type {string}
21 */
22 const url = [
23 downloadUrl,
24 version,
25 `${version}-${platform}-${arch}.zip`,
26 ].join('/');
27
28 /**
29 * Absolute path of compressed file which contains FFmpeg binary.
30 */
31 const ffmpegFileAbs = path.resolve(
32 cacheDir,
33 `ffmpeg-${version}-${platform}-${arch}.zip`,
34 );
35 await request(url, ffmpegFileAbs);
36
37 return ffmpegFileAbs;
38}