Skip to content

Commit ad740c8

Browse files
committed
fix: dependency arrays & marking
1 parent fe87d9e commit ad740c8

File tree

4 files changed

+49
-23
lines changed

4 files changed

+49
-23
lines changed

frontend/src/containers/VideoPlayer/Trackbar.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { useRef, useEffect, useState, useCallback, useMemo } from 'react';
22

33
import { Canvas, Navbar } from '/src/components';
44

5+
const MARK_SIZE = 7;
6+
57
const Trackbar = ({
68
duration,
79
currentTime,
@@ -72,8 +74,10 @@ const Trackbar = ({
7274
markInX = (markIn / duration) * width;
7375
ctx.strokeStyle = 'green';
7476
ctx.beginPath();
75-
ctx.moveTo(markInX, 0);
76-
ctx.lineTo(markInX, height);
77+
ctx.moveTo(markInX, height - MARK_SIZE);
78+
ctx.lineTo(markInX, height - 1);
79+
ctx.lineTo(markInX - MARK_SIZE, height - 1);
80+
ctx.lineTo(markInX, height - MARK_SIZE);
7781
ctx.stroke();
7882
}
7983

@@ -82,8 +86,10 @@ const Trackbar = ({
8286
markOutX = (markOut / duration) * width + frameWidth;
8387
ctx.strokeStyle = 'red';
8488
ctx.beginPath();
85-
ctx.moveTo(markOutX, 0);
86-
ctx.lineTo(markOutX, height);
89+
ctx.moveTo(markOutX, height - MARK_SIZE);
90+
ctx.lineTo(markOutX, height - 1);
91+
ctx.lineTo(markOutX + MARK_SIZE, height - 1);
92+
ctx.lineTo(markOutX, height - MARK_SIZE);
8793
ctx.stroke();
8894
}
8995

frontend/src/containers/VideoPlayer/VideoPlayerBody.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const VideoPlayerBody = ({ ...props }) => {
128128
}, [videoRef]);
129129

130130
// Position
131-
//
131+
132132
const updatePos = () => {
133133
const video = videoRef.current;
134134
const atFrame = time2frames(video.currentTime, props.frameRate);
@@ -139,7 +139,7 @@ const VideoPlayerBody = ({ ...props }) => {
139139
const markOutFrame =
140140
time2frames(markOutRef.current, props.frameRate) || durFramesRef.current - 1;
141141

142-
if (atFrame === markOutFrame) {
142+
if (atFrame >= markOutFrame && atFrame < markOutFrame + 4) {
143143
videoRef.current.currentTime = markInRef.current || 0;
144144
videoRef.current.play();
145145
}
@@ -157,7 +157,7 @@ const VideoPlayerBody = ({ ...props }) => {
157157

158158
useEffect(() => {
159159
updatePosMon();
160-
}, [videoRef, isPlaying, loop]);
160+
}, [videoRef, isPlaying]);
161161

162162
const seekToFrame = (frame) => {
163163
const videoElement = videoRef.current;

frontend/src/pages/AssetEditor/Preview.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const Preview = ({ assetData, setAssetData }) => {
5555
);
5656
const frameRate = useMemo(() => {
5757
const fps = assetData['video/fps_f'] || 25.0;
58-
//console.log('fps', fps)
5958
return fps;
6059
}, [assetData]);
6160

@@ -82,7 +81,7 @@ const Preview = ({ assetData, setAssetData }) => {
8281
if (!arrayEquals(existingSubclips, subclips)) {
8382
patchAsset({ subclips: subclips.length ? subclips : null });
8483
}
85-
}, [subclips, assetData]);
84+
}, [subclips]);
8685

8786
// Dropdown menu options for poster frame
8887

@@ -109,7 +108,6 @@ const Preview = ({ assetData, setAssetData }) => {
109108
const onSetMarks = () => {
110109
// Set asset mark_in and mark_out values
111110
// (content primary selection)
112-
console.log('Setting margs');
113111
patchAsset({
114112
mark_in: selection.mark_in || null,
115113
mark_out: selection.mark_out || null,
@@ -127,6 +125,11 @@ const Preview = ({ assetData, setAssetData }) => {
127125
return;
128126
}
129127

128+
if (selection.mark_out - selection.mark_in < 2) {
129+
toast.error('Region must be at least 2 frames long');
130+
return;
131+
}
132+
130133
setSubclips((subclips) => [
131134
...subclips,
132135
{ title: `SubClip ${subclips.length + 1}`, ...selection },

frontend/src/pages/AssetEditor/Subclip.jsx

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import styled from 'styled-components';
2+
import { toast } from 'react-toastify';
23
import { Timecode } from '@wfoxall/timeframe';
34

45
import { InputText, Button } from '/src/components';
@@ -65,29 +66,45 @@ const Subclip = ({
6566
const startTC = new Timecode(Math.floor(mark_in * fps), fps);
6667
const endTC = new Timecode(Math.floor(mark_out * fps), fps);
6768

69+
const updateSubclip = () => {
70+
if (!(selection.mark_in && selection.mark_out)) {
71+
toast.error('Please select a region first');
72+
return;
73+
}
74+
75+
if (selection.mark_in >= selection.mark_out) {
76+
toast.error('Please select a valid region');
77+
return;
78+
}
79+
80+
if (selection.mark_out - selection.mark_in < 2) {
81+
toast.error('Region must be at least 2 frames long');
82+
return;
83+
}
84+
onSetMarks(selection);
85+
};
86+
87+
const showSubclip = () => {
88+
setSelection({
89+
mark_in: mark_in || null,
90+
mark_out: mark_out || null,
91+
});
92+
};
93+
6894
return (
6995
<SubclipContainer>
7096
<h3>
7197
{startTC.toString()} - {endTC.toString()}
7298
</h3>
7399
<SubclipRow>
74-
<InputText value={title} onChange={onTitleChange} style={{ flex: 1 }} />
75-
<Button icon="delete" tooltip="Delete subclip" onClick={() => onRemove()} />
76100
<Button
77101
icon="screenshot_region"
78102
tooltip="Update subclip from selection"
79-
onClick={() => onSetMarks(selection)}
80-
/>
81-
<Button
82-
icon="frame_inspect"
83-
tooltip="Select region"
84-
onClick={() =>
85-
setSelection({
86-
mark_in: mark_in || null,
87-
mark_out: mark_out || null,
88-
})
89-
}
103+
onClick={updateSubclip}
90104
/>
105+
<Button icon="delete" tooltip="Delete subclip" onClick={() => onRemove()} />
106+
<InputText value={title} onChange={onTitleChange} style={{ flex: 1 }} />
107+
<Button icon="frame_inspect" tooltip="Select region" onClick={showSubclip} />
91108
</SubclipRow>
92109
</SubclipContainer>
93110
);

0 commit comments

Comments
 (0)