diff --git a/MetadataExtractor.Tests/Data/apple-livephoto-quicktime.mov b/MetadataExtractor.Tests/Data/apple-livephoto-quicktime.mov new file mode 100644 index 000000000..234aec5ec Binary files /dev/null and b/MetadataExtractor.Tests/Data/apple-livephoto-quicktime.mov differ diff --git a/MetadataExtractor.Tests/Formats/Apple/LivePhotoMovTest.cs b/MetadataExtractor.Tests/Formats/Apple/LivePhotoMovTest.cs new file mode 100644 index 000000000..f16d37cc1 --- /dev/null +++ b/MetadataExtractor.Tests/Formats/Apple/LivePhotoMovTest.cs @@ -0,0 +1,42 @@ +// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. +namespace MetadataExtractor.Tests.Formats.Apple; + +public sealed class LivePhotoMovTest +{ + private const string TestFile = "Data/apple-livephoto-quicktime.mov"; + + [Fact] + public void GetLivePhotoQuickTimeInfo() + { + var exception = Record.Exception(() => ImageMetadataReader.ReadMetadata(TestFile)); + Assert.Null(exception); + } + + [Fact] + public void GetDirectoryNames() + { + var directories =ImageMetadataReader.ReadMetadata(TestFile); + Assert.NotNull(directories); + Assert.NotEmpty(directories); + var names = directories.Select(d => d.Name).ToArray(); + Assert.Contains("QuickTime Movie Header", names); + Assert.Contains("QuickTime Track Header", names); + Assert.Contains("QuickTime Metadata Header", names); + Assert.Contains("File Type", names); + Assert.Contains("File", names); + } + + /// + /// Live Photos is actually two files. Original JPEG/HEIF Image and Full HD Video(QuickTime). + /// in the ios ecology, live photo connect image with mov with same name, and meta key `Content Identifier` + /// + [Fact] + public void GetLivePhotoContentIdentifier() + { + var directories =ImageMetadataReader.ReadMetadata(TestFile); + var quickTimeMetadataHeaderDirectory = directories.Where(d => d.Name == "QuickTime Metadata Header")!.First(); + var contentIdentifierTag = quickTimeMetadataHeaderDirectory.Tags.Where(t => t.Name == "Content Identifier")!.First(); + Assert.Equal("EE6D649E-788F-4E3A-BCD2-483651BF7B34", contentIdentifierTag.Description); + } + +} diff --git a/MetadataExtractor/Formats/QuickTime/QuickTimeTypeChecker.cs b/MetadataExtractor/Formats/QuickTime/QuickTimeTypeChecker.cs index 3d1c54bba..ba343f389 100644 --- a/MetadataExtractor/Formats/QuickTime/QuickTimeTypeChecker.cs +++ b/MetadataExtractor/Formats/QuickTime/QuickTimeTypeChecker.cs @@ -63,13 +63,33 @@ internal sealed class QuickTimeTypeChecker : ITypeChecker private static ReadOnlySpan FtypBytes => "ftyp"u8; - public int ByteCount => 12; + public int ByteCount => 16; public Util.FileType CheckType(byte[] bytes) { - return bytes.AsSpan(4, 4).SequenceEqual(FtypBytes) - ? _ftypTrie.Find(bytes.AsSpan(8, 4)) - : Util.FileType.Unknown; + // for standard apple quicktime format + // 00000000: 0000 0014 6674 7970 7174 2020 0000 0000 ....ftypqt .... + // 00000010: 7174 2020 0000 0008 7769 6465 003e f32a qt ....wide.>.* + // 00000020: 6d64 6174 cefe f2fe 09ff 09ff 0dff 31ff mdat..........1. + if (bytes.AsSpan(4, 4).SequenceEqual(FtypBytes)) + { + return _ftypTrie.Find(bytes.AsSpan(8, 4)); + } + + // for live photo which is export from native protocols with afcclient/afcservice + // example 1 + // 00000000: 0000 0008 7769 6465 0033 a50e 6d64 6174 ....wide.3..mdat + // 00000010: 0000 001f 4e01 051a 4756 4adc 5c4c 433f ....N...GVJ.\LC? + // 00000020: 94ef c511 3cd1 43a8 03ee 1111 ee02 00c3 ....<.C......... + // example 2 + // 00000000: 0000 0008 7769 6465 004f 854d 6d64 6174 ....wide.O.Mmdat + // 00000010: 0000 002a 4e01 0523 4756 4adc 5c4c 433f ...*N..#GVJ.\LC? + // 00000020: 94ef c511 3cd1 43a8 0000 0300 0003 0000 ....<.C......... + if (bytes.AsSpan(4, 4).SequenceEqual("wide"u8) && bytes.AsSpan(12, 4).SequenceEqual("mdat"u8)) + { + return Util.FileType.QuickTime; + } + return Util.FileType.Unknown; } } } diff --git a/MetadataExtractor/MetadataExtractor.csproj b/MetadataExtractor/MetadataExtractor.csproj index b99c8c17c..c52d76d61 100644 --- a/MetadataExtractor/MetadataExtractor.csproj +++ b/MetadataExtractor/MetadataExtractor.csproj @@ -8,6 +8,7 @@ MOV and related QuickTime video formats such as MP4, M4V, 3G2, 3GP are supported Camera manufacturer specific support exists for Agfa, Canon, Casio, DJI, Epson, Fujifilm, Kodak, Kyocera, Leica, Minolta, Nikon, Olympus, Panasonic, Pentax, Reconyx, Sanyo, Sigma/Foveon and Sony models. Metadata Extractor + MetadataExtractor.NaughtyGitCat net8.0;netstandard1.3;netstandard2.1;net462 $(NoWarn);1591 true