π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix: update isolated function
Prateek Sunal5eef2a5816e2
diff --git a/mobile/lib/main.dart b/mobile/lib/main.dartindex c4ae34fa28..93d82b567b 100644--- a/mobile/lib/main.dart+++ b/mobile/lib/main.dart@@ -33,6 +33,7 @@ import 'package:photos/services/collections_service.dart';import 'package:photos/services/favorites_service.dart';import "package:photos/services/filedata/filedata_service.dart";import 'package:photos/services/home_widget_service.dart';+import "package:photos/services/isolated_ffmpeg_service.dart";import 'package:photos/services/local_file_update_service.dart';import "package:photos/services/machine_learning/face_ml/person/person_service.dart";import 'package:photos/services/machine_learning/ml_service.dart';@@ -212,6 +213,8 @@ Future<void> _init(bool isBackground, {String via = ''}) async {Computer.shared().turnOn(workersCount: 4).ignore();CryptoUtil.init();+ IsolatedFfmpegService.init();+_logger.info("Lockscreen init $tlog");unawaited(LockScreenSettings.instance.init(preferences));diff --git a/mobile/lib/services/isolated_ffmpeg_service.dart b/mobile/lib/services/isolated_ffmpeg_service.dartindex e688ea5810..78db724214 100644--- a/mobile/lib/services/isolated_ffmpeg_service.dart+++ b/mobile/lib/services/isolated_ffmpeg_service.dart@@ -1,12 +1,24 @@+import "package:computer/computer.dart";import "package:ffmpeg_kit_flutter/ffmpeg_kit.dart";import "package:ffmpeg_kit_flutter/ffmpeg_session.dart";class IsolatedFfmpegService {- static Future<FFmpegSession> ffmpegRun(Map args) async {- final command = args['command'] as String;+ static final Computer _computer = Computer.create();- final session = await FFmpegKit.execute(command);+ static void init() {+ _computer.turnOn(workersCount: 1);+ }+ static Future<FFmpegSession> runFfmpeg(String command) async {+ return _computer.compute<Map, FFmpegSession>(+ _ffmpegRun,+ param: {'command': command},+ );+ }++ static Future<FFmpegSession> _ffmpegRun(Map args) async {+ final command = args['command'] as String;+ final session = await FFmpegKit.execute(command);return session;}}diff --git a/mobile/lib/services/preview_video_store.dart b/mobile/lib/services/preview_video_store.dartindex d91756bc52..b426198f0b 100644--- a/mobile/lib/services/preview_video_store.dart+++ b/mobile/lib/services/preview_video_store.dart@@ -4,7 +4,6 @@ import "dart:convert";import "dart:io";import "package:collection/collection.dart";-import "package:computer/computer.dart";import "package:dio/dio.dart";import "package:encrypt/encrypt.dart" as enc;import "package:ffmpeg_kit_flutter/ffmpeg_session.dart";@@ -226,69 +225,52 @@ class PreviewVideoStore {// case 1, if it's already a good streamif (bitrate != null && bitrate <= 4000 * 1000 && codecIsH264) {- session = await Computer.shared().compute(- IsolatedFfmpegService.ffmpegRun,- param: {- "command": '-i "${file.path}" '- '-c:v copy -c:a copy '- '-f hls -hls_time 2 -hls_flags single_file '- '-hls_list_size 0 -hls_key_info_file ${keyinfo.path} '- '$prefix/output.m3u8',- },+ session = await IsolatedFfmpegService.runFfmpeg(+ '-i "${file.path}" '+ '-c:v copy -c:a copy '+ '-f hls -hls_time 2 -hls_flags single_file '+ '-hls_list_size 0 -hls_key_info_file ${keyinfo.path} '+ '$prefix/output.m3u8',);} // case 2, if it's bitrate is good, but codec is notelse if (bitrate != null &&codec != null &&bitrate <= 2000 * 1000 &&!codecIsH264) {- session = await Computer.shared().compute(- IsolatedFfmpegService.ffmpegRun,- param: {- "command": '-i "${file.path}" '- '-vf "format=yuv420p10le,zscale=transfer=linear,tonemap=tonemap=hable:desat=0:peak=10,zscale=transfer=bt709:matrix=bt709:primaries=bt709,format=yuv420p" '- '-color_primaries bt709 -color_trc bt709 -colorspace bt709 '- '-c:v libx264 -crf 23 -preset medium '- '-c:a copy '- '-f hls -hls_time 2 -hls_flags single_file '- '-hls_list_size 0 -hls_key_info_file ${keyinfo.path} '- '$prefix/output.m3u8',- },+ session = await IsolatedFfmpegService.runFfmpeg(+ '-i "${file.path}" '+ '-vf "format=yuv420p10le,zscale=transfer=linear,tonemap=tonemap=hable:desat=0:peak=10,zscale=transfer=bt709:matrix=bt709:primaries=bt709,format=yuv420p" '+ '-color_primaries bt709 -color_trc bt709 -colorspace bt709 '+ '-c:v libx264 -crf 23 -preset medium '+ '-c:a copy '+ '-f hls -hls_time 2 -hls_flags single_file '+ '-hls_list_size 0 -hls_key_info_file ${keyinfo.path} '+ '$prefix/output.m3u8',);} // case 3, if it's color space is goodelse if (colorSpace != null && isColorGood) {- session = await Computer.shared().compute(- IsolatedFfmpegService.ffmpegRun,- param: {- "command": '-i "${file.path}" '- '-vf "scale=-2:720,fps=30" '- '-c:v libx264 -b:v 2000k -crf 23 -preset medium '- '-c:a aac -b:a 128k -f hls -hls_time 2 -hls_flags single_file '- '-hls_list_size 0 -hls_key_info_file ${keyinfo.path} '- '$prefix/output.m3u8',- },+ session = await IsolatedFfmpegService.runFfmpeg(+ '-i "${file.path}" '+ '-vf "scale=-2:720,fps=30" '+ '-c:v libx264 -b:v 2000k -crf 23 -preset medium '+ '-c:a aac -b:a 128k -f hls -hls_time 2 -hls_flags single_file '+ '-hls_list_size 0 -hls_key_info_file ${keyinfo.path} '+ '$prefix/output.m3u8',);} // case 4, make it compatibleelse {- session = await Computer.shared().compute(- IsolatedFfmpegService.ffmpegRun,- param: {- "command": '-i "${file.path}" '- '-vf "scale=-2:720,fps=30,format=yuv420p10le,zscale=transfer=linear,tonemap=tonemap=hable:desat=0:peak=10,zscale=transfer=bt709:matrix=bt709:primaries=bt709,format=yuv420p" '- '-color_primaries bt709 -color_trc bt709 -colorspace bt709 '- '-x264-params "colorprim=bt709:transfer=bt709:colormatrix=bt709" '- '-c:v libx264 -b:v 2000k -crf 23 -preset medium '- '-c:a aac -b:a 128k -f hls -hls_time 2 -hls_flags single_file '- '-hls_list_size 0 -hls_key_info_file ${keyinfo.path} '- '$prefix/output.m3u8',- },+ session = await IsolatedFfmpegService.runFfmpeg(+ '-i "${file.path}" '+ '-vf "scale=-2:720,fps=30,format=yuv420p10le,zscale=transfer=linear,tonemap=tonemap=hable:desat=0:peak=10,zscale=transfer=bt709:matrix=bt709:primaries=bt709,format=yuv420p" '+ '-color_primaries bt709 -color_trc bt709 -colorspace bt709 '+ '-x264-params "colorprim=bt709:transfer=bt709:colormatrix=bt709" '+ '-c:v libx264 -b:v 2000k -crf 23 -preset medium '+ '-c:a aac -b:a 128k -f hls -hls_time 2 -hls_flags single_file '+ '-hls_list_size 0 -hls_key_info_file ${keyinfo.path} '+ '$prefix/output.m3u8',);}- if (session == null) {- error = "Failed to create ffmpeg session";- return;- }-final returnCode = await session.getReturnCode();String? objectId;@@ -314,11 +296,8 @@ class PreviewVideoStore {objectSize = result.$2;// Fetch resolution of generated stream by decrypting a single frame- final FFmpegSession session2 = await Computer.shared().compute(- IsolatedFfmpegService.ffmpegRun,- param: {- '-allowed_extensions ALL -i "$prefix/output.m3u8" -frames:v 1 -c copy "$prefix/frame.ts"',- },+ final FFmpegSession session2 = await IsolatedFfmpegService.runFfmpeg(+ '-allowed_extensions ALL -i "$prefix/output.m3u8" -frames:v 1 -c copy "$prefix/frame.ts"',);final returnCode2 = await session2.getReturnCode();int? width, height;