Skip to content

Commit

Permalink
Add a check of mixed resolution when creating movie.
Browse files Browse the repository at this point in the history
  • Loading branch information
phileastv committed Dec 26, 2023
1 parent 19922ff commit d64f745
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/lang/en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,8 @@ const Map<String, String> en = {
'useAlternativeCalendarColors': 'Use alternative calendar colors',
'useAlternativeCalendarColorsDescription':
'Changes green and red in calendar to blue and yellow. Useful for colorblind people.',
'mixedResolutionAlert' : 'Mixed Resolutions detected',
'mixedResolutionAlertDescription' : 'At least one snippet seems to have a different resolution.\n\n'
'This can cause unexpected results when using your film.\n\n'
'Try to delete theses files or move them to a different profile.'
};
6 changes: 5 additions & 1 deletion lib/lang/fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,9 @@ const Map<String, String> fr = {
'Lorsqu\'il est activé, sélectionner des dates passées filtrera les vidéos par cette date. Lorsqu\'il est désactivé, toutes les vidéos seront affichées. Fonctionne uniquement avec le sélecteur de fichiers expérimental.',
'useAlternativeCalendarColors': 'Utilisez des couleurs de calendrier alternatives',
'useAlternativeCalendarColorsDescription':
'Change le vert et le rouge dans le calendrier en bleu et jaune. Utile pour les personnes daltoniennes.'
'Change le vert et le rouge dans le calendrier en bleu et jaune. Utile pour les personnes daltoniennes.',
'mixedResolutionAlert' : 'Mix de résolutions détecté.',
'mixedResolutionAlertDescription' : 'Au moins une vidéo semble avoir un mix de résolutions.\n\n'
'Cela peut produire des résultats innatendus lorsque vous utilisez votre film.\n\n'
'Essayez de supprimer ces fichiers ou de les déplacer dans un autre profil.'
};
39 changes: 39 additions & 0 deletions lib/pages/home/create_movie/widgets/create_movie_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class _CreateMovieButtonState extends State<CreateMovieButton> {
final VideoCountController controller = Get.find();
bool isProcessing = false;
String progress = '';
String usedResolution = '';
var mixedResolutionError = [];

void _openVideo(String filePath) async {
await OpenFilex.open(filePath);
Expand Down Expand Up @@ -153,6 +155,27 @@ class _CreateMovieButtonState extends State<CreateMovieButton> {
}
});

// Checks if there is a mix of horizontal/vertical videos by comparing their resolution.
await executeFFprobe(
'-v quiet -show_entries stream=width,height -of default=nw=1:nk=1 "$currentVideo"')
.then((session) async {
final returnCode = await session.getReturnCode();
if (ReturnCode.isSuccess(returnCode)) {
final sessionLog = await session.getOutput();
if (sessionLog == usedResolution) {
return;
} else if (usedResolution == '' && sessionLog!.isNotEmpty) {
usedResolution = sessionLog;
} else {
mixedResolutionError.add(currentVideo);
}
} else {
final sessionLog = await session.getLogsAsString();
Utils.logError('${logTag}Error checking if $currentVideo was recorded on v1.5');
Utils.logError('${logTag}Error: $sessionLog');
}
});

// Make sure all selected videos have a subtitles and audio stream before creating movie, and finally check their resolution, resizes if necessary.
// To avoid asking permission for every single video, we make a copy and leave the original untouched
if (!isV1point5) {
Expand Down Expand Up @@ -278,6 +301,22 @@ class _CreateMovieButtonState extends State<CreateMovieButton> {
});
}

// Show an error if multiple resolutions is detected.
if(mixedResolutionError.isNotEmpty) {
showDialog(
barrierDismissible: false,
context: Get.context!,
builder: (context) => CustomDialog(
isDoubleAction: false,
title: 'mixedResolutionAlert'.tr,
content: "${'mixedResolutionAlertDescription'.tr}\n\n${mixedResolutionError.toString()}",
actionText: 'Ok',
actionColor: Colors.red,
action: () => Get.offAllNamed(Routes.HOME),
),
);
}

if (mounted) {
setState(() {
progress = '$currentIndex / ${selectedVideos.length}';
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/save_video/widgets/save_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ class _SaveButtonState extends State<SaveButton> {
final returnCode = await session.getReturnCode();
if (ReturnCode.isSuccess(returnCode)) {
final sessionLog = await session.getOutput();
Utils.logInfo('résultat ffprobe : $sessionLog');
// 4:3 vidéos (ex : produced by pixel devices in photo modes), will be scaled up to fit into 1080x1920.
// 4:3 videos (ex : produced by pixel devices in photo modes), will be scaled up to fit into 1080x1920.
if (sessionLog!.contains('4:3')) {
scale = 'scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920';
Utils.logInfo('${logTag}4/3 video detected, cropping to 9/16.');
Expand Down

0 comments on commit d64f745

Please sign in to comment.