Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | /**
* 视频生成模块 - 类型定义
* 定义视频项目、素材、配置的数据结构
*/
// ============ 核心类型 ============
/** 视频项目状态 */
export type VideoProjectStatus = 'draft' | 'processing' | 'completed' | 'failed';
/** 素材类型 */
export type MaterialType = 'image' | 'audio' | 'template';
/** 转场效果 */
export type TransitionEffect = 'none' | 'fade' | 'slide';
/** 字幕位置 */
export type SubtitlePosition = 'top' | 'bottom' | 'center';
/** 图片配置项 */
export interface ImageConfig {
url: string; // 图片URL
duration: number; // 显示时长(秒)
transition: TransitionEffect; // 转场效果
kenburns?: KenBurnsConfig; // Ken Burns 效果配置
}
/** Ken Burns 效果配置 */
export interface KenBurnsConfig {
enabled: boolean;
minZoom: number; // 最小缩放 (如 1.0)
maxZoom: number; // 最大缩放 (如 1.3)
panDirection?: 'in' | 'out' | 'left' | 'right' | 'random';
zoomCurve?: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
}
/** 音频配置 */
export interface AudioConfig {
url: string; // 音频URL(必填)
startTime?: number; // 音频开始时间(截取)
endTime?: number; // 音频结束时间(截取)
volume: number; // 音量 0-1
}
/** 背景音乐配置 */
export interface BgmConfig {
url: string; // BGM URL
volume: number; // 音量 0-1
loop: boolean; // 是否循环
fadeIn?: number; // 淡入时长(秒)
fadeOut?: number; // 淡出时长(秒)
}
/** 字幕配置 */
export interface SubtitleConfig {
text: string; // 字幕文本
fontSize?: number; // 字体大小
fontColor?: string; // 字体颜色
backgroundColor?: string; // 背景颜色
position: SubtitlePosition; // 位置
margin?: number; // 边距
style?: 'normal' | 'bold'; // 样式
}
/** 视频参数 */
export interface VideoParams {
width: number; // 视频宽度
height: number; // 视频高度
fps: number; // 帧率
bitrate: string; // 码率 (如 "2M")
format: string; // 格式 (如 "mp4")
}
/** 完整视频配置 */
export interface VideoConfig {
// 图片配置
images: ImageConfig[];
// 音频配置
audio: AudioConfig;
// 背景音乐配置(可选)
bgm?: BgmConfig;
// 字幕配置(可选)
subtitle?: SubtitleConfig;
// 视频参数
video: VideoParams;
// Ken Burns 全局配置
kenburns: KenBurnsConfig;
}
// ============ 数据库模型类型 ============
/** 视频项目(数据库) */
export interface VideoProjectDB {
id: number;
userId: number | null;
title: string;
description: string | null;
coverUrl: string | null;
configJson: string | null;
outputUrl: string | null;
duration: number | null;
fileSize: number | null;
bookId: number | null;
chapterId: number | null; // 直接关联章节
status: VideoProjectStatus;
progress: number;
errorMsg: string | null;
createdAt: Date;
updatedAt: Date;
}
/** 视频素材(数据库) */
export interface VideoMaterialDB {
id: number;
userId: number | null;
type: MaterialType;
name: string;
url: string;
thumbnail: string | null;
tags: string | null;
category: string | null;
duration: number | null;
size: number | null;
width: number | null;
height: number | null;
createdAt: Date;
updatedAt: Date;
}
// ============ 请求/响应类型 ============
/** 创建视频项目请求 */
export interface CreateVideoProjectRequest {
title: string;
description?: string;
coverUrl?: string;
config?: VideoConfig;
bookId?: number;
chapterId?: number; // 直接关联章节
}
/** 更新视频项目请求 */
export interface UpdateVideoProjectRequest {
title?: string;
description?: string;
coverUrl?: string;
config?: VideoConfig;
}
/** 生成视频请求 */
export interface GenerateVideoRequest {
projectId: number;
}
/** 获取视频项目列表查询 */
export interface GetVideoProjectsQuery {
userId?: number;
status?: VideoProjectStatus;
page?: number;
pageSize?: number;
}
/** 视频项目响应 */
export interface VideoProjectResponse extends VideoProjectDB {
config?: VideoConfig;
}
/** 素材列表查询 */
export interface GetMaterialsQuery {
userId?: number;
type?: MaterialType;
category?: string;
page?: number;
pageSize?: number;
}
/** 素材响应 */
export interface VideoMaterialResponse {
id: number;
userId: number | null;
type: MaterialType;
name: string;
url: string;
thumbnail: string | null;
tags?: string[];
category: string | null;
duration: number | null;
size: number | null;
width: number | null;
height: number | null;
createdAt: Date;
updatedAt: Date;
}
/** 生成进度响应 */
export interface GenerateProgressResponse {
projectId: number;
status: VideoProjectStatus;
progress: number;
outputUrl?: string;
duration?: number;
fileSize?: number;
errorMsg?: string;
}
// ============ 预设配置 ============
/** 预设视频配置 */
export const PRESET_VIDEO_CONFIGS: Record<string, VideoConfig> = {
// 竖屏 9:16 (短视频)
portrait: {
images: [],
audio: {
url: '',
volume: 1,
},
video: {
width: 720,
height: 1280,
fps: 30,
bitrate: '2M',
format: 'mp4',
},
kenburns: {
enabled: true,
minZoom: 1.0,
maxZoom: 1.2,
},
},
// 横屏 16:9 (横版视频)
landscape: {
images: [],
audio: {
url: '',
volume: 1,
},
video: {
width: 1920,
height: 1080,
fps: 30,
bitrate: '4M',
format: 'mp4',
},
kenburns: {
enabled: true,
minZoom: 1.0,
maxZoom: 1.15,
},
},
// 方形 1:1 (社交媒体)
square: {
images: [],
audio: {
url: '',
volume: 1,
},
video: {
width: 1080,
height: 1080,
fps: 30,
bitrate: '2M',
format: 'mp4',
},
kenburns: {
enabled: true,
minZoom: 1.0,
maxZoom: 1.25,
},
},
};
// ============ 工具函数 ============
/** 解析配置JSON */
export function parseConfig(json: string | null): VideoConfig | null {
if (!json) return null;
try {
return JSON.parse(json);
} catch {
return null;
}
}
/** 序列化配置为JSON */
export function serializeConfig(config: VideoConfig): string {
return JSON.stringify(config);
}
/** 解析标签JSON */
export function parseTags(tags: string | null): string[] {
if (!tags) return [];
try {
return JSON.parse(tags);
} catch {
return [];
}
}
/** 序列化标签为JSON */
export function serializeTags(tags: string[]): string {
return JSON.stringify(tags);
}
|