private SampleEntry mergeSampleEntry(SampleEntry se1, SampleEntry se2) { if (!se1.getType().equals(se2.getType())) { return null; } else if (se1 instanceof VisualSampleEntry && se2 instanceof VisualSampleEntry) { return mergeVisualSampleEntry((VisualSampleEntry) se1, (VisualSampleEntry) se2); } else if (se1 instanceof AudioSampleEntry && se2 instanceof AudioSampleEntry) { return mergeAudioSampleEntries((AudioSampleEntry) se1, (AudioSampleEntry) se2); } else { return null; } }
static String getFormat(Track track) { String type = null; for (SampleEntry sampleEntry : track.getSampleEntries()) { OriginalFormatBox frma; frma = Path.getPath((Container) sampleEntry, "sinf/frma"); String _type; if (frma != null) { _type = frma.getDataFormat(); } else { _type = sampleEntry.getType(); } if (type == null) { type = _type; } else { if (!type.equals(_type)) { throw new RuntimeException("The SyncSampleIntersectionFindler only works when all SampleEntries are of the same type. " + type + " vs. " + _type); } } } return type; }
public SilenceTrackImpl(Track ofType, long ms) { source = ofType; name = "" + ms + "ms silence"; assert ofType.getSampleEntries().size() == 1: ""; if ("mp4a".equals(ofType.getSampleEntries().get(0).getType())) { int numFrames = l2i(getTrackMetaData().getTimescale() * ms / 1000 / 1024); decodingTimes = new long[numFrames]; Arrays.fill(decodingTimes, getTrackMetaData().getTimescale() * ms / numFrames / 1000); while (numFrames-- > 0) { samples.add(new SampleImpl((ByteBuffer) ByteBuffer.wrap(new byte[]{ 0x21, 0x10, 0x04, 0x60, (byte) 0x8c, 0x1c, }).rewind(), ofType.getSampleEntries().get(0))); } } else { throw new RuntimeException("Tracks of type " + ofType.getClass().getSimpleName() + " are not supported"); } }
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()); }
if (decSe == null) { OriginalFormatBox frma; if (se.getType().equals("enca")) { frma = Path.getPath((AudioSampleEntry) se, "sinf/frma"); } else if (se.getType().equals("encv")) { frma = Path.getPath((VisualSampleEntry) se, "sinf/frma"); } else { ((VisualSampleEntry) decSe).setType(frma.getDataFormat()); } else { throw new RuntimeException("I don't know " + decSe.getType());
String type = t.getSampleEntries().get(0).getType(); System.out.println("Track of type " + type ); if (t.getSampleEntries().get(0) instanceof VisualSampleEntry) {
@Override public Sample get(final int index) { final Sample orignalSample = parentSamples.get(index); if (orignalSample.getSampleEntry().getType().equals("avc1") && Arrays.binarySearch(Avc1ToAvc3TrackImpl.this.getSyncSamples(), index + 1) >= 0) {
private SampleEntry mergeSampleEntry(SampleEntry se1, SampleEntry se2) { if (!se1.getType().equals(se2.getType())) { return null; } else if (se1 instanceof VisualSampleEntry && se2 instanceof VisualSampleEntry) { return mergeVisualSampleEntry((VisualSampleEntry) se1, (VisualSampleEntry) se2); } else if (se1 instanceof AudioSampleEntry && se2 instanceof AudioSampleEntry) { return mergeAudioSampleEntries((AudioSampleEntry) se1, (AudioSampleEntry) se2); } else { return null; } }
public static String getFormat(Track track) { List<SampleEntry> ses = track.getSampleEntries(); String format = null; for (SampleEntry se : ses) { OriginalFormatBox frma = Path.getPath((Container) se, "sinf/frma"); if (frma != null) { if (format == null || format.equals(frma.getDataFormat())) { format = frma.getDataFormat(); } else { throw new RuntimeException("cant determine format of track"); } } else { if (format == null || format.equals(se.getType())) { format = se.getType(); } else { throw new RuntimeException("cant determine format of track"); } } } return format; }
public SilenceTrackImpl(Track ofType, long ms) { source = ofType; name = "" + ms + "ms silence"; assert ofType.getSampleEntries().size() == 1: ""; if ("mp4a".equals(ofType.getSampleEntries().get(0).getType())) { int numFrames = l2i(getTrackMetaData().getTimescale() * ms / 1000 / 1024); decodingTimes = new long[numFrames]; Arrays.fill(decodingTimes, getTrackMetaData().getTimescale() * ms / numFrames / 1000); while (numFrames-- > 0) { samples.add(new SampleImpl((ByteBuffer) ByteBuffer.wrap(new byte[]{ 0x21, 0x10, 0x04, 0x60, (byte) 0x8c, 0x1c, }).rewind(), ofType.getSampleEntries().get(0))); } } else { throw new RuntimeException("Tracks of type " + ofType.getClass().getSimpleName() + " are not supported"); } }
static String getFormat(Track track) { String type = null; for (SampleEntry sampleEntry : track.getSampleEntries()) { OriginalFormatBox frma; frma = Path.getPath((Container) sampleEntry, "sinf/frma"); String _type; if (frma != null) { _type = frma.getDataFormat(); } else { _type = sampleEntry.getType(); } if (type == null) { type = _type; } else { if (!type.equals(_type)) { throw new RuntimeException("The SyncSampleIntersectionFindler only works when all SampleEntries are of the same type. " + type + " vs. " + _type); } } } return type; }
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()); }
if (decSe == null) { OriginalFormatBox frma; if (se.getType().equals("enca")) { frma = Path.getPath((AudioSampleEntry) se, "sinf/frma"); } else if (se.getType().equals("encv")) { frma = Path.getPath((VisualSampleEntry) se, "sinf/frma"); } else { ((VisualSampleEntry) decSe).setType(frma.getDataFormat()); } else { throw new RuntimeException("I don't know " + decSe.getType());
@Override public Sample get(final int index) { final Sample orignalSample = parentSamples.get(index); if (orignalSample.getSampleEntry().getType().equals("avc1") && Arrays.binarySearch(Avc1ToAvc3TrackImpl.this.getSyncSamples(), index + 1) >= 0) {
log.debug("Sample entry type: {}", entry.getType());
log.debug("Sample entry type: {}", entry.getType());
type = frma.getDataFormat(); } else { type = se.getType();