com.coremedia.iso.boxes.MovieBox Java Examples

The following examples show how to use com.coremedia.iso.boxes.MovieBox. 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: 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));
}