Android: reading and writing metadata .mp4 -Tag

I want to read and edit (write) mp4 metadata. In particular, I want to read / write Tag metadata in android, as shown in the image below.

Mp4 Metadata Image

I searched this on the Internet and found mp4Parser, but I think mp4Parser does not write Title Keyword.

For the .jpg file, we use XPKeyword metadata that represents the name. Just like doing this for a .mp4 file.

+6
source share
2 answers

The Android SDK contains the MediaMetadataRetriever class, to get all the metadata values ​​inside your file, you can learn more about the 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."); } } 

enter image description here

There is no way for the Android SDK to edit / write metadata, perhaps on copyright issues, but you can use options such as:

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

+7
source

I hope it's not too late, but if you want to add / edit / delete metadata fields in MP4 files, you can use the JCodec metadata editing classes.

There is a CLI tool supported by the java API. The CLI is in org.jcodec.movtool.MetadataEditorMain , and the API is in org.jcodec.movtool.MetadataEditor .

More on this: http://jcodec.org/docs/working_with_mp4_metadata.html

So basically, when you want to add some metadata, you need to know which key (s) corresponds to it. One way to find out is to check out a sample file that already contains the necessary metadata. To do this, you can run the JCodec CLI tool, which will simply print all existing metadata fields (keys with values):

 ./metaedit <file.mp4> 

Then, when you know the key you want to work with, you can use the same CLI tool:

 # Changes the author of the movie ./metaedit -f -si ©ART=New\ value file.mov 

or the same through the Java API:

 MetadataEditor mediaMeta = MetadataEditor.createFrom(new File("file.mp4")); Map<Integer, MetaValue> meta = mediaMeta.getItunesMeta(); meta.put(0xa9415254, MetaValue.createString("New value")); // fourcc for '©ART' mediaMeta.save(false); // fast mode is off 

To remove a metadata field from a file:

 MetadataEditor mediaMeta = MetadataEditor.createFrom(new File("file.mp4")); Map<Integer, MetaValue> meta = mediaMeta.getItunesMeta(); meta.remove(0xa9415254); // removes the '©ART' mediaMeta.save(false); // fast mode is off 

To convert a string to an integer fourcc, you can use something like:

 byte[] bytes = "©ART".getBytes("iso8859-1"); int fourcc = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN).getInt(); 

If you want to edit / delete Android metadata, you will need to use a different set of fucntion (because it is stored differently than iTunes metadata):

 ./metaedit -sk com.android.capture.fps,float=25.0 file.mp4 

OR, alternatively, via the API:

 MetadataEditor mediaMeta = MetadataEditor.createFrom(new File("file.mp4")); Map<String, MetaValue> meta = mediaMeta.getKeyedMeta(); meta.put("com.android.capture.fps", MetaValue.createFloat(25.)); mediaMeta.save(false); // fast mode is off 
0
source

All Articles