MCPcopy
hub / github.com/CapSoftware/Cap / adjustVideoSpeed

Function adjustVideoSpeed

apps/web/components/tools/SpeedController.tsx:159–389  ·  view source on GitHub ↗
(videoUrl: string)

Source from the content-addressed store, hash-verified

157 };
158
159 const adjustVideoSpeed = async (videoUrl: string): Promise<void> => {
160 return new Promise((resolve, reject) => {
161 const video = document.createElement("video");
162 videoRef.current = video;
163 video.src = videoUrl;
164 video.muted = false;
165
166 video.oncanplay = async () => {
167 try {
168 const canvas = document.createElement("canvas");
169 canvas.width = video.videoWidth;
170 canvas.height = video.videoHeight;
171 const ctx = canvas.getContext("2d", { alpha: false });
172
173 if (!ctx) {
174 throw new Error("Failed to create canvas context");
175 }
176
177 let inputFormat = "video/webm";
178 if (file?.type) {
179 inputFormat = file.type;
180 } else if (file?.name) {
181 const extension = file.name.split(".").pop()?.toLowerCase();
182 if (extension === "mp4") inputFormat = "video/mp4";
183 else if (extension === "webm") inputFormat = "video/webm";
184 else if (extension === "mov") inputFormat = "video/quicktime";
185 }
186
187 let mimeTypes: string[] = [];
188
189 if (inputFormat.includes("mp4")) {
190 mimeTypes = [
191 "video/mp4",
192 "video/webm;codecs=vp9,opus",
193 "video/webm;codecs=vp8,opus",
194 "video/webm;codecs=vp9",
195 "video/webm;codecs=vp8",
196 "video/webm",
197 ];
198 } else {
199 mimeTypes = [
200 "video/webm;codecs=vp9,opus",
201 "video/webm;codecs=vp8,opus",
202 "video/webm;codecs=vp9",
203 "video/webm;codecs=vp8",
204 "video/webm",
205 "video/mp4",
206 ];
207 }
208
209 let selectedMimeType = "";
210 for (const type of mimeTypes) {
211 if (MediaRecorder.isTypeSupported(type)) {
212 selectedMimeType = type;
213 break;
214 }
215 }
216

Callers 1

processVideoFunction · 0.85

Calls 5

trackEventFunction · 0.90
rejectFunction · 0.85
finishProcessingFunction · 0.85
startMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected