Skip to content

Commit

Permalink
Merge pull request #2 from ente-io/fix_bug
Browse files Browse the repository at this point in the history
Fixed bug in motion photo detection
  • Loading branch information
ua741 authored Nov 30, 2023
2 parents e4edd3a + ebcc8fd commit f1ec3d3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
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

0 comments on commit f1ec3d3

Please sign in to comment.