sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.75k stars 566 forks source link

Question: how to add&read metadata to audio/video files? #363

Open AndroidDeveloperLB opened 5 years ago

AndroidDeveloperLB commented 5 years ago

I've seen this repository showing how to do it using the mp4parser repository (meaning here).

It works, but it uses an old version of the library ('com.googlecode.mp4parser:isoparser:1.1.22' instead of 'org.mp4parser:isoparser:1.9.37' ) . When updating to it, it doesn't work anymore (either doesn't read, or doesn't write) .

Is this really the best way to add and read metadata? Isn't there a better way? What's the official way to add and read metadata from an audio/video file? Which file formats are supported? Isn't there an API for this on Android itself?

HBiSoft commented 4 years ago

This is an old question, but hopefully it helps someone.

You can read/write metadata like this:

for(int i=0; i<video.getTracks().size();i++){
    Track videoTrack = video.getTracks().get(i);
    if(videoTrack.getHandler().equals("vide")){
        TrackMetaData metaData = videoTrack.getTrackMetaData();

        //Read Metadata
        double width = metaData.getWidth();
        double height = metaData.getHeight();

        //Write Metadata
        metaData.setHeight(yourDouble);
        metaData.setWidth(yourDouble);
    }
}

video is referring to Movie video = MovieCreator.build(new FileDataSourceViaHeapImpl(filePath));.

nonlin commented 1 year ago

what about custom metadata?

AndroidDeveloperLB commented 1 year ago

@HBiSoft What about metadata that exists in general, instead of in some points in the video/audio file? Also, does this work for audio files too?

adeds commented 1 year ago

please create a sample or documentation to write a custom metadata on existing file @sannies 🙏

i found this file btw: https://raw.githubusercontent.com/sannies/mp4parser/ff137905f8f7334c3013fa5fa461a438de49c7e1/examples/src/main/java/org/mp4parser/examples/metadata/MetaDataInsert.java