I want to read and edit(Write) the mp4 metadata. Particularly I want to read/write Tag metadata in android as shown in below picture.
I searched for this on internet and found mp4Parser, but I think mp4Parser don't write Title Keyword.
For .jpg file we use XPKeyword metadata which represents title. So same way how to do same for .mp4 file.
Step 1 Add MP4 file into the metadata tagger for MP4. Go to the Toolbox section > Fix Media Metadata to enter the metadata editing window. And click … button to add the MP4 video that you want to edit metadata.
Tap ☰. You'll find this menu icon in the top left corner of the app and a menu will slide out from the left. Tap Directories. You'll see folders for your internal storage as well as folders where MP4 files are typically found.
The Android SDK contains the class MediaMetadataRetriever to retrieve all the metadata values inside your file, you can read more about MetaData values here.
public void readMetaData() {
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/Android/data/myfile.mp4");
if (file.exists()) {
Log.i(TAG, ".mp4 file Exist");
//Added in API level 10
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(file.getAbsolutePath());
for (int i = 0; i < 1000; i++){
//only Metadata != null is printed!
if(retriever.extractMetadata(i)!=null) {
Log.i(TAG, "Metadata :: " + retriever.extractMetadata(i));
}
}
} catch (Exception e) {
Log.e(TAG, "Exception : " + e.getMessage());
}
} else {
Log.e(TAG, ".mp4 file doesn´t exist.");
}
}
To edit/write metadata, Android SDK doesn´t have any method, probably by copyright issues, but you can use options like:
https://github.com/sannies/mp4parser
http://multimedia.cx/eggs/supplying-ffmpeg-with-metadata/
https://github.com/bytedeco/javacv/blob/master/src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With