2025-11-21 10:12:42 +00:00
|
|
|
import { useEffect, useRef } from "react";
|
|
|
|
|
import { useGetVideoFeed } from "./useGetVideoFeed";
|
|
|
|
|
|
|
|
|
|
export const useCreateVideoSnapshot = () => {
|
|
|
|
|
const latestBitmapRef = useRef<ImageBitmap | null>(null);
|
|
|
|
|
const { videoQuery } = useGetVideoFeed();
|
|
|
|
|
|
|
|
|
|
const snapShot = videoQuery?.data;
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
async function createBitmap() {
|
|
|
|
|
if (!snapShot) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const bitmap = await createImageBitmap(snapShot);
|
2025-11-21 16:01:34 +00:00
|
|
|
if (!bitmap) return;
|
2025-11-21 10:12:42 +00:00
|
|
|
latestBitmapRef.current = bitmap;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
createBitmap();
|
|
|
|
|
}, [snapShot]);
|
|
|
|
|
|
|
|
|
|
return { latestBitmapRef };
|
|
|
|
|
};
|