com.drew.metadata.mp4.boxes.MovieHeaderBox Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metadata-extractor Show documentation
Show all versions of metadata-extractor Show documentation
This is a fork of com.drewnoakes' metadata-extractor that relocates com.adobe.internal to com.adobe.
Java library for extracting EXIF, IPTC, XMP, ICC and other metadata from image and video files.
/*
* Copyright 2002-2019 Drew Noakes and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* More information about this project is available at:
*
* https://drewnoakes.com/code/exif/
* https://github.com/drewnoakes/metadata-extractor
*/
package com.drew.metadata.mp4.boxes;
import com.drew.lang.DateUtil;
import com.drew.lang.Rational;
import com.drew.lang.SequentialReader;
import com.drew.metadata.mp4.Mp4Directory;
import java.io.IOException;
/**
* ISO/IED 14496-12:2015 pg.23
*/
public class MovieHeaderBox extends FullBox
{
protected long creationTime;
protected long modificationTime;
protected long timescale;
protected long duration;
protected int rate;
protected int volume;
protected int[] matrix;
protected long nextTrackID;
public MovieHeaderBox(SequentialReader reader, Box box) throws IOException
{
super(reader, box);
if (version == 1) {
creationTime = reader.getInt64();
modificationTime = reader.getInt64();
timescale = reader.getUInt32();
duration = reader.getInt64();
} else {
creationTime = reader.getUInt32();
modificationTime = reader.getUInt32();
timescale = reader.getUInt32();
duration = reader.getUInt32();
}
rate = reader.getInt32();
volume = reader.getInt16();
reader.skip(2); // Reserved
reader.skip(8); // Reserved
matrix = new int[]{reader.getInt32(),
reader.getInt32(),
reader.getInt32(),
reader.getInt32(),
reader.getInt32(),
reader.getInt32(),
reader.getInt32(),
reader.getInt32(),
reader.getInt32()
};
reader.skip(24); // Pre-defined
nextTrackID = reader.getUInt32();
}
public void addMetadata(Mp4Directory directory)
{
// Get creation/modification times
directory.setDate(Mp4Directory.TAG_CREATION_TIME, DateUtil.get1Jan1904EpochDate(creationTime));
directory.setDate(Mp4Directory.TAG_MODIFICATION_TIME, DateUtil.get1Jan1904EpochDate(modificationTime));
// Get duration and time scale
directory.setLong(Mp4Directory.TAG_DURATION, duration);
directory.setLong(Mp4Directory.TAG_TIME_SCALE, timescale);
directory.setRational(Mp4Directory.TAG_DURATION_SECONDS, new Rational(duration, timescale));
directory.setIntArray(Mp4Directory.TAG_TRANSFORMATION_MATRIX, matrix);
// Calculate preferred rate fixed point
double preferredRateInteger = (rate & 0xFFFF0000) >> 16;
double preferredRateFraction = (rate & 0x0000FFFF) / Math.pow(2, 4);
directory.setDouble(Mp4Directory.TAG_PREFERRED_RATE, preferredRateInteger + preferredRateFraction);
// Calculate preferred volume fixed point
double preferredVolumeInteger = (volume & 0xFF00) >> 8;
double preferredVolumeFraction = (volume & 0x00FF) / Math.pow(2, 2);
directory.setDouble(Mp4Directory.TAG_PREFERRED_VOLUME, preferredVolumeInteger + preferredVolumeFraction);
directory.setLong(Mp4Directory.TAG_NEXT_TRACK_ID, nextTrackID);
}
}