mp4parse timelapse frame rate
Asked Answered
M

1

13

I'm trying to ingest a mp4 file and make it a timelapse. It works with the code attached below. However, the output file has frame rate of 16*originalFrameRate. Since I don't intend to play it as a slow motion video I'd prefer to drop those redundant frames to make the output file smaller.

Movie inputMovie = MovieCreator.build(fileUri);

List<Track> videoTracks = new LinkedList<>();

for (Track track : inputMovie.getTracks()) {
    if (track.getHandler().equals("vide")) {
        videoTracks.add(track);
    }
}

final int speedByFactorOf = 16;

Movie outputMovie = new Movie();

AppendTrack appendedTracks = new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()]));
outputMovie.addTrack(new WrappingTrack(appendedTracks) {
    @Override
    public long[] getSampleDurations() {
        long[] l = super.getSampleDurations();
        for (int i = 0; i < l.length; i++) {
            l[i] /= speedByFactorOf;
        }
        return l;
    }
});

BasicContainer out = (BasicContainer) new DefaultMp4Builder().build(outputMovie);

FileChannel fc = new RandomAccessFile("timelapse.mp4", "rw").getChannel();
out.writeContainer(fc);
fc.close();
out.close();

I was unable to find any examples of how to change the output frame rate.

Mucoid answered 4/6, 2018 at 0:26 Comment(3)
So basically you want to play a 16 min video in 1 min? If so then how do you decide which frames to drop? Because dropping a frame means you will have a glitch in the transitionsSkell
I assume time lapses don't have smooth transitions, do they? I'd like just to keep 1 out of every 16 consecutive framesMucoid
Reading this on their repo Create JPEGs from a movie. No - this is no decoder. The MP4 Parser doesn't know how to do that. Create a movie from JPEGs, I have a feeling that they don't support what you are askingSkell
E
0

As stated by @tarun-lalwani if the project you're referring to is https://github.com/sannies/mp4parser then it is only able to edit the MP4 container and NOT the video / audio / media etc. held within the container. Even if you could use metadata to accelerate the FPS by sixteen times, the file size would not become any smaller because all the frames would still be within the file (just shown for a shorter duration). You would need to use something like FFmpeg (e.g. via https://github.com/bramp/ffmpeg-cli-wrapper ) or some other programmatic video editor to do what you're describing thus only keeping every sixteenth frame of video so the video file actually becomes smaller.

TLDR; mp4parser is not the correct project for editing video (as opposed to metadata) and what you want to achieve sounds like it is beyond the scope of just fiddling with the container.

Eloiseelon answered 10/6, 2018 at 6:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.