Skip to content

armgit / ente

Public Imported from GitHub
0

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

Enable native video editor and add edit logging

Prateek Sunal1638a069cfe4
diff --git a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
index 6f9b55eee6..37d6e4b941 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
@@ -22,6 +22,7 @@ import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/tools/editor/export_video_service.dart";
import "package:photos/ui/tools/editor/native_video_export_service.dart";
import 'package:photos/ui/tools/editor/video_crop_page.dart';
+import "package:photos/ui/tools/editor/video_crop_util.dart";
import "package:photos/ui/tools/editor/video_editor/video_editor_app_bar.dart";
import "package:photos/ui/tools/editor/video_editor/video_editor_bottom_action.dart";
import "package:photos/ui/tools/editor/video_editor/video_editor_main_actions.dart";
@@ -95,23 +96,23 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
),
);
- _controller!.initialize().then((_) {
- // Apply metadata rotation to the video player
- if (_quarterTurnsForRotationCorrection != null &&
- _quarterTurnsForRotationCorrection! != 0) {
- final rotationDegrees = _quarterTurnsForRotationCorrection! * 90;
- _controller!.video.value = _controller!.video.value.copyWith(
- rotationCorrection: rotationDegrees,
- );
- }
- setState(() {});
- }).catchError(
- (error) {
- // handle minumum duration bigger than video duration error
- Navigator.pop(context);
- },
- test: (e) => e is VideoMinDurationError,
- );
+ _controller!
+ .initialize()
+ .then((_) {
+ // Apply metadata rotation to the video player
+ if (_quarterTurnsForRotationCorrection != null &&
+ _quarterTurnsForRotationCorrection! != 0) {
+ final rotationDegrees = _quarterTurnsForRotationCorrection! * 90;
+ _controller!.video.value = _controller!.video.value.copyWith(
+ rotationCorrection: rotationDegrees,
+ );
+ }
+ setState(() {});
+ })
+ .catchError((error) {
+ // handle minumum duration bigger than video duration error
+ Navigator.pop(context);
+ }, test: (e) => e is VideoMinDurationError);
});
}
@@ -138,7 +139,8 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
child: ValueListenableBuilder<bool>(
valueListenable: _isExporting,
builder: (context, isExporting, _) {
- final isReady = _controller != null &&
+ final isReady =
+ _controller != null &&
_controller!.initialized &&
_quarterTurnsForRotationCorrection != null;
@@ -205,8 +207,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
children: [
Text(
"Native (i)",
- style: getEnteTextTheme(context)
- .mini
+ style: getEnteTextTheme(context).mini
.copyWith(color: colorScheme.textMuted),
),
const SizedBox(width: 4),
@@ -235,9 +236,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
svgPath:
"assets/video-editor/video-editor-trim-action.svg",
onPressed: () => _openSubEditor(
- VideoTrimPage(
- controller: _controller!,
- ),
+ VideoTrimPage(controller: _controller!),
),
),
const SizedBox(width: 24),
@@ -246,9 +245,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
svgPath:
"assets/video-editor/video-editor-crop-action.svg",
onPressed: () => _openSubEditor(
- VideoCropPage(
- controller: _controller!,
- ),
+ VideoCropPage(controller: _controller!),
),
),
const SizedBox(width: 24),
@@ -257,9 +254,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
svgPath:
"assets/video-editor/video-editor-rotate-action.svg",
onPressed: () => _openSubEditor(
- VideoRotatePage(
- controller: _controller!,
- ),
+ VideoRotatePage(controller: _controller!),
),
),
],
@@ -281,6 +276,8 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
? _useNativeExport
: flagService.useNativeVideoEditor;
+ _logEditState(shouldUseNative: shouldUseNative);
+
_isExporting.value = true;
final dialogKey = GlobalKey<LinearProgressDialogState>();
@@ -322,9 +319,7 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
required GlobalKey<LinearProgressDialogState> dialogKey,
}) async {
if (shouldUseNative) {
- final tempDir = Directory.systemTemp.createTempSync(
- 'ente_video_export',
- );
+ final tempDir = Directory.systemTemp.createTempSync('ente_video_export');
final outputPath = path.join(
tempDir.path,
'export_${DateTime.now().millisecondsSinceEpoch}.mp4',
@@ -357,15 +352,11 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
dialogKey.currentState!.setProgress(0.0);
}
- return await _runFfmpegExport(
- dialogKey: dialogKey,
- );
+ return await _runFfmpegExport(dialogKey: dialogKey);
}
}
- return await _runFfmpegExport(
- dialogKey: dialogKey,
- );
+ return await _runFfmpegExport(dialogKey: dialogKey);
}
Future<File> _runFfmpegExport({
@@ -422,7 +413,8 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
return;
}
- final fileName = path.basenameWithoutExtension(widget.file.title!) +
+ final fileName =
+ path.basenameWithoutExtension(widget.file.title!) +
"_edited_" +
DateTime.now().microsecondsSinceEpoch.toString() +
".mp4";
@@ -502,6 +494,49 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
return Navigator.of(context).push(_VideoEditorSubPageRoute(child));
}
+ void _logEditState({required bool shouldUseNative}) {
+ final controller = _controller;
+ if (controller == null) {
+ _logger.info(
+ "Export requested but controller not ready (native=$shouldUseNative)",
+ );
+ return;
+ }
+
+ final rotation = controller.rotation;
+ final startTrimMs = controller.startTrim.inMilliseconds;
+ final endTrimMs = controller.endTrim.inMilliseconds;
+ final trimmedDurationMs = controller.trimmedDuration.inMilliseconds;
+ final videoDurationMs = controller.videoDuration.inMilliseconds;
+ final minTrim = controller.minTrim;
+ final maxTrim = controller.maxTrim;
+
+ String fileSpaceCropSummary;
+ try {
+ final crop = VideoCropUtil.calculateFileSpaceCrop(controller: controller);
+ fileSpaceCropSummary =
+ "file(x=${crop.x}, y=${crop.y}, w=${crop.width}, h=${crop.height})";
+ } catch (e) {
+ fileSpaceCropSummary = "file=unavailable(${e.runtimeType})";
+ }
+
+ final cropInfo =
+ "normalized(min=${_formatOffset(controller.minCrop)}, max=${_formatOffset(controller.maxCrop)}), "
+ "$fileSpaceCropSummary"
+ "${controller.preferredCropAspectRatio != null ? ", aspectRatio=${controller.preferredCropAspectRatio!.toStringAsFixed(3)}" : ""}";
+
+ _logger.info(
+ "Export starting (native=$shouldUseNative) rotation=${rotation}Β°, "
+ "trim={startMs:$startTrimMs, endMs:$endTrimMs, durationMs:$trimmedDurationMs, "
+ "min:${minTrim.toStringAsFixed(3)}, max:${maxTrim.toStringAsFixed(3)}, "
+ "videoDurationMs:$videoDurationMs} "
+ "crop={$cropInfo}",
+ );
+ }
+
+ String _formatOffset(Offset offset) =>
+ "(${offset.dx.toStringAsFixed(3)}, ${offset.dy.toStringAsFixed(3)})";
+
Future<void> _doRotationCorrectionIfAndroid() async {
if (Platform.isAndroid) {
try {
@@ -531,22 +566,22 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
class _VideoEditorSubPageRoute extends PageRouteBuilder<void> {
_VideoEditorSubPageRoute(this.child)
- : super(
- fullscreenDialog: true,
- transitionDuration: const Duration(milliseconds: 220),
- reverseTransitionDuration: const Duration(milliseconds: 180),
- pageBuilder: (_, __, ___) => child,
- transitionsBuilder: (_, animation, __, child) {
- return FadeTransition(
- opacity: CurvedAnimation(
- parent: animation,
- curve: Curves.easeOutCubic,
- reverseCurve: Curves.easeInCubic,
- ),
- child: child,
- );
- },
- );
+ : super(
+ fullscreenDialog: true,
+ transitionDuration: const Duration(milliseconds: 220),
+ reverseTransitionDuration: const Duration(milliseconds: 180),
+ pageBuilder: (_, __, ___) => child,
+ transitionsBuilder: (_, animation, __, child) {
+ return FadeTransition(
+ opacity: CurvedAnimation(
+ parent: animation,
+ curve: Curves.easeOutCubic,
+ reverseCurve: Curves.easeInCubic,
+ ),
+ child: child,
+ );
+ },
+ );
final Widget child;
}
diff --git a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
index 0d17c1c69e..4130c628f7 100644
--- a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
+++ b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
@@ -72,7 +72,7 @@ class FlagService {
bool get widgetSharedAlbums => internalUser;
- bool get useNativeVideoEditor => internalUser;
+ bool get useNativeVideoEditor => true;
bool get useWidgetV2 => kDebugMode;