0

I want to set the duration of an mp4 file using the mp4 atoms. I've updated the duration property for mvhd, mdhd, tkhd but with no luck. What i want to do is to set the length from 3 minutes to 30 seconds, let's say. I know that time=duration/timescale.

Thanks.

florinp
  • 329
  • 2
  • 5
  • 13
  • See http://stackoverflow.com/questions/18436551/mp4-atom-parsing-where-to-configure-time/18552833#18552833 – devshorts Nov 19 '13 at 22:19

2 Answers2

1

The duration in the fields there is just a kind of summary. You need to extend the time each single picture is displayed. Do that by manipulating the box found here:

/moov/trak/mdia/minf/stbl/stts

It is the time to sample atom/box. To learn about the content and structure of this atom/box you can safely use the Quicktime File Format Specification if you don't have an ISO/EIC 14496-12 at hand.

To increase or decrease the speed of the video you may multiply every sample duration (most cases just a single one) by a factor.

NOTE: H264 video also has the ctts box in some cases (if B-frames are used). You will need to modify the times there, too.

Sebastian Annies
  • 2,438
  • 1
  • 20
  • 38
1

Editing an mp4 file is not simple as modifying one box can affect its size and the size of all ancestors. Also timing values are tightly linked: DTS, cts , track duration, edit list, movie duration ... Some operations can be done simply in place, such as extending the duration of the last sample of a track and reflecting that change in the headers. In your case, reducing the duration means ignoring some samples. You could edit the sample tables but that's very hard and will change almost all boxes. You could use an edit list but that's also hard. It's easier to make a new file with MP4Box:

MP4Box -add input.mp4:dur=30 output.mp4
cconcolato
  • 1,186
  • 10
  • 9