本文整理汇总了Java中com.coremedia.iso.boxes.MovieHeaderBox.getDuration方法的典型用法代码示例。如果您正苦于以下问题:Java MovieHeaderBox.getDuration方法的具体用法?Java MovieHeaderBox.getDuration怎么用?Java MovieHeaderBox.getDuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.coremedia.iso.boxes.MovieHeaderBox
的用法示例。
在下文中一共展示了MovieHeaderBox.getDuration方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadIsoFile
import com.coremedia.iso.boxes.MovieHeaderBox; //导入方法依赖的package包/类
private Media loadIsoFile(IsoFile isoFile, FileBaseResourceInfo fileBaseResourceInfo) {
// Grab the file type box
FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class);
if (fileType == null) {
return null;
}
// String brand = fileType.getMajorBrand();
// String type = null;
//
// for(String t : mp4_audio_brands) {
// if (brand.equals(t)){
// type = t;
// break;
// }
// }
//
// for(String t : mp4_video_brands) {
// if (brand.equals(t)){
// type = t;
// break;
// }
// }
//
// if (type == null){
// return null;
// }
// Audio.Format format = null;
// String encoding = null;
// if ("mp3".equals(audioHeader.getEncodingType())){
// format = Audio.Format.mp3;
// encoding = "mp3";
// }else if ("AAC".equals(audioHeader.getEncodingType())){
// format = Audio.Format.m4a;
// encoding = "aac";
// }
//
// mp4 file format, see:
// http://1.richitec.sinaapp.com/?p=46
// Get the main MOOV box
MovieBox moov = getOrNull(isoFile, MovieBox.class);
if (moov == null) {
// Bail out
return null;
}
double duration = 0;
// Pull out some information from the header box
MovieHeaderBox mHeader = getOrNull(moov, MovieHeaderBox.class);
if (mHeader == null) {
return null;
}
// Get the duration. Seconds
duration = (double)mHeader.getDuration() / mHeader.getTimescale();
// see: http://en.wikipedia.org/wiki/Bit_rate
int bitrate = (int)(fileBaseResourceInfo.getContentLength() * 8 / duration / 1000);
Audio audio = new DefaultAudio(
fileBaseResourceInfo,
Audio.Format.m4a, "aac",
duration,
bitrate,
Audio.BitrateMode.variable);
M4aMetaDataParser metaDataParser = new M4aMetaDataParser();
audio.setMetaData(metaDataParser.parse(moov));
return audio;
}
示例2: loadIsoFile
import com.coremedia.iso.boxes.MovieHeaderBox; //导入方法依赖的package包/类
private Media loadIsoFile(IsoFile isoFile, FileBaseResourceInfo fileBaseResourceInfo) {
// Grab the file type box
FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class);
if (fileType == null) {
return null;
}
// Get the main MOOV box
MovieBox moov = getOrNull(isoFile, MovieBox.class);
if (moov == null) {
// Bail out
return null;
}
double duration = 0;
// Pull out some information from the header box
MovieHeaderBox mHeader = getOrNull(moov, MovieHeaderBox.class);
if (mHeader == null) {
return null;
}
// Get the duration. Seconds
duration = (double)mHeader.getDuration() / mHeader.getTimescale();
if (duration == 0){
duration = 1;
}
// Get some more information from the track header
List<TrackBox> tb = moov.getBoxes(TrackBox.class);
if (tb.isEmpty()) {
return null;
}
// Get the video with and height
int width = 0;
int height = 0;
for(int idx=0; idx<tb.size(); idx++){
TrackBox track = tb.get(idx);
TrackHeaderBox header = track.getTrackHeaderBox();
int w = (int)header.getWidth();
int h = (int)header.getHeight();
if (w==0 && h==0){
// skip the none-video track
continue;
}
// Get the video with and height
width = w;
height = h;
break;
}
if (width == 0 && height == 0) {
// no video track found.
return null;
}
Video.Format format = (
MIME_TYPE_VIDEO_MP4.equals(fileBaseResourceInfo.getMimeType())?
Video.Format.mp4:
Video.Format.mov);
return new DefaultVideo(
fileBaseResourceInfo, format,
width, height, duration);
}