sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.75k stars 566 forks source link

Muxing mp4 DASH tracks #324

Closed kapodamy closed 5 years ago

kapodamy commented 6 years ago

I'm trying to mux two tracks from two different files (m4v and m4a files respectively) both files are DASH type. The generated MP4 file is not created correctly. Also, Windows Explorer does not show a thumbnail

The code I use:

public static Track loadTrackFrom(String path) {
  Movie m4 = MovieCreator.build(path);
  return m4.getTracks().get(0);
}

public static void Main(String[] args) {
    Track m4v = loadTrackFrom("video-dash.m4v");
    Track m4a = loadTrackFrom("audio-dash.m4a");
    RandomAccessFile raf = new RandomAccessFile("merged.mp4", "rw");

    Movie m = new Movie();
    m.addTrack(m4v);
    m.addTrack(m4a);

    DefaultMp4Builder builder = new DefaultMp4Builder();
    Container stdMp4 = builder.build(m);
    stdMp4.writeContainer(raf.getChannel());
    raf.close();
}

In the merged file the following fields are empty:

  1. moov/trak[0]/edts/elst{0}.segmentDuration
  2. moov/trak[0]/mdia/hdlr.name (is optional?)
  3. moov/trak[1]/mdia/hdlr.name (is optional?)
sannies commented 6 years ago

Hi, would you be able to create a PR for hdlr name and segment duration (how can segment duration be empty? Isn't it a 32 bit integer? It can be empty but missing?) The additional 8 bytes don't do any harm (besides wasting 8 bytes). By always adding 8 bytes I have enough room for the extended size field when mdat becomes larger than 2GB and thereby the offset calculation is simplified.

kapodamy commented 6 years ago

Isn't it a 32 bit integer? It can be empty but missing?

I mean values are 0 and about mdat, i did not know that. later I will take a look at DefaultMp4Builder.

sannies commented 6 years ago

The value that is zero describes a time-shift of the track in the movie timeline. It would surprise me if zero were a problem as zero is a very typical value.

kapodamy notifications@github.com schrieb am So., 5. Aug. 2018, 17:38:

Isn't it a 32 bit integer? It can be empty but missing?

I mean values are 0 and about mdat, i did not know that.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sannies/mp4parser/issues/324#issuecomment-410528293, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKUDyZgTPHi72Iqg5abFjOKsgPg74v2ks5uNxF3gaJpZM4VvMUg .

kapodamy commented 6 years ago

Ok, moov/trak[0]/edts/elst{0}.segmentDuration it doesnt need to have a non-zero value. using Icaros ThumbnailProvider (included with K-Lite Codec Pack) can be zero but with default Windows explorer thumbnail provider no. Its strange.

also researching better the file moov/trak[0]/tkhd.duration is zero.

in conclusion, to obtain a thumbnail with any thumbnail provider setting... : moov/mvhd.timeScale to 1000. moov/mvhd.duration to duration / timeScale * 1000 moov/trak[0]/tkhd.duration with the same value in moov/trak[0]/mdia/mdhd.duration moov/trak[0]/edts/elst{0}.segmentDuration with the track duration in miliseconds.

track[0] is the video track