mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-06-28 03:01:28 +08:00
feat(local): 添加本地视频处理功能
- 实现本地视频上传和处理功能 - 新增 LocalDownloader 类处理本地视频 - 更新前端界面支持本地视频选择 - 添加视频封面提取和保存功能 - 优化后端路由支持本地视频上传
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import shutil
|
||||
from dotenv import load_dotenv
|
||||
import subprocess
|
||||
import os
|
||||
import uuid
|
||||
load_dotenv()
|
||||
api_path = os.getenv("API_BASE_URL", "http://localhost")
|
||||
BACKEND_PORT= os.getenv("BACKEND_PORT", 8000)
|
||||
|
||||
BACKEND_BASE_URL = f"{api_path}:{BACKEND_PORT}"
|
||||
|
||||
from typing import Optional
|
||||
def generate_screenshot(video_path: str, output_dir: str, timestamp: int, index: int) -> str:
|
||||
"""
|
||||
使用 ffmpeg 生成截图,返回生成图片路径
|
||||
@@ -24,3 +31,30 @@ def generate_screenshot(video_path: str, output_dir: str, timestamp: int, index:
|
||||
subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
return output_path
|
||||
|
||||
|
||||
|
||||
def save_cover_to_static(local_cover_path: str, subfolder: Optional[str] = "cover") -> str:
|
||||
"""
|
||||
将封面图片保存到 static 目录下,并返回前端可访问的路径
|
||||
:param local_cover_path: 本地原封面路径(比如提取出来的jpg)
|
||||
:param subfolder: 子目录,默认是 cover,可以自定义
|
||||
:return: 前端访问路径,例如 /static/cover/xxx.jpg
|
||||
"""
|
||||
# 项目根目录
|
||||
project_root = os.getcwd()
|
||||
|
||||
# static目录
|
||||
static_dir = os.path.join(project_root, "static")
|
||||
|
||||
# 确定目标子目录
|
||||
target_dir = os.path.join(static_dir, subfolder or "cover")
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
|
||||
# 拷贝文件
|
||||
file_name = os.path.basename(local_cover_path)
|
||||
target_path = os.path.join(target_dir, file_name)
|
||||
shutil.copy2(local_cover_path, target_path) # 保留原时间戳、权限
|
||||
image_relative_path = f"/static/{subfolder}/{file_name}".replace("\\", "/")
|
||||
url_path = f"{BACKEND_BASE_URL.rstrip('/')}/{image_relative_path.lstrip('/')}"
|
||||
# 返回前端可访问的路径
|
||||
return url_path
|
||||
|
||||
Reference in New Issue
Block a user