/** * Shortcut to get the MovieBox since it is often needed and present in * nearly all ISO 14496 files (at least if they are derived from MP4 ). * * @return the MovieBox or <code>null</code> */ public MovieBox getMovieBox() { for (Box box : getBoxes()) { if (box instanceof MovieBox) { return (MovieBox) box; } } return null; }
public static TYPE getType(IsoFile isoFile) { List<HandlerBox> handlerBoxes = isoFile.getBoxes(HandlerBox.class, true); for (HandlerBox handlerBox : handlerBoxes) { if ("vide".equals(handlerBox.getHandlerType())) { return TYPE.VIDEO; } else if ("soun".equals(handlerBox.getHandlerType())) { return TYPE.AUDIO; } else { System.err.println("unknown"); } } return TYPE.AUDIO; }
public static boolean needsOffsetCorrection(IsoFile isoFile) { if (Path.getPaths(isoFile, "mdat").size() > 1) { throw new RuntimeException("There might be the weird case that a file has two mdats. One before" + " moov and one after moov. That would need special handling therefore I just throw an " + "exception here. "); } if (Path.getPaths(isoFile, "moof").size() > 0) { throw new RuntimeException("Fragmented MP4 files need correction, too. (But I would need to look where)"); } for (Box box : isoFile.getBoxes()) { if ("mdat".equals(box.getType())) { return false; } if ("moov".equals(box.getType())) { return true; } } throw new RuntimeException("Hmmm - shouldn't happen"); }
private boolean needsOffsetCorrection(IsoFile isoFile) { if (Path.getPath(isoFile, "moov[0]/mvex[0]") != null) { // Fragmented files don't need a correction return false; } else { // no correction needed if mdat is before moov as insert into moov want change the offsets of mdat for (Box box : isoFile.getBoxes()) { if ("moov".equals(box.getType())) { return true; } if ("mdat".equals(box.getType())) { return false; } } throw new RuntimeException("I need moov or mdat. Otherwise all this doesn't make sense"); } }
public static void main(String[] args) throws IOException { String f = Avc1ToAvc3Example.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/1365070268951.mp4"; Movie m = MovieCreator.build(new FileInputStream(f).getChannel(), new FileRandomAccessSourceImpl(new RandomAccessFile(f, "r")), "inmem"); Movie m2 = new Movie(); for (Track track : m.getTracks()) { if (track.getSampleEntries().get(0).getType().equals("avc1")) { m2.addTrack(new Avc1ToAvc3TrackImpl(track)); } else { m2.addTrack(track); } } new FragmentedMp4Builder().build(m2).writeContainer(new FileOutputStream("output.mp4").getChannel()); IsoFile i = new IsoFile("output.mp4"); for (Box box : i.getBoxes()) { System.err.println(box + "@-nooffsets"); } } }
public Avc1ToAvc3TrackImpl(Track parent) throws IOException { super(parent); for (SampleEntry sampleEntry : parent.getSampleEntries()) { if (sampleEntry.getType().equals("avc1")) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { // This creates a copy cause I can't change the original instance sampleEntry.getBox(Channels.newChannel(baos)); VisualSampleEntry avc3SampleEntry = (VisualSampleEntry) new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray()))).getBoxes().get(0); avc3SampleEntry.setType("avc3"); avc1toavc3.put(sampleEntry, avc3SampleEntry); } catch (IOException e) { throw new RuntimeException("Dumping sample entry to memory failed"); } } else { avc1toavc3.put(sampleEntry, sampleEntry); } } samples = new ReplaceSyncSamplesList(parent.getSamples()); }
decSe = (SampleEntry) new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray()))).getBoxes().get(0); } catch (IOException e) { throw new RuntimeException("Dumping stsd to memory failed");
try { se.getBox(Channels.newChannel(baos)); encSampleEntry= (SampleEntry) new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray()))).getBoxes().get(0); } catch (IOException e) { throw new RuntimeException("Dumping stsd to memory failed");
/** * Shortcut to get the MovieBox since it is often needed and present in * nearly all ISO 14496 files (at least if they are derived from MP4 ). * * @return the MovieBox or <code>null</code> */ public MovieBox getMovieBox() { for (Box box : getBoxes()) { if (box instanceof MovieBox) { return (MovieBox) box; } } return null; }
IsoFile isoFile = new IsoFile("project.mp4"); UserBox userbox = isoFile.getBoxes(UserBox.class).get(0); System.out.println(new String(userbox.getData()));
public Avc1ToAvc3TrackImpl(Track parent) throws IOException { super(parent); for (SampleEntry sampleEntry : parent.getSampleEntries()) { if (sampleEntry.getType().equals("avc1")) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { // This creates a copy cause I can't change the original instance sampleEntry.getBox(Channels.newChannel(baos)); VisualSampleEntry avc3SampleEntry = (VisualSampleEntry) new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray()))).getBoxes().get(0); avc3SampleEntry.setType("avc3"); avc1toavc3.put(sampleEntry, avc3SampleEntry); } catch (IOException e) { throw new RuntimeException("Dumping sample entry to memory failed"); } } else { avc1toavc3.put(sampleEntry, sampleEntry); } } samples = new ReplaceSyncSamplesList(parent.getSamples()); }
decSe = (SampleEntry) new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray()))).getBoxes().get(0); } catch (IOException e) { throw new RuntimeException("Dumping stsd to memory failed");
try { MovieBox moov = isoFile.getBoxes(MovieBox.class).get(0); if (log.isDebugEnabled()) { log.debug("moov children: {}", moov.getBoxes().size()); log.debug("Time: {}", formattedDuration); List<MediaDataBox> mdats = isoFile.getBoxes(MediaDataBox.class); if (mdats != null && !mdats.isEmpty()) { log.debug("mdat count: {}", mdats.size());
try { MovieBox moov = isoFile.getBoxes(MovieBox.class).get(0); if (log.isDebugEnabled()) { log.debug("moov children: {}", moov.getBoxes().size()); log.debug("Time: {}", formattedDuration); List<MediaDataBox> mdats = isoFile.getBoxes(MediaDataBox.class); if (mdats != null && !mdats.isEmpty()) { log.debug("mdat count: {}", mdats.size());
try { MovieBox moov = isoFile.getBoxes(MovieBox.class).get(0); if (log.isDebugEnabled()) { log.debug("moov children: {}", moov.getBoxes().size()); log.debug("Time: {}", formattedDuration); List<MediaDataBox> mdats = isoFile.getBoxes(MediaDataBox.class); if (mdats != null && !mdats.isEmpty()) { log.debug("mdat count: {}", mdats.size()); List<MovieFragmentBox> moofs = isoFile.getBoxes(MovieFragmentBox.class); // moof if (moofs != null && !moofs.isEmpty()) { log.info("Movie contains {} framents", moofs.size()); if (isoFile.getBoxes(MovieFragmentRandomAccessBox.class).size() > 0) { // mfra log.info("Movie contains frament random access info"); if (isoFile.getBoxes(ActionMessageFormat0SampleEntryBox.class).size() > 0) { log.info("Movie contains AMF entries");
try { MovieBox moov = isoFile.getBoxes(MovieBox.class).get(0); if (log.isDebugEnabled()) { log.debug("moov children: {}", moov.getBoxes().size()); log.debug("Time: {}", formattedDuration); List<MediaDataBox> mdats = isoFile.getBoxes(MediaDataBox.class); if (mdats != null && !mdats.isEmpty()) { log.debug("mdat count: {}", mdats.size()); List<MovieFragmentBox> moofs = isoFile.getBoxes(MovieFragmentBox.class); // moof if (moofs != null && !moofs.isEmpty()) { log.info("Movie contains {} framents", moofs.size()); if (isoFile.getBoxes(MovieFragmentRandomAccessBox.class).size() > 0) { // mfra log.info("Movie contains frament random access info"); if (isoFile.getBoxes(ActionMessageFormat0SampleEntryBox.class).size() > 0) { log.info("Movie contains AMF entries");
try { se.getBox(Channels.newChannel(baos)); encSampleEntry= (SampleEntry) new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray()))).getBoxes().get(0); } catch (IOException e) { throw new RuntimeException("Dumping stsd to memory failed");