sannies / mp4parser

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

How to deal with seconds or some second fraction to trim a video? #400

Closed fmmarzoa closed 4 years ago

fmmarzoa commented 4 years ago

Hi there,

I need to trim a video so as to keep only the last n seconds. Say n is 5.

I'm looking into this example: https://github.com/sannies/mp4parser/blob/master/examples/src/main/java/com/googlecode/mp4parser/SingleTrackShortenExample.java

But the data I'm getting from the track metadata is quite confusing. First things first, I don't seem to be able to figure out the length of the video in seconds. For a pretty small video Track.getDuration() is returning 2,307,776 (are these samples?) and videoTrack.getTrackMetaData().getTimescale returns 90,000 (samples per second or something? that many?).

I think I probably lack of some basic understanding of the stuff at work here, so any help in that sense would be welcome.

Thanks a lot in advance!

fmmarzoa commented 4 years ago

Just got ffmpeg to do the trick, so there's no need for an answer. Thanks!