π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
preview 1
Manav Rathi53618d0e1fca
diff --git a/web/packages/gallery/services/ffmpeg/index.ts b/web/packages/gallery/services/ffmpeg/index.tsindex 108c94b604..1152a33f5f 100644--- a/web/packages/gallery/services/ffmpeg/index.ts+++ b/web/packages/gallery/services/ffmpeg/index.ts@@ -268,3 +268,60 @@ const convertToMP4Native = async (electron: Electron, blob: Blob) => {await readConvertToMP4Done(electron, token);return mp4Blob;};++/**+ * Generate a preview variant of for the given video using a wasm FFmpeg running+ * in a web worker.+ *+ * See: [Note: Preview variant of videos].+ *+ * @param blob The input video blob.+ *+ * @returns The data of the generated preview variant.+ */+export const generateVideoPreviewVariantWeb = async (blob: Blob) =>+ ffmpegExecWeb(generateVideoPreviewMetadataCommand, blob, "mp4");++/**+ * The FFmpeg command to use to create a preview variant of videos.+ *+ * Current parameters+ *+ * - 720p width+ * - 2000kbps bitrate+ * - 30fps frame rate+ *+ * See: [Note: Preview variant of videos]+ *+ * Options:+ *+ * - `-vf` creates a filter graph for the video stream+ *+ * - `-vf scale=720:-1` scales the video to 720p width, keeping aspect ratio.+ *+ * - `-r` sets the frame rate.+ *+ * - `-c:v libx264` sets the codec for the video stream to H264.+ *+ * - `-b:v 2000k` sets the bitrate for the video stream.+ *+ * - `-c:a aac -b:a 128k` converts the audio stream to 128k bit AAC.+ */+const generateVideoPreviewMetadataCommand = [+ ffmpegPathPlaceholder,+ "-i",+ inputPathPlaceholder,+ "-vf",+ "scale=720:-1",+ "-r",+ "30",+ "-c:v",+ "libx264",+ "-b:v",+ "2000k",+ "-c:a",+ "aac",+ "-b:a",+ "128k",+ outputPathPlaceholder,+];diff --git a/web/packages/gallery/services/preview.ts b/web/packages/gallery/services/preview.tsnew file mode 100644index 0000000000..7263f0bfaa--- /dev/null+++ b/web/packages/gallery/services/preview.ts@@ -0,0 +1,29 @@+import type { EnteFile } from "@/media/file";+import { FileType } from "@/media/file-type";+import { downloadManager } from "./download";++/**+ * Create a preview variant of the given video {@link file}.+ *+ * [Note: Preview variant of videos]+ *+ * A preview variant of a video is created by transcoding it into a smaller,+ * streamable and more standard format.+ *+ * The video is transcoded into a format that is both smaller but is also using+ * a much more widely supported codec etc so that it can be played back readily+ * across browsers and OSes independent of the codec used by the source video.+ *+ * We also use a format that can be streamed back by the client instead of+ * needing to download it all at once.+ *+ * @param file The {@link EnteFile} of type video for which we want to create a+ * preview variant.+ */+export const createVideoPreviewVariant = (file: EnteFile) => {+ if (file.metadata.fileType != FileType.video)+ throw new Error("Preview variant can only be created for video files");++ const fileBlob = downloadManager.fileBlob(file);+ console.log(fileBlob);+};