Skip to content

Commit

Permalink
Update VideoThumbnail.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger committed Nov 8, 2024
1 parent 76a04d6 commit 1821511
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions packages/convert/app/components/VideoThumbnail.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import {FastAverageColor} from 'fast-average-color';
import {useEffect, useRef, useState} from 'react';
import React, {useEffect, useRef, useState} from 'react';

const THUMBNAIL_HEIGHT = Math.round((350 / 16) * 9);

export const VideoThumbnail: React.FC<{
readonly thumbnail: VideoFrame | null;
}> = ({thumbnail}) => {
const ThumbnailContent: React.FC<{readonly thumbnail: VideoFrame}> = ({
thumbnail,
}) => {
const ref = useRef<HTMLCanvasElement>(null);

const scaleRatio = thumbnail ? THUMBNAIL_HEIGHT / thumbnail.displayHeight : 0;
const width = thumbnail ? Math.round(thumbnail.displayWidth * scaleRatio) : 0;
const scaleRatio = THUMBNAIL_HEIGHT / thumbnail.displayHeight;
const width = Math.round(thumbnail.displayWidth * scaleRatio);

const [color, setColor] = useState<string>('transparent');

useEffect(() => {
if (!thumbnail) {
return;
}

createImageBitmap(thumbnail, {
resizeWidth: width,
resizeHeight: THUMBNAIL_HEIGHT,
Expand All @@ -34,10 +30,7 @@ export const VideoThumbnail: React.FC<{
}, [scaleRatio, thumbnail, width]);

return (
<div
className="border-b-2 border-black flex justify-center"
style={{height: THUMBNAIL_HEIGHT, background: color}}
>
<div className="flex justify-center" style={{backgroundColor: color}}>
<canvas
ref={ref}
width={width}
Expand All @@ -50,3 +43,15 @@ export const VideoThumbnail: React.FC<{
</div>
);
};
export const VideoThumbnail: React.FC<{
readonly thumbnail: VideoFrame | null;
}> = ({thumbnail}) => {
return (
<div
className="border-b-2 border-black "
style={{height: THUMBNAIL_HEIGHT}}
>
{thumbnail ? <ThumbnailContent thumbnail={thumbnail} /> : null}
</div>
);
};

0 comments on commit 1821511

Please sign in to comment.