예제 #1
0
  protected MovieBox createMovieBox(Movie movie, Map<Track, int[]> chunks) {
    MovieBox movieBox = new MovieBox();
    MovieHeaderBox mvhd = new MovieHeaderBox();

    mvhd.setCreationTime(new Date());
    mvhd.setModificationTime(new Date());
    mvhd.setMatrix(movie.getMatrix());
    long movieTimeScale = getTimescale(movie);
    long duration = 0;

    for (Track track : movie.getTracks()) {
      long tracksDuration;

      if (track.getEdits() == null || track.getEdits().isEmpty()) {
        tracksDuration =
            (track.getDuration() * movieTimeScale / track.getTrackMetaData().getTimescale());
      } else {
        double d = 0;
        for (Edit edit : track.getEdits()) {
          d += (long) edit.getSegmentDuration();
        }
        tracksDuration = (long) (d * movieTimeScale);
      }

      if (tracksDuration > duration) {
        duration = tracksDuration;
      }
    }

    mvhd.setDuration(duration);
    mvhd.setTimescale(movieTimeScale);
    // find the next available trackId
    long nextTrackId = 0;
    for (Track track : movie.getTracks()) {
      nextTrackId =
          nextTrackId < track.getTrackMetaData().getTrackId()
              ? track.getTrackMetaData().getTrackId()
              : nextTrackId;
    }
    mvhd.setNextTrackId(++nextTrackId);

    movieBox.addBox(mvhd);
    for (Track track : movie.getTracks()) {
      movieBox.addBox(createTrackBox(track, movie, chunks));
    }
    // metadata here
    Box udta = createUdta(movie);
    if (udta != null) {
      movieBox.addBox(udta);
    }
    return movieBox;
  }
예제 #2
0
  protected Box createEdts(Track track, Movie movie) {
    if (track.getEdits() != null && track.getEdits().size() > 0) {
      EditListBox elst = new EditListBox();
      elst.setVersion(0); // quicktime won't play file when version = 1
      List<EditListBox.Entry> entries = new ArrayList<EditListBox.Entry>();

      for (Edit edit : track.getEdits()) {
        entries.add(
            new EditListBox.Entry(
                elst,
                Math.round(edit.getSegmentDuration() * movie.getTimescale()),
                edit.getMediaTime() * track.getTrackMetaData().getTimescale() / edit.getTimeScale(),
                edit.getMediaRate()));
      }

      elst.setEntries(entries);
      EditBox edts = new EditBox();
      edts.addBox(elst);
      return edts;
    } else {
      return null;
    }
  }
예제 #3
0
  protected TrackBox createTrackBox(Track track, Movie movie, Map<Track, int[]> chunks) {

    TrackBox trackBox = new TrackBox();
    TrackHeaderBox tkhd = new TrackHeaderBox();

    tkhd.setEnabled(true);
    tkhd.setInMovie(true);
    tkhd.setInPreview(true);
    tkhd.setInPoster(true);
    tkhd.setMatrix(track.getTrackMetaData().getMatrix());

    tkhd.setAlternateGroup(track.getTrackMetaData().getGroup());
    tkhd.setCreationTime(track.getTrackMetaData().getCreationTime());

    if (track.getEdits() == null || track.getEdits().isEmpty()) {
      tkhd.setDuration(
          track.getDuration() * getTimescale(movie) / track.getTrackMetaData().getTimescale());
    } else {
      long d = 0;
      for (Edit edit : track.getEdits()) {
        d += (long) edit.getSegmentDuration();
      }
      tkhd.setDuration(d * track.getTrackMetaData().getTimescale());
    }

    tkhd.setHeight(track.getTrackMetaData().getHeight());
    tkhd.setWidth(track.getTrackMetaData().getWidth());
    tkhd.setLayer(track.getTrackMetaData().getLayer());
    tkhd.setModificationTime(new Date());
    tkhd.setTrackId(track.getTrackMetaData().getTrackId());
    tkhd.setVolume(track.getTrackMetaData().getVolume());

    trackBox.addBox(tkhd);

    trackBox.addBox(createEdts(track, movie));

    MediaBox mdia = new MediaBox();
    trackBox.addBox(mdia);
    MediaHeaderBox mdhd = new MediaHeaderBox();
    mdhd.setCreationTime(track.getTrackMetaData().getCreationTime());
    mdhd.setDuration(track.getDuration());
    mdhd.setTimescale(track.getTrackMetaData().getTimescale());
    mdhd.setLanguage(track.getTrackMetaData().getLanguage());
    mdia.addBox(mdhd);
    HandlerBox hdlr = new HandlerBox();
    mdia.addBox(hdlr);

    hdlr.setHandlerType(track.getHandler());

    MediaInformationBox minf = new MediaInformationBox();
    if (track.getHandler().equals("vide")) {
      minf.addBox(new VideoMediaHeaderBox());
    } else if (track.getHandler().equals("soun")) {
      minf.addBox(new SoundMediaHeaderBox());
    } else if (track.getHandler().equals("text")) {
      minf.addBox(new NullMediaHeaderBox());
    } else if (track.getHandler().equals("subt")) {
      minf.addBox(new SubtitleMediaHeaderBox());
    } else if (track.getHandler().equals("hint")) {
      minf.addBox(new HintMediaHeaderBox());
    } else if (track.getHandler().equals("sbtl")) {
      minf.addBox(new NullMediaHeaderBox());
    }

    // dinf: all these three boxes tell us is that the actual
    // data is in the current file and not somewhere external
    DataInformationBox dinf = new DataInformationBox();
    DataReferenceBox dref = new DataReferenceBox();
    dinf.addBox(dref);
    DataEntryUrlBox url = new DataEntryUrlBox();
    url.setFlags(1);
    dref.addBox(url);
    minf.addBox(dinf);
    //

    Box stbl = createStbl(track, movie, chunks);
    minf.addBox(stbl);
    mdia.addBox(minf);

    return trackBox;
  }