Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fe videofmt #120

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 96 additions & 77 deletions src/components/Frame/index.tsx → src/components/Dynamic/Frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,95 +126,114 @@ const VideoFrame = () => {
</Button>
{!!video && <Box>{video.name}</Box>}
</Stack>
{!!video && (
<>
<Box
sx={{
minHeight: '290px',
bgcolor: '#f5f5f5',
}}
>
{video ? (
<Box
component='video'
id='videoEl'
controls
sx={{ width: '100%' }}
src={URL.createObjectURL(video)}
></Box>
) : (
<Box
onClick={upload}
sx={{
fontSize: '12px',
bgcolor: 'rgba(0,0,0,0.1)',
px: 2,
borderRadius: '4px',
lineHeight: '40px',
}}
ref={messageRef}
></Box>
<Box sx={{ fontSize: '18px', fontWeight: 'bold' }}>视频帧设置</Box>
<Stack
direction='row'
alignItems={'center'}
justifyContent={'space-between'}
spacing={2}
>
<Stack direction='row' alignItems={'center'} spacing={2}>
<Box>视频帧采样间隔</Box>
<OutlinedInput
sx={{ width: '100px' }}
type='number'
value={(1 / interval).toFixed(2)}
size='small'
endAdornment='秒'
onChange={(e) => {
setInterval(Number(e.target.value) * 1000);
}}
/>
<Box>视频帧数</Box>
<OutlinedInput
sx={{ width: '100px' }}
type='number'
value={interval}
size='small'
endAdornment='fps'
onChange={(e) => {
const v = Number(e.target.value);
setInterval(v >= 0 ? v : interval);
}}
/>
<Box>预计截取 {Math.floor(duration * interval)} 张</Box>
</Stack>
<Button
variant='contained'
onClick={extract}
disabled={loadConfig || loadFrame}
>
提取视频帧
</Button>
</Stack>
<Box
sx={{
minHeight: '500px',
border: '1px dashed #ccc',
p: 2,
bgcolor: '#f5f5f5',
color: '#999',
textAlign: 'center',
lineHeight: '290px',
cursor: 'pointer',
}}
>
<Stack direction='row' flexWrap={'wrap'} sx={{ gap: 2 }}>
{imgs.map((it) => (
<Box
onClick={() => setCurImg(it)}
component='img'
width={409}
src={it}
key={it}
sx={{ cursor: 'pointer' }}
></Box>
))}
</Stack>
上传视频后即可提取视频帧截图
</Box>
<Button
variant='contained'
onClick={download}
disabled={files.length === 0 || fileDown}
>
下载所有视频帧截图
</Button>
</>
)}
)}
</Box>
<Box
sx={{
fontSize: '12px',
bgcolor: 'rgba(0,0,0,0.1)',
px: 2,
borderRadius: '4px',
lineHeight: '40px',
}}
ref={messageRef}
></Box>
<Box sx={{ fontSize: '18px', fontWeight: 'bold' }}>视频帧设置</Box>
<Stack
direction='row'
alignItems={'center'}
justifyContent={'space-between'}
spacing={2}
>
<Stack direction='row' alignItems={'center'} spacing={2}>
<Box>视频帧采样间隔</Box>
<OutlinedInput
sx={{ width: '100px' }}
type='number'
value={(1 / interval).toFixed(2)}
size='small'
endAdornment='秒'
onChange={(e) => {
setInterval(Number(e.target.value) * 1000);
}}
/>
<Box>视频帧数</Box>
<OutlinedInput
sx={{ width: '100px' }}
type='number'
value={interval}
size='small'
endAdornment='fps'
onChange={(e) => {
const v = Number(e.target.value);
setInterval(v >= 0 ? v : interval);
}}
/>
<Box>预计截取 {Math.floor(duration * interval)} 张</Box>
</Stack>
<Button
variant='contained'
onClick={extract}
disabled={loadConfig || loadFrame || !video}
>
提取视频帧
</Button>
</Stack>
<Box
sx={{
minHeight: '500px',
border: '1px dashed #ccc',
p: 2,
bgcolor: '#f5f5f5',
}}
>
<Stack direction='row' flexWrap={'wrap'} sx={{ gap: 2 }}>
{imgs.map((it) => (
<Box
onClick={() => setCurImg(it)}
component='img'
width={409}
src={it}
key={it}
sx={{ cursor: 'pointer' }}
></Box>
))}
</Stack>
</Box>
<Button
variant='contained'
onClick={download}
disabled={files.length === 0 || fileDown}
>
下载所有视频帧截图
</Button>
<Box
id='videoframe'
component='input'
Expand Down
21 changes: 0 additions & 21 deletions src/components/Dynamic/Video2Gif.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ dayjs.extend(duration);

const _C = () => {
const [video, setVideo] = useState<File>();
const [duration, setDuration] = useState<number>(0);
const [startTime, setStartTime] = useState<number>(0);
const [transformTime, setTransformTime] = useState<number>(3);
const [gif, setGif] = useState<string>('');

const [loadFile, setLoadFile] = useState(false);
const [loadConfig, setLoadingConfig] = useState(false);
const [loadTransform, setLoadTransform] = useState(false);

Expand All @@ -27,17 +25,6 @@ const _C = () => {
videoInput?.click();
};

const download = () => {
setLoadFile(true);
const link = document.createElement('a');
link.href = gif;
link.download = 'output.gif';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
setLoadFile(false);
};

const transform = async () => {
try {
setGif('');
Expand Down Expand Up @@ -84,14 +71,6 @@ const _C = () => {
setLoadingConfig(false);
};

useEffect(() => {
const videoEl = document.getElementById('videoEl') as HTMLVideoElement;
videoEl?.addEventListener('loadeddata', () => {
const duration = videoEl?.duration || 0;
setDuration(duration);
});
}, [video]);

useEffect(() => {
loadPlugin();
}, []);
Expand Down
Loading