[mob][photos] Set aspect ratio of video

This commit is contained in:
ashilkn
2024-08-01 18:38:34 +05:30
parent 9b5b1d297b
commit 31318f10d6
2 changed files with 22 additions and 3 deletions

View File

@@ -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<VideoWidgetNative>
setState(() {
_filePath = url;
});
// setAspectRatioFromVideoProps().then((_) {
// setState(() {});
// });
_setAspectRatioFromVideoProps().then((_) {
setState(() {});
});
}
}
Future<void> _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;
}
}
}

View File

@@ -58,6 +58,7 @@ Future<Map<String, IfdTag>?> getExifFromSourceFile(File originFile) async {
Future<FFProbeProps?> getVideoPropsAsync(File originalFile) async {
try {
final stopwatch = Stopwatch()..start();
final Map<int, StringBuffer> logs = {};
final completer = Completer<MediaInformation?>();
@@ -95,6 +96,8 @@ Future<FFProbeProps?> 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);