From 31318f10d6da0aff609d20875012b309237f2c91 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 1 Aug 2024 18:38:34 +0530 Subject: [PATCH] [mob][photos] Set aspect ratio of video --- .../ui/viewer/file/video_widget_native.dart | 22 ++++++++++++++++--- mobile/lib/utils/exif_util.dart | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mobile/lib/ui/viewer/file/video_widget_native.dart b/mobile/lib/ui/viewer/file/video_widget_native.dart index 4754b4ba77..ba80325cf2 100644 --- a/mobile/lib/ui/viewer/file/video_widget_native.dart +++ b/mobile/lib/ui/viewer/file/video_widget_native.dart @@ -20,6 +20,7 @@ import "package:photos/theme/ente_theme.dart"; import "package:photos/ui/actions/file/file_actions.dart"; import "package:photos/ui/viewer/file/thumbnail_widget.dart"; import "package:photos/utils/dialog_util.dart"; +import "package:photos/utils/exif_util.dart"; import "package:photos/utils/file_util.dart"; import "package:photos/utils/toast_util.dart"; @@ -250,9 +251,24 @@ class _VideoWidgetNativeState extends State setState(() { _filePath = url; }); - // setAspectRatioFromVideoProps().then((_) { - // setState(() {}); - // }); + _setAspectRatioFromVideoProps().then((_) { + setState(() {}); + }); + } + } + + Future _setAspectRatioFromVideoProps() async { + final videoProps = await getVideoPropsAsync(File(_filePath!)); + if (videoProps != null) { + if (videoProps.width != null && videoProps.height != null) { + aspectRatio = videoProps.width! / videoProps.height!; + } else { + _logger.info("Video props width and height are null"); + aspectRatio = 1; + } + } else { + _logger.info("Video props are null"); + aspectRatio = 1; } } } diff --git a/mobile/lib/utils/exif_util.dart b/mobile/lib/utils/exif_util.dart index d9bac85e6d..cbe09502e8 100644 --- a/mobile/lib/utils/exif_util.dart +++ b/mobile/lib/utils/exif_util.dart @@ -58,6 +58,7 @@ Future?> getExifFromSourceFile(File originFile) async { Future getVideoPropsAsync(File originalFile) async { try { + final stopwatch = Stopwatch()..start(); final Map logs = {}; final completer = Completer(); @@ -95,6 +96,8 @@ Future getVideoPropsAsync(File originalFile) async { return null; } final properties = await FFProbeUtil.getProperties(mediaInfo); + _logger.info("getVideoPropsAsync took ${stopwatch.elapsedMilliseconds}ms"); + stopwatch.stop(); return properties; } catch (e, s) { _logger.severe("Failed to getVideoProps", e, s);