Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug in motion photo detection #2

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.0.6
* Fixed invalid motion photo detection for Motion photo Top Shot.

## 0.0.5
* Fixed invalid motion photo detection for Pixel Pro 8.

Expand Down
Binary file added assets/pixel_6_small_video.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.3"
version: "0.0.5"
path:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class MotionPhotoConstants {
];

static String itemLengthOffsetKey = 'Item:Length';
static String GCameraMotionPhoto = 'GCamera:MotionPhoto';
static String ItemMimeType = 'Item:MimeType';

///[fileOffsetKeys] XMP Key for a Motion Photo Video Offset
static List<String> fileOffsetKeys = [
Expand Down
15 changes: 14 additions & 1 deletion lib/src/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class MotionPhotoHelpers {
if (xmpData.containsKey(offSetKey)) {
final offsetFromEnd = int.parse(xmpData[offSetKey]);
if (offSetKey == MotionPhotoConstants.itemLengthOffsetKey) {
if (offsetFromEnd + offsetFromEnd < size) {
if (offsetFromEnd + offsetFromEnd < size &&
!hasMotionPhotoTags(xmpData)) {
log('Found ${MotionPhotoConstants.itemLengthOffsetKey} but video length looks invalid');
continue;
}
Expand All @@ -31,4 +32,16 @@ class MotionPhotoHelpers {
}
return null;
}

static bool hasMotionPhotoTags(Map<String, dynamic> xmpData) {
if (xmpData.containsKey(MotionPhotoConstants.GCameraMotionPhoto)) {
return true;
}
if (xmpData.containsKey(MotionPhotoConstants.ItemMimeType)) {
return xmpData[MotionPhotoConstants.ItemMimeType]
.toString()
.startsWith('video');
}
return false;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: motion_photos
description: A Flutter package for detecting and extracting motionphotos from a image file.
version: 0.0.5
version: 0.0.6
homepage: https://ente.io

environment:
Expand Down
6 changes: 6 additions & 0 deletions test/motion_photos_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ void main() {
expect(await motionPhotos.isMotionPhoto(), true);
});

// https://github.com/ente-io/photos-app/issues/1551
test('Pixel 6 Top shot', () async {
final motionPhotos = MotionPhotos('assets/pixel_6_small_video.jpg');
expect(await motionPhotos.isMotionPhoto(), true);
});

test('Not a MotionPhoto', () async {
final motionPhotos = MotionPhotos('assets/normalphoto.jpg');
expect(await motionPhotos.isMotionPhoto(), false);
Expand Down
Loading