-
Notifications
You must be signed in to change notification settings - Fork 483
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
Add support for MP4 UUID and MOV XMP boxes #451
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.drew.metadata.mp4.boxes; | ||
|
||
import com.drew.lang.SequentialReader; | ||
import com.drew.metadata.mp4.Mp4Directory; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.util.UUID; | ||
|
||
import static com.drew.metadata.mp4.media.Mp4UserBoxDirectory.*; | ||
|
||
public class UserBox extends Box { | ||
|
||
private byte[] userData; | ||
|
||
public UserBox(SequentialReader reader, Box box) throws IOException { | ||
super(box); | ||
|
||
if (type.equals("uuid")) { | ||
usertype = getUuid(reader.getBytes(16)); | ||
} | ||
|
||
userData = reader.getBytes(reader.available()); | ||
} | ||
|
||
public void addMetadata(Mp4Directory directory) | ||
{ | ||
directory.setString(TAG_UUID, usertype); | ||
directory.setLong(TAG_LENGTH, userData.length); | ||
directory.setByteArray(TAG_USER_DATA, userData); | ||
} | ||
|
||
public String getUuid(byte[] bytes) { | ||
ByteBuffer bb = ByteBuffer.wrap(bytes); | ||
UUID uuid = new UUID(bb.getLong(), bb.getLong()); | ||
|
||
return uuid.toString(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/com/drew/metadata/mp4/media/Mp4UserBoxDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.drew.metadata.mp4.media; | ||
|
||
import com.drew.metadata.TagDescriptor; | ||
|
||
public class Mp4UserBoxDescriptor extends TagDescriptor<Mp4UserBoxDirectory> { | ||
|
||
public Mp4UserBoxDescriptor(Mp4UserBoxDirectory directory) { | ||
super(directory); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Source/com/drew/metadata/mp4/media/Mp4UserBoxDirectory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.drew.metadata.mp4.media; | ||
|
||
import com.drew.lang.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
|
||
public class Mp4UserBoxDirectory extends Mp4MediaDirectory { | ||
public static final Integer TAG_UUID = 901; | ||
public static final Integer TAG_LENGTH = 902; | ||
public static final Integer TAG_USER_DATA = 903; | ||
|
||
@NotNull | ||
private static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>(); | ||
|
||
static { | ||
Mp4UserBoxDirectory.addMp4MediaTags(_tagNameMap); | ||
_tagNameMap.put(TAG_UUID, "uuid"); | ||
_tagNameMap.put(TAG_LENGTH, "length"); | ||
_tagNameMap.put(TAG_USER_DATA, "data"); | ||
} | ||
|
||
public Mp4UserBoxDirectory() { | ||
this.setDescriptor(new Mp4UserBoxDescriptor(this)); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getName() { | ||
return "UserData"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected HashMap<Integer, String> getTagNameMap() { | ||
return _tagNameMap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.drew.metadata.mp4.media; | ||
|
||
import com.drew.imaging.mp4.Mp4Handler; | ||
import com.drew.lang.SequentialByteArrayReader; | ||
import com.drew.lang.SequentialReader; | ||
import com.drew.metadata.Metadata; | ||
import com.drew.metadata.mp4.Mp4Context; | ||
import com.drew.metadata.mp4.boxes.Box; | ||
import com.drew.metadata.mp4.boxes.UserBox; | ||
|
||
import java.io.IOException; | ||
|
||
public class Mp4UserBoxHandler<T extends Mp4UserBoxDirectory> extends Mp4Handler<Mp4UserBoxDirectory> { | ||
|
||
public Mp4UserBoxHandler(Metadata metadata) { | ||
super(metadata); | ||
} | ||
|
||
@Override | ||
protected Mp4UserBoxDirectory getDirectory() { | ||
return new Mp4UserBoxDirectory(); | ||
} | ||
|
||
@Override | ||
protected boolean shouldAcceptBox(Box box) { | ||
return box.type.equals("uuid"); | ||
} | ||
|
||
@Override | ||
protected boolean shouldAcceptContainer(Box box) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Mp4Handler processBox(Box box, byte[] payload, Mp4Context context) throws IOException { | ||
if (payload != null) { | ||
SequentialReader reader = new SequentialByteArrayReader(payload); | ||
UserBox userBox = new UserBox(reader, box); | ||
userBox.addMetadata(directory); | ||
} | ||
|
||
return this; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tag is redundant, given it can be derived from the data itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. Sorry I wasn't more clear about the test data. We can't add test media data to this repo without it becoming huge. There's a separate repo for this:
https://github.com/drewnoakes/metadata-extractor-images
I uploaded the test data you provided (thanks very much for preparing these):
drewnoakes/metadata-extractor-images@0f1e3cd
I'm happy to edit your PR's commits to remove those files, unless you'd like to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sure, you can move these files, thanks