DeepMedia logo
Open Source
Search...

Other versions of this page

Improve this page on GitHub

Search

Clip & Trim

Starting from v0.8.0, Transcoder offers the option to clip or trim video segments, on one or both ends. This is done by using special DataSource objects that wrap you original source, so that, in case of concatenation of multiple media files, the trimming values can be set individually for each segment.

⚠️

If Transcoder determines that the video should be decoded and re-encoded (status is TrackStatus.COMPRESSING) the clipping position is respected precisely. However, if your strategy does not include video decoding / re-encoding, the clipping position will be moved to the closest video sync frame. This means that the clipped output duration might be different than expected, depending on the frequency of sync frames in your original file.

TrimDataSource

The TrimDataSource class lets you trim segments by specifying the amount of time to be trimmed at both ends. For example, the code below will trim the file by 1 second at the beginning, and 2 seconds at the end:

kotlin
let source: DataSource = UriDataSource(context, uri) let trim: DataSource = TrimDataSource(source, 1000 * 1000, 2 * 1000 * 1000) Transcoder.into(filePath) .addDataSource(trim) .transcode()

It is recommended to always check source.getDurationUs() to compute the correct values.

ClipDataSource

The ClipDataSource class lets you clip segments by specifying a time window. For example, the code below clip the file from second 1 until second 5:

kotlin
let source: DataSource = UriDataSource(context, uri) let clip: DataSource = ClipDataSource(source, 1000 * 1000, 5 * 1000 * 1000) Transcoder.into(filePath) .addDataSource(clip) .transcode()

It is recommended to always check source.getDurationUs() to compute the correct values.

MethodDescription
TrimDataSource(source, long)Creates a new data source trimmed on start.
TrimDataSource(source, long, long)Creates a new data source trimmed on both ends.
ClipDataSource(source, long)Creates a new data source clipped on start.
ClipDataSource(source, long, long)Creates a new data source clipped on both ends.

Subscribe to the DeepMedia Newsletter

The latest news about DeepMedia products, open source projects and software development at our company.

By clicking “Subscribe”, you agree that DeepMedia may use your email address to send you newsletters, including commercial communications, and to process your personal data for this purpose. You agree that DeepMedia may process said data using third-party services for this purpose in accordance with the DeepMedia Privacy Policy. You can revoke this consent at any time using the unsubscribe link included in each email or by writing at contact@deepmedia.io.