2026-04-16-20-46-50 - 压缩关键帧分辨率并增加存储错误日志,修复 LocalStorage 超限导致的关键帧丢失
This commit is contained in:
@@ -456,18 +456,20 @@ export default function ReportEditor() {
|
||||
if (!videoRef.current || !canvasRef.current || currentVideoIndex === -1) return;
|
||||
const video = videoRef.current;
|
||||
const canvas = canvasRef.current;
|
||||
canvas.width = video.videoWidth;
|
||||
canvas.height = video.videoHeight;
|
||||
const MAX_WIDTH = 800;
|
||||
const scale = Math.min(1, MAX_WIDTH / video.videoWidth);
|
||||
canvas.width = video.videoWidth * scale;
|
||||
canvas.height = video.videoHeight * scale;
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx?.drawImage(video, 0, 0, canvas.width, canvas.height);
|
||||
|
||||
|
||||
const newFrame: CapturedFrame = {
|
||||
id: Date.now(),
|
||||
videoIndex: currentVideoIndex,
|
||||
videoName: videos[currentVideoIndex].name,
|
||||
time: video.currentTime,
|
||||
timeFormatted: formatTime(video.currentTime),
|
||||
dataUrl: canvas.toDataURL('image/jpeg', 0.9),
|
||||
dataUrl: canvas.toDataURL('image/jpeg', 0.6),
|
||||
isManual: true
|
||||
};
|
||||
const nextFrames = [...capturedFrames, newFrame].sort((a, b) => a.time - b.time);
|
||||
@@ -503,8 +505,10 @@ export default function ReportEditor() {
|
||||
};
|
||||
video.addEventListener('seeked', onSeeked);
|
||||
});
|
||||
canvas.width = video.videoWidth;
|
||||
canvas.height = video.videoHeight;
|
||||
const MAX_WIDTH = 800;
|
||||
const scale = Math.min(1, MAX_WIDTH / video.videoWidth);
|
||||
canvas.width = video.videoWidth * scale;
|
||||
canvas.height = video.videoHeight * scale;
|
||||
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
||||
const newFrame: CapturedFrame = {
|
||||
id: Date.now() + Math.random(),
|
||||
@@ -512,7 +516,7 @@ export default function ReportEditor() {
|
||||
videoName: videos[currentVideoIndex].name,
|
||||
time,
|
||||
timeFormatted: formatTime(time),
|
||||
dataUrl: canvas.toDataURL('image/jpeg', 0.9),
|
||||
dataUrl: canvas.toDataURL('image/jpeg', 0.6),
|
||||
isManual: false
|
||||
};
|
||||
accumulatedFrames = [...accumulatedFrames, newFrame].sort((a, b) => a.time - b.time);
|
||||
|
||||
@@ -11,8 +11,8 @@ export const storage = {
|
||||
set<T>(key: string, value: T): void {
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
} catch {
|
||||
// ignore quota exceeded
|
||||
} catch (e) {
|
||||
console.error('Storage save failed (possibly quota exceeded):', e);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -32,8 +32,8 @@ export const storage = {
|
||||
setSession<T>(key: string, value: T): void {
|
||||
try {
|
||||
sessionStorage.setItem(key, JSON.stringify(value));
|
||||
} catch {
|
||||
// ignore
|
||||
} catch (e) {
|
||||
console.error('Session storage save failed:', e);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user