From 48e566ae689cfa0e39e14ebe13dde21871bfdc77 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 30 Jul 2024 15:40:17 +0530 Subject: [PATCH 1/6] [mob][photos] Stop updating dimension in pubmmd as it could be inverted for some images --- mobile/lib/ui/viewer/file/zoomable_image.dart | 29 ++----------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/mobile/lib/ui/viewer/file/zoomable_image.dart b/mobile/lib/ui/viewer/file/zoomable_image.dart index c6c7ba003d..4df004b1a2 100644 --- a/mobile/lib/ui/viewer/file/zoomable_image.dart +++ b/mobile/lib/ui/viewer/file/zoomable_image.dart @@ -14,8 +14,6 @@ import 'package:photos/events/files_updated_event.dart'; import 'package:photos/events/local_photos_updated_event.dart'; import "package:photos/models/file/extensions/file_props.dart"; import 'package:photos/models/file/file.dart'; -import "package:photos/models/metadata/file_magic.dart"; -import "package:photos/services/file_magic_service.dart"; import "package:photos/ui/actions/file/file_actions.dart"; import 'package:photos/ui/common/loading_widget.dart'; import 'package:photos/utils/file_util.dart'; @@ -31,12 +29,12 @@ class ZoomableImage extends StatefulWidget { const ZoomableImage( this.photo, { - Key? key, + super.key, this.shouldDisableScroll, required this.tagPrefix, this.backgroundDecoration, this.shouldCover = false, - }) : super(key: key); + }); @override State createState() => _ZoomableImageState(); @@ -359,29 +357,6 @@ class _ZoomableImageState extends State { if (finalImageInfo == null && canUpdateMetadata && !_photo.hasDimensions) { finalImageInfo = await getImageInfo(finalImageProvider); } - if (finalImageInfo != null && canUpdateMetadata) { - _updateAspectRatioIfNeeded(_photo, finalImageInfo).ignore(); - } - } - - // Fallback logic to finish back fill and update aspect - // ratio if needed. - Future _updateAspectRatioIfNeeded( - EnteFile enteFile, - ImageInfo imageInfo, - ) async { - final int h = imageInfo.image.height, w = imageInfo.image.width; - if (h != enteFile.height || w != enteFile.width) { - final logMessage = - 'Updating aspect ratio for from ${enteFile.height}x${enteFile.width} to ${h}x$w'; - _logger.info(logMessage); - await FileMagicService.instance.updatePublicMagicMetadata([ - enteFile, - ], { - heightKey: h, - widthKey: w, - }); - } } bool _isGIF() => _photo.displayName.toLowerCase().endsWith(".gif"); From b2556e893b57b0abfe4f5a6ddb014078d26bb980 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 30 Jul 2024 16:18:30 +0530 Subject: [PATCH 2/6] [mob][photos] Parse rotation also when parsing video properties using ffprobe --- mobile/lib/models/ffmpeg/ffprobe_keys.dart | 4 +++- mobile/lib/models/ffmpeg/ffprobe_props.dart | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mobile/lib/models/ffmpeg/ffprobe_keys.dart b/mobile/lib/models/ffmpeg/ffprobe_keys.dart index 081fe0ff7e..5eddee32c8 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_keys.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_keys.dart @@ -28,7 +28,7 @@ class FFProbeKeys { static const date = 'date'; static const disposition = 'disposition'; static const duration = 'duration'; - static const quickTimeLocation ="com.apple.quicktime.location.ISO6709"; + static const quickTimeLocation = "com.apple.quicktime.location.ISO6709"; static const durationMicros = 'duration_us'; static const encoder = 'encoder'; static const extraDataSize = 'extradata_size'; @@ -70,6 +70,8 @@ class FFProbeKeys { static const vendorId = 'vendor_id'; static const width = 'width'; static const xiaomiSlowMoment = 'com.xiaomi.slow_moment'; + static const sideDataList = 'side_data_list'; + static const rotation = 'rotation'; } class MediaStreamTypes { diff --git a/mobile/lib/models/ffmpeg/ffprobe_props.dart b/mobile/lib/models/ffmpeg/ffprobe_props.dart index 027d0377ee..9023f83461 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_props.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_props.dart @@ -20,6 +20,7 @@ class FFProbeProps { String? fps; String? codecWidth; String? codecHeight; + int? rotation; // dot separated bitrate, fps, codecWidth, codecHeight. Ignore null value String get videoInfo { @@ -137,6 +138,8 @@ class FFProbeProps { } else if (key == FFProbeKeys.codedHeight) { result.codecHeight = stream[key].toString(); parsedData[key] = result.codecHeight; + } else if (key == FFProbeKeys.sideDataList) { + result.rotation = stream[key][0][FFProbeKeys.rotation]; } } } From 3f0855d9a41d91e5a947618f8dc267501d1ca7e0 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 30 Jul 2024 16:27:43 +0530 Subject: [PATCH 3/6] [mob][photos] write getter for video dimensions considering rotation in FFProbeProps --- mobile/lib/models/ffmpeg/ffprobe_props.dart | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mobile/lib/models/ffmpeg/ffprobe_props.dart b/mobile/lib/models/ffmpeg/ffprobe_props.dart index 9023f83461..cbe8d98f53 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_props.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_props.dart @@ -1,8 +1,10 @@ // Adapted from: https://github.com/deckerst/aves import "dart:developer"; +import "dart:ui"; import "package:collection/collection.dart"; +import "package:flutter/widgets.dart"; import "package:intl/intl.dart"; import "package:photos/models/ffmpeg/channel_layouts.dart"; import "package:photos/models/ffmpeg/codecs.dart"; @@ -33,6 +35,20 @@ class FFProbeProps { return info.join(' * '); } + Size? get videoDimentionsConsideringRotation { + final int width = int.tryParse(codecWidth ?? '0') ?? 0; + final int height = int.tryParse(codecHeight ?? '0') ?? 0; + if (width == 0 || height == 0) return null; + + if (rotation != null) { + if ((rotation! ~/ 90).isEven) { + return Size(width.toDouble(), height.toDouble()); + } else { + return Size(height.toDouble(), width.toDouble()); + } + } + } + // toString() method @override String toString() { From 6842218d2bf6f70f887f30f56424668790a40262 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 30 Jul 2024 16:37:10 +0530 Subject: [PATCH 4/6] [mob][photos] Remove unnecessary int to double conversion --- mobile/lib/models/ffmpeg/ffprobe_props.dart | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mobile/lib/models/ffmpeg/ffprobe_props.dart b/mobile/lib/models/ffmpeg/ffprobe_props.dart index cbe8d98f53..edf6845c7a 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_props.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_props.dart @@ -1,10 +1,8 @@ // Adapted from: https://github.com/deckerst/aves import "dart:developer"; -import "dart:ui"; import "package:collection/collection.dart"; -import "package:flutter/widgets.dart"; import "package:intl/intl.dart"; import "package:photos/models/ffmpeg/channel_layouts.dart"; import "package:photos/models/ffmpeg/codecs.dart"; @@ -35,16 +33,22 @@ class FFProbeProps { return info.join(' * '); } - Size? get videoDimentionsConsideringRotation { - final int width = int.tryParse(codecWidth ?? '0') ?? 0; - final int height = int.tryParse(codecHeight ?? '0') ?? 0; - if (width == 0 || height == 0) return null; + Map? get videoDimentionsConsideringRotation { + final int w = int.tryParse(codecWidth ?? '0') ?? 0; + final int h = int.tryParse(codecHeight ?? '0') ?? 0; + if (w == 0 || h == 0) return null; if (rotation != null) { if ((rotation! ~/ 90).isEven) { - return Size(width.toDouble(), height.toDouble()); + return { + "width": w, + "height": h, + }; } else { - return Size(height.toDouble(), width.toDouble()); + return { + "width": h, + "height": w, + }; } } } From 60d9a819f44ebf751b0b3c55e0b63c252c52abbe Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 30 Jul 2024 16:52:36 +0530 Subject: [PATCH 5/6] [mob][photos] Rename --- mobile/lib/models/ffmpeg/ffprobe_props.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/lib/models/ffmpeg/ffprobe_props.dart b/mobile/lib/models/ffmpeg/ffprobe_props.dart index edf6845c7a..367a143149 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_props.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_props.dart @@ -33,7 +33,7 @@ class FFProbeProps { return info.join(' * '); } - Map? get videoDimentionsConsideringRotation { + Map? get dimentionsConsideringRotation { final int w = int.tryParse(codecWidth ?? '0') ?? 0; final int h = int.tryParse(codecHeight ?? '0') ?? 0; if (w == 0 || h == 0) return null; From 08ba58d790d793a1b6961db104cb99b0e60b2913 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 30 Jul 2024 17:30:20 +0530 Subject: [PATCH 6/6] [mob][photos] Write getters to access correct height and width considering the rotation data and keep the raw codec height and width properties private in FFProbeProps --- mobile/lib/models/ffmpeg/ffprobe_props.dart | 65 +++++++++++++-------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/mobile/lib/models/ffmpeg/ffprobe_props.dart b/mobile/lib/models/ffmpeg/ffprobe_props.dart index 367a143149..b72c59f5ba 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_props.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_props.dart @@ -18,41 +18,56 @@ class FFProbeProps { String? bitrate; String? majorBrand; String? fps; - String? codecWidth; - String? codecHeight; - int? rotation; + String? _codecWidth; + String? _codecHeight; + int? _rotation; // dot separated bitrate, fps, codecWidth, codecHeight. Ignore null value String get videoInfo { final List info = []; if (bitrate != null) info.add('$bitrate'); if (fps != null) info.add('ƒ/$fps'); - if (codecWidth != null && codecHeight != null) { - info.add('$codecWidth x $codecHeight'); + if (_codecWidth != null && _codecHeight != null) { + info.add('$_codecWidth x $_codecHeight'); } return info.join(' * '); } - Map? get dimentionsConsideringRotation { - final int w = int.tryParse(codecWidth ?? '0') ?? 0; - final int h = int.tryParse(codecHeight ?? '0') ?? 0; - if (w == 0 || h == 0) return null; - - if (rotation != null) { - if ((rotation! ~/ 90).isEven) { - return { - "width": w, - "height": h, - }; + int? get width { + if (_codecWidth == null || _codecHeight == null) return null; + final intCodecWidth = int.tryParse(_codecWidth!); + if (_rotation == null) { + return intCodecWidth; + } else { + if ((_rotation! ~/ 90).isEven) { + return intCodecWidth; } else { - return { - "width": h, - "height": w, - }; + return int.tryParse(_codecHeight!); } } } + int? get height { + if (_codecWidth == null || _codecHeight == null) return null; + final intCodecHeight = int.tryParse(_codecHeight!); + if (_rotation == null) { + return intCodecHeight; + } else { + if ((_rotation! ~/ 90).isEven) { + return intCodecHeight; + } else { + return int.tryParse(_codecWidth!); + } + } + } + + double? get aspectRatio { + if (width == null || height == null || height == 0 || width == 0) { + return null; + } + return width! / height!; + } + // toString() method @override String toString() { @@ -153,13 +168,13 @@ class FFProbeProps { result.fps = _formatFPS(stream[key]); parsedData[key] = result.fps; } else if (key == FFProbeKeys.codedWidth) { - result.codecWidth = stream[key].toString(); - parsedData[key] = result.codecWidth; + result._codecWidth = stream[key].toString(); + parsedData[key] = result._codecWidth; } else if (key == FFProbeKeys.codedHeight) { - result.codecHeight = stream[key].toString(); - parsedData[key] = result.codecHeight; + result._codecHeight = stream[key].toString(); + parsedData[key] = result._codecHeight; } else if (key == FFProbeKeys.sideDataList) { - result.rotation = stream[key][0][FFProbeKeys.rotation]; + result._rotation = stream[key][0][FFProbeKeys.rotation]; } } }