Commit 0050e969 authored by Shik Chen's avatar Shik Chen Committed by Commit Bot

CCA: Optimize thumbnail generation for long video

Bug: 1058325
Test: Record a 2hrs video and check the thumbnail generation time
and content manually.

Change-Id: I189e7bdcf3b78c8aa41680456dcd556495e681dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2179863
Commit-Queue: Shik Chen <shik@chromium.org>
Reviewed-by: default avatarWei Lee <wtlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#765375}
parent ba39510f
...@@ -16,6 +16,15 @@ import * as util from './util.js'; ...@@ -16,6 +16,15 @@ import * as util from './util.js';
*/ */
const THUMBNAIL_WIDTH = 240; const THUMBNAIL_WIDTH = 240;
/**
* The maximum size of video used to generate the thumbnail. The file would be
* truncated to that size before generating the thumbnail, which speeds up the
* generation process significantly when the file is large. 32MB should be more
* than enough for getting the first frame from a video.
* @type {number}
*/
const VIDEO_THUMBNAIL_SIZE_LIMIT = 32 << 20;
/** /**
* Cover photo of gallery button. * Cover photo of gallery button.
*/ */
...@@ -59,8 +68,9 @@ class CoverPhoto { ...@@ -59,8 +68,9 @@ class CoverPhoto {
* @return {!Promise<!CoverPhoto>} * @return {!Promise<!CoverPhoto>}
*/ */
static async create(file) { static async create(file) {
const fileUrl = await filesystem.pictureURL(file);
const isVideo = filesystem.hasVideoPrefix(file); const isVideo = filesystem.hasVideoPrefix(file);
const limit = isVideo ? VIDEO_THUMBNAIL_SIZE_LIMIT : Infinity;
const fileUrl = await filesystem.pictureURL(file, limit);
const thumbnail = const thumbnail =
await util.scalePicture(fileUrl, isVideo, THUMBNAIL_WIDTH); await util.scalePicture(fileUrl, isVideo, THUMBNAIL_WIDTH);
URL.revokeObjectURL(fileUrl); URL.revokeObjectURL(fileUrl);
......
...@@ -498,14 +498,18 @@ export function getEntries() { ...@@ -498,14 +498,18 @@ export function getEntries() {
/** /**
* Returns an URL for a picture. * Returns an URL for a picture.
* @param {!FileEntry} entry File entry. * @param {!FileEntry} entry File entry.
* @param {number} limit Size limit. The file would be truncated if it's larger
* than limit.
* @return {!Promise<string>} Promise for the result. * @return {!Promise<string>} Promise for the result.
*/ */
export function pictureURL(entry) { export function pictureURL(entry, limit) {
return new Promise((resolve) => { return new Promise((resolve) => {
if (externalDir) { entry.file((file) => {
entry.file((file) => resolve(URL.createObjectURL(file))); if (file.size > limit) {
} else { file = file.slice(0, limit);
resolve(entry.toURL()); }
} const url = URL.createObjectURL(file);
resolve(url);
});
}); });
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment