Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

chain

Manav Rathi22f05f73a9d8
diff --git a/desktop/src/main/services/ffmpeg.ts b/desktop/src/main/services/ffmpeg.ts
index df9650a007..c80d595744 100644
--- a/desktop/src/main/services/ffmpeg.ts
+++ b/desktop/src/main/services/ffmpeg.ts
@@ -136,6 +136,7 @@ export interface FFmpegGenerateHLSPlaylistAndSegmentsResult {
playlistPath: string;
videoPath: string;
dimensions: { width: number; height: number };
+ videoSize: number;
}
/**
@@ -330,6 +331,7 @@ export const ffmpegGenerateHLSPlaylistAndSegments = async (
].flat();
let dimensions: ReturnType<typeof detectVideoDimensions>;
+ let videoSize: number;
try {
// Write the key and the keyInfo to their desired paths.
@@ -346,6 +348,10 @@ export const ffmpegGenerateHLSPlaylistAndSegments = async (
// Determine the dimensions of the generated video from the stderr
// output produced by ffmpeg during the conversion.
dimensions = detectVideoDimensions(conversionStderr);
+
+ // Find the size of the generated video segments by reading the size of
+ // the generated .ts file.
+ videoSize = await fs.stat(videoPath).then((st) => st.size);
} catch (e) {
log.error("HLS generation failed", e);
await Promise.all([
@@ -362,7 +368,7 @@ export const ffmpegGenerateHLSPlaylistAndSegments = async (
]);
}
- return { playlistPath, videoPath, dimensions };
+ return { playlistPath, videoPath, dimensions, videoSize };
};
/**
diff --git a/desktop/src/main/stream.ts b/desktop/src/main/stream.ts
index 1e2ae44013..396183c5cf 100644
--- a/desktop/src/main/stream.ts
+++ b/desktop/src/main/stream.ts
@@ -300,9 +300,9 @@ const handleGenerateHLSWrite = async (request: Request) => {
pendingVideoResults.set(playlistToken, result.playlistPath);
pendingVideoResults.set(videoToken, result.videoPath);
- const { dimensions } = result;
+ const { dimensions, videoSize } = result;
return new Response(
- JSON.stringify({ playlistToken, videoToken, dimensions }),
+ JSON.stringify({ playlistToken, videoToken, dimensions, videoSize }),
{ status: 200 },
);
};
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index aa2c1bd119..aad047acb8 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -403,10 +403,12 @@ const processQueueItem = async (
// TODO(HLS):
const fileBlob = await fetchOriginalVideoBlob(file, uploadItem);
+ const { objectID, url: objectUploadURL } =
+ await getFilePreviewDataUploadURL(file);
+
const res = await writeVideoStream(electron, "generate-hls", fileBlob!);
- const { playlistToken, videoToken, dimensions } = GenerateHLSResult.parse(
- await res.json(),
- );
+ const { playlistToken, videoToken, dimensions, videoSize } =
+ GenerateHLSResult.parse(await res.json());
try {
const playlistBlob = await readVideoStream(
@@ -414,31 +416,23 @@ const processQueueItem = async (
playlistToken,
).then((res) => res.blob());
- const { objectID, url: objectUploadURL } =
- await getFilePreviewDataUploadURL(file);
-
- // TOOD(HLS): Move this to the node side.
- const videoBlob = await readVideoStream(electron, videoToken).then(
- (res) => res.blob(),
- );
-
- const objectSize = videoBlob.size;
+ const videoRes = await readVideoStream(electron, videoToken);
// Video conversion is non-trivial effort, and the video segment file
// we're uploading is potentially very large, so add retries to avoid
// the need to redo everything in case of transient errors.
await retryEnsuringHTTPOkOr4xx(() =>
- fetch(objectUploadURL, { method: "PUT", body: videoBlob }),
+ fetch(objectUploadURL, { method: "PUT", body: videoRes.body }),
);
const playlistData = await encodePlaylistJSON({
type: "hls_video",
playlist: await playlistBlob.text(),
...dimensions,
- size: objectSize,
+ size: videoSize,
});
- await putVideoData(file, playlistData, objectID, objectSize);
+ await putVideoData(file, playlistData, objectID, videoSize);
} finally {
await Promise.all([
videoStreamDone(electron, playlistToken),
diff --git a/web/packages/gallery/utils/native-stream.ts b/web/packages/gallery/utils/native-stream.ts
index 9c67d3afc4..450e34e7e6 100644
--- a/web/packages/gallery/utils/native-stream.ts
+++ b/web/packages/gallery/utils/native-stream.ts
@@ -147,6 +147,10 @@ export const GenerateHLSResult = z.object({
* The dimensions (width and height in pixels) of the generated video stream.
*/
dimensions: z.object({ width: z.number(), height: z.number() }),
+ /**
+ * The size (in bytes) of the file containing the encrypted video segments.
+ */
+ videoSize: z.number(),
});
/**