mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-04 02:50:59 +08:00
feat(frontend/vditor): 实现基于 FFmpeg.wasm 的视频压缩功能
- 添加视频压缩相关配置和工具函数 - 实现 FFmpeg.wasm 初始化和视频压缩功能 - 优化文件上传流程,支持视频文件压缩
This commit is contained in:
37
frontend_nuxt/plugins/ffmpeg.client.ts
Normal file
37
frontend_nuxt/plugins/ffmpeg.client.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { FFmpeg } from '@ffmpeg/ffmpeg'
|
||||
import { toBlobURL } from '@ffmpeg/util'
|
||||
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
|
||||
|
||||
let ffmpeg: FFmpeg | null = null
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const {
|
||||
public: { ffmpegVersion },
|
||||
} = useRuntimeConfig()
|
||||
|
||||
return {
|
||||
provide: {
|
||||
ffmpeg: async () => {
|
||||
if (ffmpeg) return ffmpeg
|
||||
|
||||
ffmpeg = new FFmpeg()
|
||||
|
||||
const mtOk =
|
||||
typeof crossOriginIsolated !== 'undefined' &&
|
||||
crossOriginIsolated &&
|
||||
typeof SharedArrayBuffer !== 'undefined'
|
||||
|
||||
const pkg = mtOk ? '@ffmpeg/core-mt' : '@ffmpeg/core-st'
|
||||
const base = `https://unpkg.com/${pkg}@${ffmpegVersion}/dist/umd`
|
||||
|
||||
await ffmpeg.load({
|
||||
coreURL: await toBlobURL(`${base}/ffmpeg-core.js`, 'text/javascript'),
|
||||
wasmURL: await toBlobURL(`${base}/ffmpeg-core.wasm`, 'application/wasm'),
|
||||
workerURL: await toBlobURL(`${base}/ffmpeg-core.worker.js`, 'text/javascript'),
|
||||
})
|
||||
|
||||
return ffmpeg
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user