コード例 #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
  private MovieBox createMovieBox(Movie movie) {
    MovieBox movieBox = new MovieBox();
    MovieHeaderBox mvhd = new MovieHeaderBox();
    mvhd.setVersion(1);
    mvhd.setCreationTime(DateHelper.convert(new Date()));
    mvhd.setModificationTime(DateHelper.convert(new Date()));

    long movieTimeScale = getTimescale(movie);
    long duration = 0;

    for (Track track : movie.getTracks()) {
      long tracksDuration =
          getDuration(track) * movieTimeScale / track.getTrackMetaData().getTimescale();
      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));
    }
    // metadata here
    Box udta = createUdta(movie);
    if (udta != null) {
      movieBox.addBox(udta);
    }
    return movieBox;
  }