Beispiel #1
0
  @Override
  void executeExample() throws IOException {
    String audioEnglish = EXAMPLE_ROOT + "/count-video.mp4";
    Movie countVideo = MovieCreator.build(audioEnglish);

    TextTrackImpl subTitleEng = new TextTrackImpl();
    subTitleEng.getTrackMetaData().setLanguage("eng");

    subTitleEng.getSubs().add(new TextTrackImpl.Line(5000, 6000, "Five"));
    subTitleEng.getSubs().add(new TextTrackImpl.Line(8000, 9000, "Four"));
    subTitleEng.getSubs().add(new TextTrackImpl.Line(12000, 13000, "Three"));
    subTitleEng.getSubs().add(new TextTrackImpl.Line(16000, 17000, "Two"));
    subTitleEng.getSubs().add(new TextTrackImpl.Line(20000, 21000, "one"));

    countVideo.addTrack(subTitleEng);

    TextTrackImpl subTitleDeu =
        SrtParser.parse(new FileInputStream(new File(EXAMPLE_ROOT + "/count-subs-deutsch.srt")));
    subTitleDeu.getTrackMetaData().setLanguage("deu");
    countVideo.addTrack(subTitleDeu);

    Container out = new DefaultMp4Builder().build(countVideo);
    FileOutputStream fos = new FileOutputStream(new File(EXAMPLE_ROOT + "/output.mp4"));
    FileChannel fc = fos.getChannel();
    out.writeContainer(fc);
    fos.close();
  }
  @Test
  public void testEncryptDecryptFragmentedMp4() throws Exception {
    SecretKey sk =
        new SecretKeySpec(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, "AES");
    Movie m =
        MovieCreator.build(
            CencTracksImplTest.class.getProtectionDomain().getCodeSource().getLocation().getFile()
                + "/com/googlecode/mp4parser/authoring/samples/1365070268951.mp4");

    List<Track> encTracks = new LinkedList<Track>();
    for (Track track : m.getTracks()) {
      encTracks.add(new CencEncryptingTrackImpl(track, UUID.randomUUID(), sk));
    }
    m.setTracks(encTracks);

    Mp4Builder mp4Builder = new FragmentedMp4Builder();
    Container c = mp4Builder.build(m);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    c.writeContainer(Channels.newChannel(baos));

    c.writeContainer(new FileOutputStream("output.mp4").getChannel());

    Movie m2 = MovieCreator.build(new MemoryDataSourceImpl(baos.toByteArray()));
    List<Track> decTracks = new LinkedList<Track>();
    for (Track track : m2.getTracks()) {
      decTracks.add(new CencDecryptingTrackImpl((CencEncyprtedTrack) track, sk));
    }
    m2.setTracks(decTracks);
    c = mp4Builder.build(m2);

    c.writeContainer(new FileOutputStream("output2.mp4").getChannel());
  }
Beispiel #3
0
  public static void main(String[] args) throws IOException {
    //        AACTrackImpl aacTrack = new
    // AACTrackImpl(Ac3Example.class.getResourceAsStream("/sample.aac"));
    AACTrackImpl aacTrack =
        new AACTrackImpl(
            new FileDataSourceImpl(
                "/Users/magnus/Projects/castlabs/cff/Solekai015_1920_29_75x75_v2/Solekai_BeautifulTension_15sec_160k.aac"));
    Movie m = new Movie();
    m.addTrack(aacTrack);
    DefaultMp4Builder mp4Builder = new DefaultMp4Builder();
    Container out = mp4Builder.build(m);
    FileOutputStream fos = new FileOutputStream("output.mp4");
    FileChannel fc = fos.getChannel();
    out.writeContainer(fc);

    fos.close();
  }
  public static void main(String[] args) throws IOException {
    String audioEnglish =
        RemoveSomeSamplesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile()
            + "/count-english-audio.mp4";
    Movie originalMovie = MovieCreator.build(new FileInputStream(audioEnglish).getChannel());

    Track audio = originalMovie.getTracks().get(0);

    Movie nuMovie = new Movie();
    nuMovie.addTrack(
        new AppendTrack(
            new CroppedTrack(audio, 0, 10),
            new CroppedTrack(audio, 100, audio.getSamples().size())));

    Container out = new DefaultMp4Builder().build(nuMovie);
    FileOutputStream fos = new FileOutputStream(new File("output.mp4"));
    out.writeContainer(fos.getChannel());
    fos.close();
  }