Trimming (clipping) a Video

Discuss about generic usage of MediaCoder.

Moderator: HuggiL

meRobs
Expert
Expert
Posts: 3116
Joined: Tue Jun 23, 2009 2:45 pm
Location: Sydney, Australia

Trimming (clipping) a Video

Postby meRobs » Sun Apr 18, 2010 9:25 pm

[Updated 25 Jun 2012]

With some exceptions (see 'Exceptions for Trimming' below), video files to be converted in MediaCoder may be trimmed during the conversion. By trimming I mean removing (avoiding) video from the start and/or end of a file.

The Trim Procedure
In MediaCoder trimming is referred to as 'clipping' and is done either in the “Clipping and Effects” window (found in Features menu or by hitting Shift+F6) or by setting start and end times on the Time tab. This window is accessed by clicking either the 'Select' button, on the Time tab, or the Effects button on the Picture tab.

Once the window is opened, the file will begin play and it may be paused & re-started via the controls (see Figure below). At any time, the start and end times for a trim may be set by clicking on the Mark In/Out buttons. The double-play arrows give 10-sec jumps.

Image

To view the trimmed segment, you would need to close the window via the 'OK' button and re-open (Effects or Select button). Play will then start at the Mark-in time rather than at time zero. To set the boundaries for the trim at the desired moments will take a bit of trial and error, either by replaying the file and re-setting the mark in and out points or by playing it and noting the times that would define the final file; then, enter them later on the Time tab.
Any change made in the 'window' would be reflected on the Time tab and vice versa.

Note 1: the Mark In/Out times that are set will not be overwritten by a Preset or File > Revert all Settings. These trim values will revert to their defaults (for a full file) only for a freshly loaded file.

I-frame
An I-frame, short for intra-frame, or Keyframe, is a type of video frame used by the MPEG standard, although, its use is more general. It is a single frame containing all of the data needed to display that frame, and is viewed independently of the frames that precede and follow it. Hence, programs that are able to trim the start of a file need to do so at an I-frame.

I-frames are usually scattered among less complete frames such as P-frames and B-frames (see also: viewtopic.php?f=17&t=8599&start=0).

Accuracy of Trim
For this study, I used MediaCoder builds 4606 and 4625 (see Note 2, below). To assess the trimmed files, I used Avidemux and VirtualDubMod, freebies that can increment a file frame by frame and indicate the type (I- or P-frame, etc). Avidemux will play files in DV AVI, FLV, MP4 and WMV, whereas, VirtualDubMod is good for DV AVI, Xvid/AVI and MPEG2.

I trimmed AVI files that had been created in MediaCoder using the DV Video or Xvid Codecs and files in the MPEG2, FLV, MKV, MP4 and WMV containers. All trimmed files were converted to DV AVI using the DV Video Codec so that their frames could be compared with the source files, in either Avidemux or VirtualDubMod, to assess the trim accuracy.

In all cases examined, the initial frame of the trimmed file corresponded to the first I-frame (defined above) of the source file after the set Mark-In time. This could be off by up to 10 sec. The last frame of the trimmed file tended to be such as to give the 'set' duration, roughly, i.e., the difference between the set Mark-In and Mark-Out times, or between the Start Position and End Position on the Time tab. In other words, if the start of the trimmed file was 5 sec after the Mark-in time, the final frame would be roughly 5 sec late as well.

Since the start of a trimmed file is at an I-frame, the accuracy of trim is related to the interval between I-frames. Files converted with the FFmpeg encoder tend to have 250 frames (max) between I-frames, by default. This amounts to 10 sec for PAL conversions and 8.34 sec for NTSC and applied to most of the files in this test, including the Xvid/AVI, WMV, FLV and some MPEG2 files. The other MPEG2 files had a GOP (I-frame interval) set at 12 frames (~0.5 sec), so as to better suit DVD creation (see: viewtopic.php?f=17&t=8599&start=0). Hence, the trim error for these latter files was less than 0.5 sec. Since most VOB files would have a similar GOP, their trim would be to a similar accuracy.

The most accurate trim would be for DV AVI source files, such as those created in MediaCoder with the DV Video Codec (PAL) and also for AVIs created with the Huffyuv Codec. This is because every frame in such a file is an I-frame. In this study the start frame of each trimmed DV-AVI file was effectively at the chosen Mark-In frame and the end of the file was within 1-2 frames of the Mark-Out frame.

I was also able to trim a VOB file from a DVD (ripped to the HDD) and selected via the Add Track function in MediaCoder and trimmed as above. Being DVD-compliant, the VOB had a GOP of 12 frames, and the cuts were accurate to 0.5 sec.

Note 2: the only problem I experienced was with DV AVI files trimmed in build 4625. The first attempt worked, but, after a trim & conversion, a repeat with different trim settings failed to output (had to reload the source file and start again)! All worked correctly for a DV AVI in build 4606 and for all other formats in both builds.

Exceptions for Trimming
For this study, I had tried a number of files that had been created by MediaCoder, such as WMV (WMV8 with PCM), MP4 (MPEG-4 with MP3), MKV (AVC with AAC), FLV (H263 and MP3), MPEG2 and various AVI types. Their trimming in build 4630 was as described above.
The function works in build 4630 (above) and in builds 4640 to 4700.

However, the trimming function does not work in builds from 4720 to 4799, as pointed out in the Test Report (viewtopic.php?f=17&t=9611).
Nor does it work in builds 5002 to 5180 (see: viewtopic.php?f=17&t=10383). It does work since then, until at least 5260.

On the other hand, VOB files, and possibly other formats, especially if not created by MediaCoder, may not be so successful. Certainly, if the VOB was the first of the VTS set (DVD title), it could be trimmed as described, as could later chapters selected using the Add Track feature (described in viewtopic.php?f=17&t=8082&start=0 ).

However, a VOB other than the first of the VTS Title set (defined in the guide: viewtopic.php?f=17&t=8082&start=0) could not be trimmed. The slider (scrubber), if dragged, would jump back to its starting position, often near the end of the file, the current time indication (see Figure) remained at zero and the Mark In/Out times could not be set. This does not appear to be a failure of a particular build (4630), since the old faithful 4399 also failed to trim these VOBs. In some builds of MediaCoder, however, the Trim (clip) feature does not work properly, see the Report in: viewtopic.php?f=17&t=8912&start=0

Note 3: programs that can trim such VOB files (VirtualDubMod and Avidemux, etc) are able to do so because they index the files first.
Have you checked out the Tips & Guides for MediaCoder? Try: http://forum.mediacoderhq.com/viewtopic.php?f=17&t=8061
Also, get older builds at: http://www.videohelp.com/tools/MediaCoder/old-versions#download

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 10 guests