Java library for checking video metadata (if it's 1080p, 720p, etc.),

I'm currently looking for a library that looks at video metadata and checks if the video is 1080p, 720p, or at least be able to get basic metadata (resolution, bit rate, etc.) so that I can perform calculations to verify I myself.

I hope the library is light, cross-platform, and it can support a number of basic formats. Something like https://github.com/drewnoakes/metadata-extractor , but of course for the video.

I tried searching and found nothing, does such a library exist?

+7
source share
2 answers

I haven't tried it yet, but Java MP4 Parser looks like this is what I was looking for. It is capable of reading and editing metadata, a cross-platform and, it seems, light in file size.

Excerpt from github documentation:

Java MP4 Parser

Java API for reading, writing, and creating an MP4 container. Manipulating containers are different from encoding and decoding video and audio. Library usage

The library is published in the Maven repositories. Each release is clicked to an intermediate repository, which is published on the release page. At the request of specific releases can be clicked on the central part of maven.

<dependency> <groupId>com.googlecode.mp4parser</groupId> <artifactId>isoparser</artifactId> <version>1.1.7</version> </dependency> 

For projects that do not use the dependency management tool, each (jar, javadoc-jar, source-jar) is attached to the release. Keep in mind that the project requires aspectj-rt.jar.

What can you do?

Typical tasks for the MP4 parser are:

  • Cartoon audio / video to MP4 file
  • Add records that use the same encoding settings
  • Adding / Modifying Metadata
  • Shorten records by omitting frames. My examples will use H264 and AAC, since these two codecs are most typical for MP4 files. AC-3 is also not uncommon since the codec is well known with DVD. These are also MP4 files with H263 / MPEG-2 video tracks, but they are no longer used as widespread as most Android phones. you also can

Multimedia Audio / Video

The API and the process are straightforward:

You complete each raw file in the corresponding Track object.

H264TrackImpl h264Track = new H264TrackImpl (new FileDataSourceImpl ("video.h264")); AACTrackImpl aacTrack = new AACTrackImpl (new FileDataSourceImpl ("audio.aac"));

These Track objects are then added to the Movie object.

 Movie movie = new Movie(); movie.addTrack(h264Track); movie.addTrack(aacTrack); 

The Movie object is passed to MP4Builder to create the container.

 Container mp4file = new DefaultMp4Builder().build(movie); 

Put the container in a suitable sink.

FileChannel fc = new FileOutputStream (new File ("output.mp4")) GetChannel (). mp4file.writeContainer (k); fc.close (); There are times when the frame rate is signaled from or is known in advance so that H264 does not contain it literally. In this case, you will have to pass it to the constructor.

There are track implementations for the following formats:

  • H264
  • Aac
  • AC3
  • EC3

and additionally two subtitle tracks that do not directly wrap but are conceptually similar.

Typical problems

Audio and video are not synced. Whenever problems arise with the time possible, be sure to run

The sound begins before the video

There is always samplerate / 1024 sample / s in AAC, so each sample is 1000 * 1024 / millisecond sampler.

  • 48KHz => ~ 21.3ms
  • 44.1KHz => ~ 23.2ms

By skipping samples from the start, you can easily shorten the audio track. Remove as many as you need. You cannot compare audio and video with just that, but human perception is more reasonable for early audio than for late audio.

Remember: if someone is only 10 meters away, the delay between audio and video is> 30 ms. The brain is used for this!

AACTrackImpl aacTrackOriginal = new AACTrackImpl (new FileDataSourceImpl ("audio.aac")); // removes the first sample and shortens the AAC by ~ 22 ms CroppedTrack aacTrackShort = new CroppedTrack (aacTrackOriginal, 1, aacTrack.Samples) ;

Add records with the same encoding settings

It is important to emphasize that you cannot add two tracks with:

  • Different permissions
  • Different frame rates

That you can not do?

Create JPEG files from a movie. No - this is not a decoder. The MP4 parser does not know how to do this. Create a movie from JPEG

+1
source

All Articles