diff --git a/web/src/components/AttachmentLibrary/AttachmentFileRows.tsx b/web/src/components/AttachmentLibrary/AttachmentFileRows.tsx
index cfa64d02..ef80a3b0 100644
--- a/web/src/components/AttachmentLibrary/AttachmentFileRows.tsx
+++ b/web/src/components/AttachmentLibrary/AttachmentFileRows.tsx
@@ -1,5 +1,6 @@
import { FileAudioIcon, FileIcon, PlayIcon } from "lucide-react";
import AudioAttachmentItem from "@/components/MemoMetadata/Attachment/AudioAttachmentItem";
+import VideoPoster from "@/components/VideoPoster";
import type { AttachmentLibraryListItem } from "@/hooks/useAttachmentLibrary";
import { cn } from "@/lib/utils";
import { getAttachmentThumbnailUrl, getAttachmentType, isMotionAttachment } from "@/utils/attachment";
@@ -26,7 +27,7 @@ const AttachmentThumb = ({ item, className }: { item: AttachmentLibraryListItem;
if (type === "video/*") {
return (
-
+
diff --git a/web/src/components/AttachmentLibrary/AttachmentMediaGrid.tsx b/web/src/components/AttachmentLibrary/AttachmentMediaGrid.tsx
index 916dd78d..bf579632 100644
--- a/web/src/components/AttachmentLibrary/AttachmentMediaGrid.tsx
+++ b/web/src/components/AttachmentLibrary/AttachmentMediaGrid.tsx
@@ -1,6 +1,7 @@
import { PlayIcon } from "lucide-react";
import MotionPhotoPreview from "@/components/MotionPhotoPreview";
import { Badge } from "@/components/ui/badge";
+import VideoPoster from "@/components/VideoPoster";
import type { AttachmentLibraryMediaItem, AttachmentLibraryMonthGroup } from "@/hooks/useAttachmentLibrary";
import { useTranslate } from "@/utils/i18n";
import { AttachmentMetadataLine, AttachmentOpenButton } from "./AttachmentLibraryPrimitives";
@@ -19,7 +20,12 @@ const AttachmentMediaCard = ({ item, onPreview }: { item: AttachmentLibraryMedia
{item.kind === "video" ? (
<>
-
+
diff --git a/web/src/components/MemoMetadata/Attachment/AttachmentListView.tsx b/web/src/components/MemoMetadata/Attachment/AttachmentListView.tsx
index cfb75638..fb1354f4 100644
--- a/web/src/components/MemoMetadata/Attachment/AttachmentListView.tsx
+++ b/web/src/components/MemoMetadata/Attachment/AttachmentListView.tsx
@@ -3,6 +3,7 @@ import type { PropsWithChildren } from "react";
import { useMemo } from "react";
import MetadataSection from "@/components/MemoMetadata/MetadataSection";
import MotionPhotoPreview from "@/components/MotionPhotoPreview";
+import VideoPoster from "@/components/VideoPoster";
import { cn } from "@/lib/utils";
import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb";
import { getAttachmentUrl } from "@/utils/attachment";
@@ -115,7 +116,7 @@ const CollageVisualItem = ({
{item.kind === "video" ? (
<>
-
+
{!overlayLabel && (
@@ -170,7 +171,7 @@ const SingleVisualItem = ({ item, onPreview }: { item: VisualItem; onPreview?: (
return (
-
+
diff --git a/web/src/components/VideoPoster.tsx b/web/src/components/VideoPoster.tsx
new file mode 100644
index 00000000..4dce05ad
--- /dev/null
+++ b/web/src/components/VideoPoster.tsx
@@ -0,0 +1,82 @@
+import { useCallback, useEffect, useMemo, useState } from "react";
+import { cn } from "@/lib/utils";
+
+interface VideoPosterProps {
+ sourceUrl: string;
+ alt: string;
+ className?: string;
+ posterUrl?: string;
+}
+
+const MAX_POSTER_DIMENSION = 960;
+
+const getFrameSourceUrl = (sourceUrl: string): string => {
+ if (!sourceUrl || sourceUrl.startsWith("blob:") || sourceUrl.startsWith("data:") || sourceUrl.includes("#")) {
+ return sourceUrl;
+ }
+
+ return `${sourceUrl}#t=0.001`;
+};
+
+const getCanvasSize = (width: number, height: number) => {
+ const scale = Math.min(1, MAX_POSTER_DIMENSION / Math.max(width, height));
+ return {
+ width: Math.max(1, Math.round(width * scale)),
+ height: Math.max(1, Math.round(height * scale)),
+ };
+};
+
+const VideoPoster = ({ sourceUrl, alt, className, posterUrl }: VideoPosterProps) => {
+ const usablePosterUrl = posterUrl && posterUrl !== sourceUrl ? posterUrl : undefined;
+ const [capturedPosterUrl, setCapturedPosterUrl] = useState();
+ const frameSourceUrl = useMemo(() => getFrameSourceUrl(sourceUrl), [sourceUrl]);
+ const posterImageUrl = usablePosterUrl ?? capturedPosterUrl;
+
+ useEffect(() => {
+ setCapturedPosterUrl(undefined);
+ }, [sourceUrl, usablePosterUrl]);
+
+ const captureFrame = useCallback(
+ (video: HTMLVideoElement) => {
+ if (usablePosterUrl || capturedPosterUrl || video.videoWidth <= 0 || video.videoHeight <= 0) {
+ return;
+ }
+
+ try {
+ const { width, height } = getCanvasSize(video.videoWidth, video.videoHeight);
+ const canvas = document.createElement("canvas");
+ canvas.width = width;
+ canvas.height = height;
+
+ const context = canvas.getContext("2d");
+ if (!context) {
+ return;
+ }
+
+ context.drawImage(video, 0, 0, width, height);
+ setCapturedPosterUrl(canvas.toDataURL("image/jpeg", 0.86));
+ } catch {
+ // Cross-origin or codec-specific failures should keep the video fallback visible.
+ }
+ },
+ [capturedPosterUrl, usablePosterUrl],
+ );
+
+ if (posterImageUrl) {
+ return
;
+ }
+
+ return (
+