Saturday, May 7, 2011

MP4Box for trimming m4v videos

I had some H.264 m4v videos that I wanted to trim.

I used Avidemux a while back for trimming some xvid avi videos, but trying to trim the H.264 m4v videos didn't work. The cuts would work, but the video would be slightly jerky (using Copy). Re-encoding the video did work, but the whole point was to losslessly cut the video to save time & quality.

I tried using ffmpeg to trim the videos, but I could never get the -t flag to work. I came across a few other posts of other people having the same problem.

Then I found MP4Box, and it worked. (It's part of the gpac package).

This example extracts a new file starting at 0 and ending at 267.8 seconds.
MP4Box -splitx 0:267.8 input.m4v -out output.m4v
Notable commands from the manual that might be handy later:
-split time_in_seconds
splits in files of desired maximum duration. This will remove
all MPEG-4 Systems media.

-splits size_in_kilobytes
splits in files of desired maximum size. This will remove all
MPEG-4 Systems media.

-splitx start:end
extracts a new file from specified start to end times (in sec‐
onds). This will remove all MPEG-4 Systems media. When input
file is an ISO-Media file (QT, MP4, 3GP), if no output is speci‐
fied THE INPUT FILE IS OVERWRITTEN.


-cat <src_file>
concatenates all src_file tracks to input file, creating it if
not exisiting. Media samples are added at the end of existing
compatible tracks. If no compatible track is found for a media
it is created. Up to 20 cumulated -cat operations can be used.
Syntax is the same as -add.

3 comments:

  1. thanks for this; simple and concise; met my needs

    ReplyDelete
  2. Not working proeprly

    mp4box -splitx 1:2 "D:\HexaView-IDSS\IDSS.mp4" -out "D:\HexaView-IDSS\Clip1.mp4"

    This should generate 2 sec clip but it is generating 9 sec clip

    ReplyDelete