• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TrackBox类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.coremedia.iso.boxes.TrackBox的典型用法代码示例。如果您正苦于以下问题:Java TrackBox类的具体用法?Java TrackBox怎么用?Java TrackBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TrackBox类属于com.coremedia.iso.boxes包,在下文中一共展示了TrackBox类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: muxerFileDebug

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
public static void muxerFileDebug(){
	try 
	{
		File input = new File(SDCardUtils.getExternalSdCardPath() + "/a.h264");
		File output = new File(SDCardUtils.getExternalSdCardPath() + "/b.mp4");

		H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(input), "eng", UriParser.videoQuality.framerate, 1);
		Movie m = new Movie();
		m.addTrack(h264Track);
		m.setMatrix(Matrix.ROTATE_90);
		Container out = new DefaultMp4Builder().build(m);
		MovieHeaderBox mvhd = Path.getPath(out, "moov/mvhd");
   		mvhd.setMatrix(Matrix.ROTATE_90);
		TrackBox trackBox  = Path.getPath(out, "moov/trak");
		TrackHeaderBox tkhd = trackBox.getTrackHeaderBox();
		tkhd.setMatrix(Matrix.ROTATE_90);
		FileChannel fc = new FileOutputStream(output.getAbsolutePath()).getChannel();
		out.writeContainer(fc);
		fc.close();

	} 
	catch (IOException e) {
	    Log.e("test", "some exception", e);
	}	
}
 
开发者ID:xunboo,项目名称:JJCamera,代码行数:26,代码来源:MP4Muxer.java


示例2: build

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
public static Movie build(ReadableByteChannel channel) throws IOException {
    IsoFile isoFile = new IsoFile(channel);
    Movie m = new Movie();
    List<TrackBox> trackBoxes = isoFile.getMovieBox().getBoxes(TrackBox.class);
    for (TrackBox trackBox : trackBoxes) {
        m.addTrack(new Mp4TrackImpl(trackBox));
    }
    return m;
}
 
开发者ID:begeekmyfriend,项目名称:mp4parser_android,代码行数:10,代码来源:MovieCreator.java


示例3: createTrak

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
protected Box createTrak(Track track, Movie movie) {
    LOG.fine("Creating Track " + track);
    TrackBox trackBox = new TrackBox();
    trackBox.addBox(createTkhd(movie, track));
    trackBox.addBox(createMdia(track, movie));
    return trackBox;
}
 
开发者ID:lisnstatic,项目名称:live_master,代码行数:8,代码来源:FragmentedMp4Builder.java


示例4: handleSegment

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
/**
 * Handles a segment by merging it with the init segment into a temporary file.
 */
private void handleSegment(byte[] mediaSegment, CachedSegment cachedSegment) throws IOException {
    File segmentFile = getTempFile(mContext, "seg" + cachedSegment.representation.id + "-" + cachedSegment.segment.range + "");
    long segmentPTSOffsetUs = 0;

    if(mMp4Mode) {
        /* The MP4 iso format needs special treatment because the Android MediaExtractor/MediaCodec
         * does not support the fragmented MP4 container format. Each segment therefore needs
         * to be joined with the init fragment and converted to a "conventional" unfragmented MP4
         * container file. */
        IsoFile baseIsoFile = new IsoFile(new MemoryDataSourceImpl(mInitSegments.get(cachedSegment.representation).asByteBuffer()));
        IsoFile fragment = new IsoFile(new MemoryDataSourceImpl(mediaSegment));

        /* The PTS in a converted MP4 always start at 0, so we read the offset from the segment
         * index box and work with it at the necessary places to adjust the local PTS to global
         * PTS concerning the whole stream. */
        List<SegmentIndexBox> segmentIndexBoxes = fragment.getBoxes(SegmentIndexBox.class);
        if(segmentIndexBoxes.size() > 0) {
            SegmentIndexBox sidx = segmentIndexBoxes.get(0);
            segmentPTSOffsetUs = (long) ((double) sidx.getEarliestPresentationTime() / sidx.getTimeScale() * 1000000);
        }
        /* If there is no segment index box to read the PTS from, we calculate the PTS offset
         * from the info given in the MPD. */
        else {
            segmentPTSOffsetUs = cachedSegment.number * cachedSegment.representation.segmentDurationUs;
        }

        Movie mp4Segment = new Movie();
        for(TrackBox trackBox : baseIsoFile.getMovieBox().getBoxes(TrackBox.class)) {
            mp4Segment.addTrack(new Mp4TrackImpl(null, trackBox, fragment));
        }
        Container mp4SegmentContainer = new DefaultMp4Builder().build(mp4Segment); // always create new instance to avoid memory leaks!
        FileOutputStream fos = new FileOutputStream(segmentFile, false);
        mp4SegmentContainer.writeContainer(fos.getChannel());
        fos.close();
    } else {
        // merge init and media segments into file
        BufferedSink segmentFileSink = Okio.buffer(Okio.sink(segmentFile));
        segmentFileSink.write(mInitSegments.get(cachedSegment.representation));
        segmentFileSink.write(mediaSegment);
        segmentFileSink.close();
    }

    cachedSegment.file = segmentFile;
    cachedSegment.ptsOffsetUs = segmentPTSOffsetUs;
}
 
开发者ID:protyposis,项目名称:MediaPlayer-Extended,代码行数:49,代码来源:DashMediaExtractor.java


示例5: createTrackBox

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
protected TrackBox createTrackBox(Track track, Mp4Movie movie) {
    TrackBox trackBox = new TrackBox();
    TrackHeaderBox tkhd = new TrackHeaderBox();

    tkhd.setEnabled(true);
    tkhd.setInMovie(true);
    tkhd.setInPreview(true);
    if (track.isAudio()) {
        tkhd.setMatrix(Matrix.ROTATE_0);
    } else {
        tkhd.setMatrix(movie.getMatrix());
    }
    tkhd.setAlternateGroup(0);
    tkhd.setCreationTime(track.getCreationTime());
    tkhd.setDuration(track.getDuration() * getTimescale(movie) / track.getTimeScale());
    tkhd.setHeight(track.getHeight());
    tkhd.setWidth(track.getWidth());
    tkhd.setLayer(0);
    tkhd.setModificationTime(new Date());
    tkhd.setTrackId(track.getTrackId() + 1);
    tkhd.setVolume(track.getVolume());

    trackBox.addBox(tkhd);

    MediaBox mdia = new MediaBox();
    trackBox.addBox(mdia);
    MediaHeaderBox mdhd = new MediaHeaderBox();
    mdhd.setCreationTime(track.getCreationTime());
    mdhd.setDuration(track.getDuration());
    mdhd.setTimescale(track.getTimeScale());
    mdhd.setLanguage("eng");
    mdia.addBox(mdhd);
    HandlerBox hdlr = new HandlerBox();
    hdlr.setName(track.isAudio() ? "SoundHandle" : "VideoHandle");
    hdlr.setHandlerType(track.getHandler());

    mdia.addBox(hdlr);

    MediaInformationBox minf = new MediaInformationBox();
    minf.addBox(track.getMediaHeaderBox());

    DataInformationBox dinf = new DataInformationBox();
    DataReferenceBox dref = new DataReferenceBox();
    dinf.addBox(dref);
    DataEntryUrlBox url = new DataEntryUrlBox();
    url.setFlags(1);
    dref.addBox(url);
    minf.addBox(dinf);

    Box stbl = createStbl(track);
    minf.addBox(stbl);
    mdia.addBox(minf);

    return trackBox;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:56,代码来源:MP4Builder.java


示例6: SampleList

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
public SampleList(TrackBox trackBox) {
    initIsoFile(trackBox.getIsoFile()); // where are we?

    // first we get all sample from the 'normal' MP4 part.
    // if there are none - no problem.
    SampleSizeBox sampleSizeBox = trackBox.getSampleTableBox().getSampleSizeBox();
    ChunkOffsetBox chunkOffsetBox = trackBox.getSampleTableBox().getChunkOffsetBox();
    SampleToChunkBox sampleToChunkBox = trackBox.getSampleTableBox().getSampleToChunkBox();


    final long[] chunkOffsets = chunkOffsetBox != null ? chunkOffsetBox.getChunkOffsets() : new long[0];
    if (sampleToChunkBox != null && sampleToChunkBox.getEntries().size() > 0 &&
            chunkOffsets.length > 0 && sampleSizeBox != null && sampleSizeBox.getSampleCount() > 0) {
        long[] numberOfSamplesInChunk = sampleToChunkBox.blowup(chunkOffsets.length);

        int sampleIndex = 0;

        if (sampleSizeBox.getSampleSize() > 0) {
            sizes = new long[l2i(sampleSizeBox.getSampleCount())];
            Arrays.fill(sizes, sampleSizeBox.getSampleSize());
        } else {
            sizes = sampleSizeBox.getSampleSizes();
        }
        offsets = new long[sizes.length];

            for (int i = 0; i < numberOfSamplesInChunk.length; i++) {
                long thisChunksNumberOfSamples = numberOfSamplesInChunk[i];
            long sampleOffset = chunkOffsets[i];
                for (int j = 0; j < thisChunksNumberOfSamples; j++) {
                long sampleSize = sizes[sampleIndex];
                offsets[sampleIndex] = sampleOffset;
                    sampleOffset += sampleSize;
                    sampleIndex++;
                }
            }

        }

    // Next we add all samples from the fragments
    // in most cases - I've never seen it different it's either normal or fragmented.        
    List<MovieExtendsBox> movieExtendsBoxes = trackBox.getParent().getBoxes(MovieExtendsBox.class);

    if (movieExtendsBoxes.size() > 0) {
        Map<Long, Long> offsets2Sizes = new HashMap<Long, Long>();
        List<TrackExtendsBox> trackExtendsBoxes = movieExtendsBoxes.get(0).getBoxes(TrackExtendsBox.class);
        for (TrackExtendsBox trackExtendsBox : trackExtendsBoxes) {
            if (trackExtendsBox.getTrackId() == trackBox.getTrackHeaderBox().getTrackId()) {
                for (MovieFragmentBox movieFragmentBox : trackBox.getIsoFile().getBoxes(MovieFragmentBox.class)) {
                    offsets2Sizes.putAll(getOffsets(movieFragmentBox, trackBox.getTrackHeaderBox().getTrackId(), trackExtendsBox));
                }
            }
        }
        
        if (sizes == null || offsets == null) {
            sizes = new long[0];
            offsets = new long[0];
        }
        
        splitToArrays(offsets2Sizes);
    }
    
    // We have now a map from all sample offsets to their sizes
}
 
开发者ID:lisnstatic,项目名称:live_master,代码行数:64,代码来源:SampleList.java


示例7: createTrackBox

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
private TrackBox createTrackBox(Track track, Mp4Movie movie) {
    TrackBox trackBox = new TrackBox();
    TrackHeaderBox tkhd = new TrackHeaderBox();

    tkhd.setEnabled(true);
    tkhd.setInMovie(true);
    tkhd.setInPreview(true);
    if (track.isAudio()) {
        tkhd.setMatrix(Matrix.ROTATE_0);
    } else {
        tkhd.setMatrix(movie.getMatrix());
    }
    tkhd.setAlternateGroup(0);
    tkhd.setCreationTime(track.getCreationTime());
    tkhd.setModificationTime(track.getCreationTime());
    tkhd.setDuration(track.getDuration() * getTimescale(movie) / track.getTimeScale());
    tkhd.setHeight(track.getHeight());
    tkhd.setWidth(track.getWidth());
    tkhd.setLayer(0);
    tkhd.setModificationTime(new Date());
    tkhd.setTrackId(track.getTrackId() + 1);
    tkhd.setVolume(track.getVolume());

    trackBox.addBox(tkhd);

    MediaBox mdia = new MediaBox();
    trackBox.addBox(mdia);
    MediaHeaderBox mdhd = new MediaHeaderBox();
    mdhd.setCreationTime(track.getCreationTime());
    mdhd.setModificationTime(track.getCreationTime());
    mdhd.setDuration(track.getDuration());
    mdhd.setTimescale(track.getTimeScale());
    mdhd.setLanguage("eng");
    mdia.addBox(mdhd);
    HandlerBox hdlr = new HandlerBox();
    hdlr.setName(track.isAudio() ? "SoundHandle" : "VideoHandle");
    hdlr.setHandlerType(track.getHandler());

    mdia.addBox(hdlr);

    MediaInformationBox minf = new MediaInformationBox();
    minf.addBox(track.getMediaHeaderBox());

    DataInformationBox dinf = new DataInformationBox();
    DataReferenceBox dref = new DataReferenceBox();
    dinf.addBox(dref);
    DataEntryUrlBox url = new DataEntryUrlBox();
    url.setFlags(1);
    dref.addBox(url);
    minf.addBox(dinf);

    Box stbl = createStbl(track);
    minf.addBox(stbl);
    mdia.addBox(minf);

    return trackBox;
}
 
开发者ID:lisnstatic,项目名称:live_master,代码行数:58,代码来源:SrsMp4Muxer.java


示例8: handleSegment

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
/**
 * Handles a segment by merging it with the init segment into a temporary file.
 */
private void handleSegment(byte[] mediaSegment, CachedSegment cachedSegment) throws IOException {
    File segmentFile = getTempFile(mContext, "seg" + cachedSegment.representation.id + "-" + cachedSegment.segment.range + "");
    long segmentPTSOffsetUs = 0;

    if(mMp4Mode) {
        /* The MP4 iso format needs special treatment because the Android MediaExtractor/MediaCodec
         * does not support the fragmented MP4 container format. Each segment therefore needs
         * to be joined with the init fragment and converted to a "conventional" unfragmented MP4
         * container file. */
        IsoFile baseIsoFile = new IsoFile(new MemoryDataSourceImpl(mInitSegments.get(cachedSegment.representation).toByteArray())); // TODO do not go ByteString -> byte[] -> ByteBuffer, find more efficient way (custom mp4parser DataSource maybe?)
        IsoFile fragment = new IsoFile(new MemoryDataSourceImpl(mediaSegment));

        /* The PTS in a converted MP4 always start at 0, so we read the offset from the segment
         * index box and work with it at the necessary places to adjust the local PTS to global
         * PTS concerning the whole stream. */
        List<SegmentIndexBox> segmentIndexBoxes = fragment.getBoxes(SegmentIndexBox.class);
        if(segmentIndexBoxes.size() > 0) {
            SegmentIndexBox sidx = segmentIndexBoxes.get(0);
            segmentPTSOffsetUs = (long) ((double) sidx.getEarliestPresentationTime() / sidx.getTimeScale() * 1000000);
        }
        /* If there is no segment index box to read the PTS from, we calculate the PTS offset
         * from the info given in the MPD. */
        else {
            segmentPTSOffsetUs = cachedSegment.number * cachedSegment.representation.segmentDurationUs;
        }

        Movie mp4Segment = new Movie();
        for(TrackBox trackBox : baseIsoFile.getMovieBox().getBoxes(TrackBox.class)) {
            mp4Segment.addTrack(new Mp4TrackImpl(null, trackBox, fragment));
        }
        Container mp4SegmentContainer = mMp4Builder.build(mp4Segment);
        FileOutputStream fos = new FileOutputStream(segmentFile, false);
        mp4SegmentContainer.writeContainer(fos.getChannel());
        fos.close();
    } else {
        // merge init and media segments into file
        BufferedSink segmentFileSink = Okio.buffer(Okio.sink(segmentFile));
        segmentFileSink.write(mInitSegments.get(cachedSegment.representation));
        segmentFileSink.write(mediaSegment);
        segmentFileSink.close();
    }

    cachedSegment.file = segmentFile;
    cachedSegment.ptsOffsetUs = segmentPTSOffsetUs;
}
 
开发者ID:g-marsh,项目名称:MediaPlayer-GregMods,代码行数:49,代码来源:DashMediaExtractor.java


示例9: RotateVideo

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
public static Uri RotateVideo( Uri uri, int rotation ) {

      Uri rotatedVideoUri = null;

      try {
         IsoFile file = new IsoFile( uri.toString() );

         List<Box> boxes = file.getMovieBox().getBoxes();

         for ( Box box : boxes ) {
            if ( box instanceof TrackBox ) {
               TrackBox trackBox = (TrackBox) box;
               
               HandlerBox handlerBox = trackBox.getMediaBox().getHandlerBox();
               if ( handlerBox.getHandlerType().toLowerCase( Locale.US ).equals( "vide" ) ) {
                  TrackHeaderBox trackHeaderBox = trackBox.getTrackHeaderBox();
                  trackHeaderBox.setMatrix( GetMatrixFromRotation( rotation ) );
               }
            }
         }

         String pathWithoutExtension = uri.toString().replace( ".mp4", "" );

         String rotatedFileName = String.format( Locale.US, "%s_rotated_to_%d.mp4", pathWithoutExtension, rotation );

         FileOutputStream videoFileOutputStream = new FileOutputStream( rotatedFileName );
         file.getBox( videoFileOutputStream.getChannel() );

         file.close();
         videoFileOutputStream.close();

         rotatedVideoUri = Uri.parse( rotatedFileName );

      } catch ( IOException e ) {
         e.printStackTrace();

         return null;
      }

      return rotatedVideoUri;
   }
 
开发者ID:hoolrory,项目名称:AndroidVideoSamples,代码行数:42,代码来源:MediaHelper.java


示例10: loadIsoFile

import com.coremedia.iso.boxes.TrackBox; //导入依赖的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);
}
 
开发者ID:ivarptr,项目名称:clobaframe,代码行数:72,代码来源:VideoLoader.java


示例11: LoadSpecificBox

import com.coremedia.iso.boxes.TrackBox; //导入依赖的package包/类
private void LoadSpecificBox( TrackBox box ) {

   }
 
开发者ID:hoolrory,项目名称:VideoInfoViewer,代码行数:4,代码来源:BoxInfoView.java



注:本文中的com.coremedia.iso.boxes.TrackBox类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BasicTextUI类代码示例发布时间:2022-05-21
下一篇:
Java FacesServlet类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap