com.coremedia.iso.boxes.Box Java Examples

The following examples show how to use com.coremedia.iso.boxes.Box. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MP4Builder.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
public void finishMovie(boolean error) throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();

    fc.close();
    fos.close();
}
 
Example #2
Source File: MP4Builder.java    From VideoCompressor with Apache License 2.0 6 votes vote down vote up
public void finishMovie(boolean error) throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();

    fc.close();
    fos.close();
}
 
Example #3
Source File: MP4Builder.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void finishMovie() throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();
    fos.getFD().sync();

    fc.close();
    fos.close();
}
 
Example #4
Source File: MP4Builder.java    From SiliCompressor with Apache License 2.0 6 votes vote down vote up
public void finishMovie(boolean error) throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();

    fc.close();
    fos.close();
}
 
Example #5
Source File: MP4Builder.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void finishMovie() throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();
    fos.getFD().sync();

    fc.close();
    fos.close();
}
 
Example #6
Source File: MP4Builder.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void finishMovie() throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();
    fos.getFD().sync();

    fc.close();
    fos.close();
}
 
Example #7
Source File: DownloadFinishedReceiver.java    From YouTube-In-Background with MIT License 6 votes vote down vote up
private void correctChunkOffsets(Container container, long correction)
{
    List<Box> chunkOffsetBoxes = Path.getPaths(container, "/moov[0]/trak/mdia[0]/minf[0]/stbl[0]/stco[0]");
    for (Box chunkOffsetBox : chunkOffsetBoxes) {

        LinkedList<Box> stblChildren = new LinkedList<>(chunkOffsetBox.getParent().getBoxes());
        stblChildren.remove(chunkOffsetBox);

        long[] cOffsets = ((ChunkOffsetBox) chunkOffsetBox).getChunkOffsets();
        for (int i = 0; i < cOffsets.length; i++) {
            cOffsets[i] += correction;
        }

        StaticChunkOffsetBox cob = new StaticChunkOffsetBox();
        cob.setChunkOffsets(cOffsets);
        stblChildren.add(cob);
        chunkOffsetBox.getParent().setBoxes(stblChildren);
    }
}
 
Example #8
Source File: MP4Builder.java    From react-native-video-helper with MIT License 6 votes vote down vote up
public void finishMovie(boolean error) throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();

    fc.close();
    fos.close();
}
 
Example #9
Source File: MP4Builder.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void finishMovie() throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();
    fos.getFD().sync();

    fc.close();
    fos.close();
}
 
Example #10
Source File: MP4Builder.java    From VideoCompressor with Apache License 2.0 6 votes vote down vote up
public void finishMovie(boolean error) throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();

    fc.close();
    fos.close();
}
 
Example #11
Source File: MP4Builder.java    From talk-android with MIT License 6 votes vote down vote up
public void finishMovie(boolean error) throws Exception {
    if (mdat.getContentSize() != 0) {
        flushCurrentMdat();
    }

    for (Track track : currentMp4Movie.getTracks()) {
        List<Sample> samples = track.getSamples();
        long[] sizes = new long[samples.size()];
        for (int i = 0; i < sizes.length; i++) {
            sizes[i] = samples.get(i).getSize();
        }
        track2SampleSizes.put(track, sizes);
    }

    Box moov = createMovieBox(currentMp4Movie);
    moov.getBox(fc);
    fos.flush();

    fc.close();
    fos.close();
}
 
Example #12
Source File: MP4Builder.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #13
Source File: MP4Builder.java    From SiliCompressor with Apache License 2.0 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #14
Source File: MP4Builder.java    From talk-android with MIT License 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #15
Source File: MP4Builder.java    From VideoCompressor with Apache License 2.0 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #16
Source File: MP4Builder.java    From react-native-video-helper with MIT License 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #17
Source File: MP4Builder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createCtts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #18
Source File: MP4Builder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createCtts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #19
Source File: MP4Builder.java    From VideoCompressor with Apache License 2.0 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #20
Source File: MP4Builder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createCtts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #21
Source File: MP4Builder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
protected Box createStbl(Track track) {
    SampleTableBox stbl = new SampleTableBox();

    createStsd(track, stbl);
    createStts(track, stbl);
    createCtts(track, stbl);
    createStss(track, stbl);
    createStsc(track, stbl);
    createStsz(track, stbl);
    createStco(track, stbl);

    return stbl;
}
 
Example #22
Source File: MP4Builder.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example #23
Source File: MP4Builder.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example #24
Source File: MediaHelper.java    From AndroidVideoSamples with Apache License 2.0 4 votes vote down vote up
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;
   }
 
Example #25
Source File: MP4Builder.java    From talk-android with MIT License 4 votes vote down vote up
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;
}
 
Example #26
Source File: FakeCamOutput.java    From sensorhub with Mozilla Public License 2.0 4 votes vote down vote up
private void sendMeasurement()
{
    // read next video frame
    try
    {
        videoFrameBuffer.reset();
        WritableByteChannel byteChannel = Channels.newChannel(videoFrameBuffer);
        
        // init or loop
        if (mp4Boxes == null || !mp4Boxes.hasNext())
            mp4Boxes = mp4File.getBoxes().iterator();
        
        // copy all box until actual frame data is found
        while (mp4Boxes.hasNext())
        {
            Box currentBox = mp4Boxes.next();
                            
            if (currentBox instanceof MovieBox)
            {
                log.trace(((MovieBox) currentBox).getMovieHeaderBox().toString());
            }
            
            if (currentBox instanceof MovieFragmentBox)
            {
                // always increment seq number
                sampleCounter++;
                ((MovieFragmentBox) currentBox).getBoxes(MovieFragmentHeaderBox.class).get(0).setSequenceNumber(sampleCounter);;
                
                // need to rewrite base offset so it's not relative to begining of file
                //((MovieFragmentBox) currentBox).getTrackFragmentHeaderBoxes().get(0).setDefaultBaseIsMoof(true);
                ((MovieFragmentBox) currentBox).getTrackFragmentHeaderBoxes().get(0).setBaseDataOffset(-1L);
                ((MovieFragmentBox) currentBox).getTrackFragmentHeaderBoxes().get(0).setDefaultSampleDuration(4000);
                ((MovieFragmentBox) currentBox).getTrackRunBoxes().get(0).setDataOffset(224-8);
                
                log.trace(((MovieFragmentBox) currentBox).getBoxes(MovieFragmentHeaderBox.class).get(0).toString());
                log.trace(((MovieFragmentBox) currentBox).getTrackFragmentHeaderBoxes().get(0).toString());
                log.trace(((MovieFragmentBox) currentBox).getTrackRunBoxes().get(0).toString());
                //for (Entry sample: ((MovieFragmentBox) currentBox).getTrackRunBoxes().get(0).getEntries())
                //    System.out.println(sample);                    
            }
            
            if (currentBox.getType().equals("moof"))
            {
                // TODO add time tag box (tfdt?)
                log.trace("Copying box " + currentBox.getType());
                currentBox.getBox(byteChannel);
            }
            
            else if (currentBox.getType().equals("mdat"))
            {
                log.trace("Copying box " + currentBox.getType());
                currentBox.getBox(byteChannel);
                break;
            }
            
            else if (currentBox.getType().equals("mfra"))
            {
                mp4Boxes = mp4File.getBoxes().iterator();
            }
        }
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
            
    // build and publish datablock
    DataBlockCompressed dataBlock = new DataBlockCompressed();
    dataBlock.setUnderlyingObject(videoFrameBuffer.toByteArray());
    
    // update latest record and send event
    latestRecord = dataBlock;
    latestRecordTime = System.currentTimeMillis();
    eventHandler.publishEvent(new SensorDataEvent(latestRecordTime, FakeCamOutput.this, dataBlock));
}
 
Example #27
Source File: MP4Builder.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example #28
Source File: MP4Builder.java    From SiliCompressor with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #29
Source File: MP4Builder.java    From VideoCompressor with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #30
Source File: MP4Builder.java    From react-native-video-helper with MIT License 4 votes vote down vote up
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;
}