com.coremedia.iso.IsoFile Java Examples
The following examples show how to use
com.coremedia.iso.IsoFile.
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 TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #2
Source File: MP4Builder.java From VideoCompressor with Apache License 2.0 | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #3
Source File: MP4Builder.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #4
Source File: MP4Builder.java From react-native-video-helper with MIT License | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #5
Source File: MP4Builder.java From VideoCompressor with Apache License 2.0 | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #6
Source File: MP4Builder.java From talk-android with MIT License | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #7
Source File: MP4Builder.java From SiliCompressor with Apache License 2.0 | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #8
Source File: ProcessVideoUtils.java From patrol-android with GNU General Public License v3.0 | 6 votes |
/** * Shortens/Crops a track */ public static String trimToLast20sec(File src) throws IOException { IsoFile isoFile = new IsoFile(src.getAbsolutePath()); double duration = (double) isoFile.getMovieBox().getMovieHeaderBox().getDuration() / isoFile.getMovieBox().getMovieHeaderBox().getTimescale(); Log.d(TAG, "trimToLast20sec: " + duration); if (duration > 20) { double startTime = duration - 20; File dst = new File(FilesUtils.getOutputExternalMediaFile(FilesUtils.MEDIA_TYPE_VIDEO).getAbsolutePath()); Log.d(TAG, "dst: " + dst.getAbsolutePath()); startTrim(src, dst, startTime, duration); FilesUtils.removeFile(src.getAbsolutePath()); return dst.getAbsolutePath(); } return null; }
Example #9
Source File: MP4Builder.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #10
Source File: MP4Builder.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #11
Source File: MP4Builder.java From Telegram with GNU General Public License v2.0 | 6 votes |
public void getBox(WritableByteChannel writableByteChannel) throws IOException { ByteBuffer bb = ByteBuffer.allocate(16); long size = getSize(); if (isSmallBox(size)) { IsoTypeWriter.writeUInt32(bb, size); } else { IsoTypeWriter.writeUInt32(bb, 1); } bb.put(IsoFile.fourCCtoBytes("mdat")); if (isSmallBox(size)) { bb.put(new byte[8]); } else { IsoTypeWriter.writeUInt64(bb, size); } bb.rewind(); writableByteChannel.write(bb); }
Example #12
Source File: DashMediaExtractor.java From MediaPlayer-Extended with Apache License 2.0 | 4 votes |
/** * 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; }
Example #13
Source File: MediaHelper.java From AndroidVideoSamples with Apache License 2.0 | 4 votes |
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; }