From cf950a81f7919f8a4889934978c0fbb8dcf79e4a Mon Sep 17 00:00:00 2001 From: WakelessSloth56 Date: Sun, 27 Oct 2024 10:03:20 +0800 Subject: [PATCH 1/3] fix: fix wasm plugin option muxWithMetadata --- registry/lib/plugins/video/download/wasm-output/Config.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/lib/plugins/video/download/wasm-output/Config.vue b/registry/lib/plugins/video/download/wasm-output/Config.vue index 0934be6e4f..09862e113b 100644 --- a/registry/lib/plugins/video/download/wasm-output/Config.vue +++ b/registry/lib/plugins/video/download/wasm-output/Config.vue @@ -33,7 +33,7 @@ export default Vue.extend({ }, methods: { saveOptions() { - options.muxWithMetadata = this.muxExtraAssets + options.muxWithMetadata = this.muxWithMetadata Object.assign(storedOptions, options) }, }, From cb7df01bdf3216d45ef1c85d54a129c6e0c67b93 Mon Sep 17 00:00:00 2001 From: WakelessSloth56 Date: Sun, 27 Oct 2024 10:41:38 +0800 Subject: [PATCH 2/3] feat: wasm plugin deleteFile message --- .../video/download/wasm-output/ffmpeg.ts | 21 +++++++++++++++++++ .../video/download/wasm-output/handler.ts | 13 +++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts b/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts index 5f991c0ba1..04d025239d 100644 --- a/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts +++ b/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts @@ -17,6 +17,7 @@ enum FFMessageType { EXEC = 'EXEC', WRITE_FILE = 'WRITE_FILE', READ_FILE = 'READ_FILE', + DELETE_FILE = 'DELETE_FILE', ERROR = 'ERROR', } @@ -38,6 +39,7 @@ export class FFmpeg { case FFMessageType.EXEC: case FFMessageType.WRITE_FILE: case FFMessageType.READ_FILE: + case FFMessageType.DELETE_FILE: this.#resolves[id](data) break case FFMessageType.ERROR: @@ -140,6 +142,20 @@ export class FFmpeg { undefined, signal, ) as Promise + + public deleteFile = (path: string, signal?: AbortSignal) => + this.#send( + { + type: FFMessageType.DELETE_FILE, + data: { path }, + }, + undefined, + signal, + ) as Promise + + public onProgress(callback: (event: ProgressEvent) => void): void { + this.#progressEventCallback = callback + } } // ========================================================================== // @@ -165,11 +181,16 @@ interface FFMessageReadFileData { encoding: string } +interface FFMessageDeleteFileData { + path: string +} + type FFMessageData = | FFMessageLoadConfig | FFMessageExecData | FFMessageWriteFileData | FFMessageReadFileData + | FFMessageDeleteFileData interface Message { type: string diff --git a/registry/lib/plugins/video/download/wasm-output/handler.ts b/registry/lib/plugins/video/download/wasm-output/handler.ts index 7d6842e1cf..256c2612e6 100644 --- a/registry/lib/plugins/video/download/wasm-output/handler.ts +++ b/registry/lib/plugins/video/download/wasm-output/handler.ts @@ -59,13 +59,13 @@ async function single( httpGet(audioUrl, progress(1, '正在下载音频流')), ]) - ffmpeg.writeFile('video', video) - ffmpeg.writeFile('audio', audio) + await ffmpeg.writeFile('video', video) + await ffmpeg.writeFile('audio', audio) const args = ['-i', 'video', '-i', 'audio'] if (ffmetadata) { - ffmpeg.writeFile('ffmetadata', new TextEncoder().encode(ffmetadata)) + await ffmpeg.writeFile('ffmetadata', new TextEncoder().encode(ffmetadata)) args.push('-i', 'ffmetadata', '-map_metadata', '2') if (!outputMkv) { args.push('-movflags', '+use_metadata_tags') @@ -87,6 +87,13 @@ async function single( toast.message = '完成!' toast.duration = 1000 + await Promise.all([ + ffmpeg.deleteFile('video'), + ffmpeg.deleteFile('audio'), + ffmpeg.deleteFile('output'), + ffmetadata ? ffmpeg.deleteFile('ffmetadata') : Promise.resolve(), + ]) + await DownloadPackage.single( name.replace(/.[^/.]+$/, `.${outputMkv ? 'mkv' : 'mp4'}`), outputBlob, From 30ec155fa8a37c23afe7bc8f5a0cb62aff615b6f Mon Sep 17 00:00:00 2001 From: WakelessSloth56 Date: Sun, 27 Oct 2024 10:42:22 +0800 Subject: [PATCH 3/3] feat: wasm plugin progress event --- .../plugins/video/download/wasm-output/ffmpeg.ts | 15 ++++++++++++++- .../plugins/video/download/wasm-output/handler.ts | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts b/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts index 04d025239d..f02e78d346 100644 --- a/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts +++ b/registry/lib/plugins/video/download/wasm-output/ffmpeg.ts @@ -19,6 +19,7 @@ enum FFMessageType { READ_FILE = 'READ_FILE', DELETE_FILE = 'DELETE_FILE', ERROR = 'ERROR', + PROGRESS = 'PROGRESS', } export class FFmpeg { @@ -26,6 +27,8 @@ export class FFmpeg { #resolves: Callbacks = {} #rejects: Callbacks = {} + #progressEventCallback: (event: ProgressEvent) => void + public loaded = false #registerHandlers = () => { @@ -42,6 +45,11 @@ export class FFmpeg { case FFMessageType.DELETE_FILE: this.#resolves[id](data) break + case FFMessageType.PROGRESS: + if (this.#progressEventCallback) { + this.#progressEventCallback(data) + } + break case FFMessageType.ERROR: this.#rejects[id](data) break @@ -197,7 +205,12 @@ interface Message { data?: FFMessageData } -type CallbackData = Uint8Array | string | boolean | Error | undefined +interface ProgressEvent { + progress: number + time: number +} + +type CallbackData = Uint8Array | string | boolean | Error | ProgressEvent | undefined interface Callbacks { [id: number | string]: (data: CallbackData) => void diff --git a/registry/lib/plugins/video/download/wasm-output/handler.ts b/registry/lib/plugins/video/download/wasm-output/handler.ts index 256c2612e6..4be359a0dd 100644 --- a/registry/lib/plugins/video/download/wasm-output/handler.ts +++ b/registry/lib/plugins/video/download/wasm-output/handler.ts @@ -2,6 +2,7 @@ import { DownloadPackage, PackageEntry } from '@/core/download' import { meta } from '@/core/meta' import { getComponentSettings } from '@/core/settings' import { Toast } from '@/core/toast' +import { formatPercent } from '@/core/utils/formatters' import { title as pluginTitle } from '.' import type { Options } from '../../../../components/video/download' import { DownloadVideoAction } from '../../../../components/video/download/types' @@ -76,7 +77,9 @@ async function single( console.debug('FFmpeg commandline args:', args.join(' ')) - toast.message = '混流中……' + ffmpeg.onProgress(event => { + toast.message = `混流中: ${formatPercent(event.progress)}` + }) await ffmpeg.exec(args) const output = await ffmpeg.readFile('output')