Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultMp4Builder produces incorrect EditListBox segment durations #443

Open
vlyutskanov opened this issue Jun 24, 2021 · 0 comments
Open

Comments

@vlyutskanov
Copy link

When I use DefaultMp4Builder.build on a movie with h264 video track with edits and aac audio track, the resulting mp4 file has its video reduced to a fraction and only the audio playing.

After some investigation, I noticed that the Movie class has this function defined:

    public long getTimescale() {
        long timescale = this.getTracks().iterator().next().getTrackMetaData().getTimescale();
        for (Track track : this.getTracks()) {
            timescale = gcd(track.getTrackMetaData().getTimescale(), timescale);
        }
        return timescale;
    }

and the DefaultMp4Builder has this one:

    public long getTimescale(Movie movie) {

        long timescale = movie.getTracks().iterator().next().getTrackMetaData().getTimescale();
        for (Track track : movie.getTracks()) {
            timescale = lcm(timescale, track.getTrackMetaData().getTimescale());
        }
        return timescale;
    }

While similar, they differ in logic as the first one uses gdc and the second lcm. DefaultMp4Builder uses in most cases the lcm version, but specifically uses the gcd version in function createEdts:

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

If I override createEdts to use the lcm version like this:

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

then I get the expected mp4 file that has the complete video.

Shouldn't Movie.getTimescale use lcm too? Or if gcd is the correct behavior there, perhaps DefaultMp4Builder should use consistently the lcm function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant