Explorar o código

Add documentation about ffmpeg

https://alexandercleasby.dev/blog/use-ffmpeg-electron
Manav Rathi hai 1 ano
pai
achega
bb865a7b15
Modificáronse 3 ficheiros con 31 adicións e 1 borrados
  1. 7 0
      desktop/electron-builder.yml
  2. 4 1
      desktop/src/preload.ts
  3. 20 0
      desktop/src/services/ffmpeg.ts

+ 7 - 0
desktop/electron-builder.yml

@@ -31,6 +31,13 @@ mac:
     hardenedRuntime: true
     x64ArchFiles: Contents/Resources/ggmlclip-mac
 afterSign: electron-builder-notarize
+# When Electron packages our node_modules, they go into the ASAR archive. This
+# is not what we want for the FFMPEG binaries though, and instead put them
+# outside of the ASAR archive so that we can get at a direct path to these files
+# when trying to run it.
+#
+# The filtering by `${os}` and `${arch}` is to include only the binaries for the
+# os/arch combination that we're bundling.
 asarUnpack:
     - node_modules/ffmpeg-static/bin/${os}/${arch}/ffmpeg
     - node_modules/ffmpeg-static/index.js

+ 4 - 1
desktop/src/preload.ts

@@ -385,7 +385,7 @@ setupLogging();
 // [Note: Transferring large amount of data over IPC]
 //
 // Electron's IPC implementation uses the HTML standard Structured Clone
-// Algorithm to serialize objects passed between processes. [1]
+// Algorithm to serialize objects passed between processes.
 // https://www.electronjs.org/docs/latest/tutorial/ipc#object-serialization
 //
 // In particular, both ArrayBuffer and the web File types are eligible for
@@ -406,6 +406,9 @@ setupLogging();
 // copying, the IPC should be fast enough for even moderately large data:
 // https://github.com/electron/electron/issues/1948#issuecomment-864191345
 //
+// The main problem with transfering large amounts of data is potentially
+// running out of memory, causing the app to crash as it copies it over across
+// the processes.
 contextBridge.exposeInMainWorld("ElectronAPIs", {
     exists,
     checkExistsAndCreateDir,

+ 20 - 0
desktop/src/services/ffmpeg.ts

@@ -20,6 +20,26 @@ function getFFmpegStaticPath() {
     return pathToFfmpeg.replace("app.asar", "app.asar.unpacked");
 }
 
+/**
+ * Run a ffmpeg command
+ *
+ * [Note: FFMPEG in Electron]
+ *
+ * There is a wasm build of FFMPEG, but that is currently 10-20 times slower
+ * that the native build. That is slow enough to be unusable for our purposes.
+ * https://ffmpegwasm.netlify.app/docs/performance
+ *
+ * So the alternative is to bundle a ffmpeg binary with our app. e.g.
+ *
+ *     yarn add fluent-ffmpeg ffmpeg-static ffprobe-static
+ *
+ * (we only use ffmpeg-static, the rest are mentioned for completeness' sake).
+ *
+ * Interestingly, Electron already bundles an ffmpeg library (it comes from the
+ * ffmpeg fork maintained by Chromium).
+ * https://chromium.googlesource.com/chromium/third_party/ffmpeg
+ * https://stackoverflow.com/questions/53963672/what-version-of-ffmpeg-is-bundled-inside-electron
+ */
 export async function runFFmpegCmd(
     cmd: string[],
     inputFilePath: string,