π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
wip ocr
Manav Rathicf5d64554aae
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex 2e1465f45f..af2ca7a2f8 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -5,6 +5,7 @@ import EditIcon from "@mui/icons-material/Edit";import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";import FullscreenExitOutlinedIcon from "@mui/icons-material/FullscreenExitOutlined";import FullscreenOutlinedIcon from "@mui/icons-material/FullscreenOutlined";+import TextFieldsIcon from "@mui/icons-material/TextFields";import UnArchiveIcon from "@mui/icons-material/Unarchive";import {Dialog,@@ -27,6 +28,7 @@ import { LoadingButton } from "ente-base/components/mui/LoadingButton";import { useIsSmallWidth } from "ente-base/components/utils/hooks";import { type ModalVisibilityProps } from "ente-base/components/utils/modal";import { useBaseContext } from "ente-base/context";+import { isDevBuild } from "ente-base/env";import { lowercaseExtension } from "ente-base/file-name";import { formattedListJoin, pt, ut } from "ente-base/i18n";import type { LocalUser } from "ente-base/local-user";@@ -53,6 +55,7 @@ import React, {useRef,useState,} from "react";+import { extractOCR } from "../../services/ffmpeg";import {fileInfoExifForFile,updateItemDataAlt,@@ -447,6 +450,17 @@ export const FileViewer: React.FC<FileViewerProps> = ({.catch(onGenericError);}, [onGenericError, handleMoreMenuCloseIfNeeded, activeAnnotatedFile]);+ // TODO(OCR): WIP+ const handleCopyText = useCallback(async () => {+ handleMoreMenuCloseIfNeeded();+ const imageBlob = activeAnnotatedFile?.itemData.originalImageBlob;+ console.log(imageBlob);+ if (imageBlob) {+ const text = await extractOCR(imageBlob);+ console.log(text);+ }+ }, [handleMoreMenuCloseIfNeeded, activeAnnotatedFile]);+const handleEditImage = useMemo(() => {return onSaveEditedImageCopy? () => {@@ -940,6 +954,17 @@ export const FileViewer: React.FC<FileViewerProps> = ({<ContentCopyIcon sx={{ "&&": { fontSize: "18px" } }} /></MoreMenuItem>)}+ {isDevBuild &&+ process.env.NEXT_PUBLIC_ENTE_WIP_VIDEO_STREAMING && (+ <MoreMenuItem onClick={handleCopyText}>+ <MoreMenuItemTitle>+ {pt("Copy text")}+ </MoreMenuItemTitle>+ <TextFieldsIcon+ sx={{ "&&": { fontSize: "18px" } }}+ />+ </MoreMenuItem>+ )}{activeAnnotatedFile.annotation.showEditImage && (<MoreMenuItem onClick={handleEditImage}><MoreMenuItemTitle>{t("edit_image")}</MoreMenuItemTitle>diff --git a/web/packages/gallery/services/ffmpeg/index.ts b/web/packages/gallery/services/ffmpeg/index.tsindex fd80705aea..dab3ab15fb 100644--- a/web/packages/gallery/services/ffmpeg/index.ts+++ b/web/packages/gallery/services/ffmpeg/index.ts@@ -322,3 +322,30 @@ const transcodeAndGenerateHLSPlaylistCommand = ["128k",outputPathPlaceholder,];++// TODO(OCR): WIP experiment+export const extractOCR = async (blob: Blob) =>+ ffmpegExecWeb(extractOCRCommand, blob, "txt");++/**+ * The FFmpeg command to use to create a preview variant of videos.+ *+ * Current parameters+ *+ * - H264+ * - 720p width+ * - 2000kbps bitrate+ * - 30fps frame rate+ */+const extractOCRCommand = [+ "FFPROBE",+ "-show_entries",+ "frame_tags=lavfi.ocr.text",+ "-f",+ "lavfi",+ "-i",+ // `"movie=${inputPathPlaceholder},ocr"`,+ "INPUT_PROBE",+ "-o",+ outputPathPlaceholder,+];diff --git a/web/packages/gallery/services/ffmpeg/web.ts b/web/packages/gallery/services/ffmpeg/web.tsindex cbf745833f..dfdb2e3639 100644--- a/web/packages/gallery/services/ffmpeg/web.ts+++ b/web/packages/gallery/services/ffmpeg/web.ts@@ -1,5 +1,4 @@import { FFmpeg } from "@ffmpeg/ffmpeg";-import { newID } from "ente-base/id";import log from "ente-base/log";import { PromiseQueue } from "ente-utils/promise";import {@@ -27,7 +26,7 @@ const createFFmpeg = async () => {wasmURL: "https://assets.ente.io/ffmpeg-core-0.12.10/ffmpeg-core.wasm",});// This is too noisy to enable even during development. Uncomment to taste.- // ffmpeg.on("log", (e) => log.debug(() => ["[ffmpeg]", e.message]));+ ffmpeg.on("log", (e) => log.debug(() => ["[ffmpeg]", e.message]));return ffmpeg;};@@ -72,11 +71,18 @@ const ffmpegExec = async (outputFileExtension: string,blob: Blob,) => {- const inputPath = newID("in_");- const outputSuffix = outputFileExtension ? "." + outputFileExtension : "";- const outputPath = newID("out_") + outputSuffix;+ const inputPath = "test.png"; //newID("in_") + ".png";+ // const outputSuffix = outputFileExtension ? "." + outputFileExtension : "";+ const outputPath = "out.txt"; //newID("out_") + outputSuffix;- const cmd = substitutePlaceholders(command, inputPath, outputPath);+ console.log(command, outputFileExtension);+ // let cmd1 = substitutePlaceholders(command, inputPath, outputPath);+ // // TODO(OCR): WIP+ // if (command[0] == "FFPROBE") {+ // cmd = cmd+ // .slice(1)+ // .map((w) => (w == "INPUT_PROBE" ? `"movie=${inputPath},ocr"` : w));+ // }const inputData = new Uint8Array(await blob.arrayBuffer());@@ -86,11 +92,38 @@ const ffmpegExec = async (await ffmpeg.writeFile(inputPath, inputData);// returns `0` if no error, `!= 0` if timeout (1) or error.- const status = await ffmpeg.exec(cmd);+ // const status = await (command[0] == "FFPROBE"+ // ? ffmpeg.ffprobe(cmd)+ // : ffmpeg.exec(cmd));+ // const status = await ffmpeg.exec(cmd);+ // await ffmpeg.ffprobe([+ // "-v",+ // "error",+ // "-show_entries",+ // "format=duration",+ // "-of",+ // "default=noprint_wrappers=1:nokey=1",+ // "video.avi",+ // "-o",+ // "output.txt",+ // ]);+ // [debug] [ffmpeg] [lavfi @ 0xe313e0] No such filter: 'ocr'+ const status = await ffmpeg.ffprobe([+ "-v",+ "error",+ "-show_entries",+ "frame_tags=lavfi.ocr.text",+ "-f",+ "lavfi",+ "-i",+ "movie=test.png,ocr",+ "-o",+ "out.txt",+ ]);if (status !== 0) {- log.info(- `[wasm] ffmpeg command failed with exit code ${status}: ${cmd.join(" ")}`,- );+ // log.info(+ // `[wasm] ffmpeg command failed with exit code ${status}: ${cmd.join(" ")}`,+ // );throw new Error(`ffmpeg command failed with exit code ${status}`);}