akhaliq HF Staff commited on
Commit
c0b2859
·
verified ·
1 Parent(s): 59ee84a

Video: play server's H.264 source copy; play() rejections handled

Browse files
Files changed (1) hide show
  1. index.html +15 -11
index.html CHANGED
@@ -162,6 +162,8 @@
162
  function show(kind, sourceUrl, depthUrl) {
163
  drop.style.display = "none";
164
  outPlaceholder.style.display = "none";
 
 
165
  const isVideo = kind === "video";
166
  srcImg.hidden = isVideo; depthImg.hidden = isVideo;
167
  srcVid.hidden = !isVideo; depthVid.hidden = !isVideo;
@@ -169,11 +171,7 @@
169
  srcVid.src = sourceUrl; depthVid.src = depthUrl;
170
  const sync = () => { depthVid.currentTime = srcVid.currentTime; };
171
  srcVid.addEventListener("loadeddata", sync, { once: true });
172
- // Some uploads (e.g. iPhone HEVC) cannot decode in Chrome at all \u2014 the depth result is
173
- // still valid, so say so instead of failing the whole view.
174
- srcVid.onerror = () =>
175
- setStatus(`The original video format cannot be played by this browser \u2014 the depth result is unaffected.`, false, false);
176
- srcVid.play(); depthVid.play();
177
  depthVid.onerror = () => setStatus("The depth video failed to load.", true);
178
  } else {
179
  srcImg.src = sourceUrl; depthImg.src = depthUrl;
@@ -215,7 +213,7 @@
215
  async function processFile(file) {
216
  if (!file) return;
217
  const isVideo = file.type.startsWith("video/");
218
- const sourceUrl = URL.createObjectURL(file);
219
  // The input window shows the source immediately; the output window shows work in progress.
220
  drop.style.display = "none";
221
  outPlaceholder.style.display = "";
@@ -223,7 +221,8 @@
223
  outTitle.textContent = `Estimating depth${isVideo ? " (first 60 frames)" : ""}\u2026`;
224
  if (isVideo) {
225
  srcImg.hidden = true; srcVid.hidden = false;
226
- srcVid.src = sourceUrl; srcVid.play();
 
227
  } else {
228
  srcVid.hidden = true; srcImg.hidden = false;
229
  srcImg.src = sourceUrl;
@@ -240,10 +239,15 @@
240
  `The server returned no depth output \u2014 payload: ${JSON.stringify(payload)?.slice(0, 160)}`,
241
  );
242
  }
243
- if (isVideo && depthUrl.startsWith("data:")) {
244
- // Chrome refuses large data-URI videos ("no supported source") but has no limit on
245
- // blob URLs \u2014 decode the data URI into a blob and hand the player that instead.
246
- depthUrl = URL.createObjectURL(await (await fetch(depthUrl)).blob());
 
 
 
 
 
247
  }
248
  outPlaceholder.classList.remove("working");
249
  show(isVideo ? "video" : "image", sourceUrl, depthUrl);
 
162
  function show(kind, sourceUrl, depthUrl) {
163
  drop.style.display = "none";
164
  outPlaceholder.style.display = "none";
165
+ // play() rejections (e.g. a codec the browser lacks) must not surface as raw errors.
166
+ const play = (el) => el.play?.().catch(() => {});
167
  const isVideo = kind === "video";
168
  srcImg.hidden = isVideo; depthImg.hidden = isVideo;
169
  srcVid.hidden = !isVideo; depthVid.hidden = !isVideo;
 
171
  srcVid.src = sourceUrl; depthVid.src = depthUrl;
172
  const sync = () => { depthVid.currentTime = srcVid.currentTime; };
173
  srcVid.addEventListener("loadeddata", sync, { once: true });
174
+ play(srcVid); play(depthVid);
 
 
 
 
175
  depthVid.onerror = () => setStatus("The depth video failed to load.", true);
176
  } else {
177
  srcImg.src = sourceUrl; depthImg.src = depthUrl;
 
213
  async function processFile(file) {
214
  if (!file) return;
215
  const isVideo = file.type.startsWith("video/");
216
+ let sourceUrl = URL.createObjectURL(file);
217
  // The input window shows the source immediately; the output window shows work in progress.
218
  drop.style.display = "none";
219
  outPlaceholder.style.display = "";
 
221
  outTitle.textContent = `Estimating depth${isVideo ? " (first 60 frames)" : ""}\u2026`;
222
  if (isVideo) {
223
  srcImg.hidden = true; srcVid.hidden = false;
224
+ srcVid.src = sourceUrl;
225
+ srcVid.play?.().catch(() => {});
226
  } else {
227
  srcVid.hidden = true; srcImg.hidden = false;
228
  srcImg.src = sourceUrl;
 
239
  `The server returned no depth output \u2014 payload: ${JSON.stringify(payload)?.slice(0, 160)}`,
240
  );
241
  }
242
+ if (isVideo) {
243
+ // For videos the server also returns the input re-encoded to H.264: the original file is
244
+ // often HEVC, which Chrome cannot decode, so play the server copy in the input window.
245
+ if (payload?.source?.startsWith("data:")) {
246
+ sourceUrl = URL.createObjectURL(await (await fetch(payload.source)).blob());
247
+ }
248
+ if (depthUrl.startsWith("data:")) {
249
+ depthUrl = URL.createObjectURL(await (await fetch(depthUrl)).blob());
250
+ }
251
  }
252
  outPlaceholder.classList.remove("working");
253
  show(isVideo ? "video" : "image", sourceUrl, depthUrl);