better time formatting

This commit is contained in:
wil committed 2024-02-28 10:01:56 -05:00
1 parent e06f05006b
commit 07dcf566d8
9 files changed
+99 -58

No files matched your search

@@ -1,15 +1,19 @@
import React, {
forwardRef,
useCallback,
useEffect,
useLayoutEffect,
useState,
useRef,
PointerEvent
PointerEvent,
} from "react";
import {
faPlay,
faPause,
faGripDots
faGripDots,
faVolume,
faVolumeMute,
faVolumeSlash,
} from "@fortawesome/pro-solid-svg-icons"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
@@ -19,49 +23,24 @@ import {
} from "components/common";
import { VideoFakeyouProps } from "../VideoFakeyou/VideoFakeyou";
import { QuickTrimData, TrimStates, PlaybarStates } from "./types";
import { formatSecondsToHHMMSSCS } from "./helpers";
import './styles.scss'
function roundTo2Dec(floaty:number){
return Math.round(floaty*100)/100;
}
function fractionToPercentage(fraction:number){
return roundTo2Dec(fraction * 100);
}
function formatSecondsToHHMMSS(seconds:number){
if(seconds < 3600)
return new Date(seconds * 1000).toISOString().substring(14, 19)
else
return new Date(seconds * 1000).toISOString().slice(11, 19);
}
export type QuickTrimType = {
trimStartSeconds: number;
trimEndSeconds: number;
}
interface VideoQuickTrimProps extends VideoFakeyouProps{
onSelect: (val: QuickTrimType)=>void;
onSelect: (values: QuickTrimData)=>void;
}
type TrimState = {
isScrubbingTrim: boolean;
trimDuration: number;
trimStart: number;
trimEnd: number;
maxDuration: number;
}
const initialTrimState = {
const initialTrimState:TrimStates = {
isScrubbingTrim: false,
trimDuration: 3,
trimStart: 0,
trimEnd: 0,
maxDuration: 0,
}
type PlaybarState = {
playbarWidth: number;
timeCursorOffset: number;
}
const initialPlaybarState = {
const initialPlaybarState:PlaybarStates = {
playbarWidth: 0,
timeCursorOffset: 0,
}
@@ -77,21 +56,21 @@ export default function VideoQuickTrim({
"5s": 5,
"10s": 10,
"15s" : 15,
"20s" : 20,
// "20s" : 20,
};
const videoRef = useRef<HTMLVideoElement | null>(null);
const playbarRef = useRef<HTMLDivElement | null>(null);
const trimZoneRef = useRef<HTMLDivElement>(null);
const [{playbarWidth, timeCursorOffset}, setPlaybarState] = useState<PlaybarState>(initialPlaybarState);
const [{playbarWidth, timeCursorOffset}, setPlaybarState] = useState<PlaybarStates>(initialPlaybarState);
const [playpause, setPlaypause] = useState<'playing'|'paused'|'stopped'>('paused');
const [{
trimStart,
trimEnd,
trimDuration,
isScrubbingTrim,
}, setTrimState] = useState<TrimState>(initialTrimState);
}, setTrimState] = useState<TrimStates>(initialTrimState);
@@ -207,9 +186,9 @@ export default function VideoQuickTrim({
}}
onPointerMove={(e: PointerEvent<HTMLDivElement>)=>{
if(trimZoneRef.current && playbarRef.current && isScrubbingTrim){
console.log(fractionToPercentage(
(e.clientX - trimZoneRef.current.getBoundingClientRect().left) / (playbarRef.current.getBoundingClientRect().width)
) + "%");
// console.log(fractionToPercentage(
// (e.clientX - trimZoneRef.current.getBoundingClientRect().left) / (playbarRef.current.getBoundingClientRect().width)
// ) + "%");
}
}}
>
@@ -225,8 +204,18 @@ export default function VideoQuickTrim({
variant="secondary"
onClick={handlePlaypause}
/>
<div className="playtime ms-3">
<p>{`${formatSecondsToHHMMSS(videoRef.current?.currentTime || 0)} / ${formatSecondsToHHMMSS(videoRef.current?.duration || 0)}`}</p>
<div className="playtime ms-3 d-flex">
<span >
<p>
{`${formatSecondsToHHMMSSCS(videoRef.current?.currentTime || 0)}`}
</p>
</span>
<div>/</div>
<span>
<p>
{`${formatSecondsToHHMMSSCS(videoRef.current?.duration || 0)}`}
</p>
</span>
</div>
</div>
<SelectionBubbles
@@ -236,4 +225,4 @@ export default function VideoQuickTrim({
</div>
</div>
);
}
};
@@ -0,0 +1,14 @@
export function roundTo2Dec(floaty:number){
return Math.round(floaty*100)/100;
}
export function fractionToPercentage(fraction:number){
return roundTo2Dec(fraction * 100);
}
export function formatSecondsToHHMMSSCS(seconds:number){
//example of the ISO String: 1970-01-01T00:01:40.774Z
const isoString = new Date(seconds * 1000).toISOString();
if(seconds > 3600)
return isoString.substring(11, 19) + "." + isoString.substring(20, 22)
else
return isoString.substring(14, 19) + "." + isoString.substring(20, 22);
}
@@ -1 +1,5 @@
export { default } from './VideoQuickTrim';
import VideoQuickTrim from './VideoQuickTrim'
import { QuickTrimData } from './types';
export type { QuickTrimData };
export default VideoQuickTrim;
@@ -70,4 +70,15 @@ $playbar-height: 2rem;
height: $playbar-height;
background-color: $white;
}
.playtime{
span{
width: 60px;
}
div{
width: 10px;
margin-left: 3px;
margin-right: 5px;
text-align: center;
}
}
}
@@ -0,0 +1,19 @@
//For integration into other components
export type QuickTrimData = {
trimStartSeconds: number;
trimEndSeconds: number;
}
// INTERNALS
export type TrimStates = {
isScrubbingTrim: boolean;
trimDuration: number;
trimStart: number;
trimEnd: number;
maxDuration: number;
}
export type PlaybarStates = {
playbarWidth: number;
timeCursorOffset: number;
}
@@ -48,6 +48,7 @@ import TintSpinner from "./TintSpinner";
import VideoBasic from "./VideoBasic";
import VideoFakeyou from "./VideoFakeyou";
import VideoInput from "./VideoInput";
// import VideoQuickTrim, {QuickTrimType} from "./VideoQuickTrim";
import SelectionBubbles from "./SelectionBubbles";
import Scene3D from "./Scene3D";
@@ -109,6 +110,7 @@ export {
VideoBasic,
VideoFakeyou,
VideoInput,
// VideoQuickTrim,
SelectionBubbles,
Scene3D,
};
@@ -9,16 +9,17 @@ type CNPreset =
const defaultPreset = {
cnCanny: 0,
cnDepth: 0.7,
cnDepth: 0,
cnLineArtAnime: 0.7,
cnLineArtRealistic: 0.7,
cnLineArtRealistic: 0,
cnLipsStrength: 0,
cnOpenPose: 0.7,
cnPipeFace: 0.7,
cnSparseScribble: 0.7,
cnSoftEdge: 0.7,
cnOpenPose: 1,
cnPipeFace: 0,
cnSparseScribble: 0,
cnSoftEdge: 1,
cnRegularSteps: 20,
}
const closeupPreset = {
cnCanny: 0,
cnDepth: 0,
@@ -29,7 +30,7 @@ const closeupPreset = {
cnPipeFace: 0,
cnSparseScribble: 0.7,
cnSoftEdge: 0.7,
cnRegularSteps: 30,
cnRegularSteps: 20,
}
const halfbodyPreset = {
cnCanny: 0,
@@ -41,7 +42,7 @@ const halfbodyPreset = {
cnPipeFace: 0,
cnSparseScribble: 0.7,
cnSoftEdge: 0.7,
cnRegularSteps: 30,
cnRegularSteps: 20,
}
const fullbodyPreset = {
cnCanny: 0,
@@ -53,7 +54,7 @@ const fullbodyPreset = {
cnPipeFace: 0,
cnSparseScribble: 0.7,
cnSoftEdge: 0.7,
cnRegularSteps: 30,
cnRegularSteps: 20,
}
const landscapePreset = {
cnCanny: 0.7,
@@ -65,7 +66,7 @@ const landscapePreset = {
cnPipeFace: 0,
cnSparseScribble: 0.7,
cnSoftEdge: 0.7,
cnRegularSteps: 30,
cnRegularSteps: 20,
}
const typogPreset = {
@@ -78,7 +79,7 @@ const typogPreset = {
cnPipeFace: 0,
cnSparseScribble: 0,
cnSoftEdge: 0.7,
cnRegularSteps: 30,
cnRegularSteps: 20,
}
export type {
@@ -10,6 +10,7 @@ import {
TextArea,
VideoFakeyou
} from "components/common";
import VideoQuickTrim from 'components/common/VideoQuickTrim';
import EnqueueVideoStyleTransfer from "@storyteller/components/src/api/video_styleTransfer";
@@ -234,10 +234,10 @@ export default function SectionAdvanceOptions({
}}/>
</div>
</div>
<div className="row g-3 p-3">
{/* <div className="row g-3 p-3">
<div className="col-md-6">
<NumberSliderV2 {...{
min: 1, max: 64, step: 30,
min: 1, max: 64, step: 1,
initialValue: vstVal.cnRegularSteps,
label: "Regular Steps",
thumbTip: "Regular Steps",
@@ -247,7 +247,7 @@ export default function SectionAdvanceOptions({
}
}}/>
</div>
</div>
</div> */}
<div className="d-flex p-3 justify-content-end">
<Button
icon={faRotateLeft}