Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Read and Write .mp4 metadata -Tag

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.

Mp4 Metadata 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.

like image 938
Ankesh kumar Jaisansaria Avatar asked Apr 30 '16 15:04

Ankesh kumar Jaisansaria


People also ask

Can you add metadata to MP4?

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.

Where are MP4 files stored on Android?

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.


1 Answers

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.");
    }
}

enter image description here

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

like image 92
Jorgesys Avatar answered Oct 13 '22 06:10

Jorgesys