mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-07 04:20:47 +08:00
chore: remove ffmpeg video compression
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
/**
|
||||
* 基于 FFmpeg.wasm 的视频压缩工具
|
||||
* 专为现代浏览器 (Chrome/Safari) 优化
|
||||
* 视频上传工具
|
||||
*/
|
||||
|
||||
import { UPLOAD_CONFIG } from '../config/uploadConfig.js'
|
||||
import { compressVideoWithFFmpeg, isFFmpegSupported } from './ffmpegVideoCompressor.js'
|
||||
import { useNuxtApp } from '#app'
|
||||
|
||||
// 导出配置供外部使用
|
||||
export const VIDEO_CONFIG = UPLOAD_CONFIG.VIDEO
|
||||
@@ -18,7 +15,6 @@ export function checkFileSize(file) {
|
||||
isValid: file.size <= VIDEO_CONFIG.MAX_SIZE,
|
||||
actualSize: file.size,
|
||||
maxSize: VIDEO_CONFIG.MAX_SIZE,
|
||||
needsCompression: file.size > VIDEO_CONFIG.TARGET_SIZE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,48 +28,3 @@ export function formatFileSize(bytes) {
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩视频文件 - 使用 FFmpeg.wasm
|
||||
*/
|
||||
export async function compressVideo(file, onProgress = () => {}) {
|
||||
// 检查是否需要压缩
|
||||
const sizeCheck = checkFileSize(file)
|
||||
if (!sizeCheck.needsCompression) {
|
||||
onProgress({ stage: 'completed', progress: 100 })
|
||||
return file
|
||||
}
|
||||
|
||||
// 检查 FFmpeg 支持
|
||||
if (!isFFmpegSupported()) {
|
||||
throw new Error('当前浏览器不支持视频压缩功能,请使用 Chrome 或 Safari 浏览器')
|
||||
}
|
||||
|
||||
try {
|
||||
const { $ffmpeg } = useNuxtApp()
|
||||
const ff = await $ffmpeg()
|
||||
return await compressVideoWithFFmpeg(ff, file, { onProgress })
|
||||
} catch (error) {
|
||||
console.error('FFmpeg 压缩失败:', error)
|
||||
throw new Error(`视频压缩失败: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载 FFmpeg(可选的性能优化)
|
||||
*/
|
||||
export async function preloadVideoCompressor() {
|
||||
try {
|
||||
// FFmpeg 初始化现在通过 Nuxt 插件处理
|
||||
// 这里只需要检查支持性
|
||||
if (!isFFmpegSupported()) {
|
||||
throw new Error('当前浏览器不支持 FFmpeg')
|
||||
}
|
||||
const { $ffmpeg } = useNuxtApp()
|
||||
await $ffmpeg()
|
||||
return { success: true, message: 'FFmpeg 预加载成功' }
|
||||
} catch (error) {
|
||||
console.warn('FFmpeg 预加载失败:', error)
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user