Trimming Sources
In most transcoding operations, the entire contents of one file are converted into a different format. However, there can be cases where you don’t want the entire file and instead want only a sub-segment of the file to be converted. Some examples include:
- Removing bars and tone from the beginning of a video
- Removing excess material from the end of a video
- Extracting a short selection to use as a preview video
- Transcoding a segment in order to rapidly test encoding parameters
- Perform complex editing operations with multiple clips
Within the Hybrik job JSON, you can specify each of these types of transcodes using the “trim” specifier. In this short tutorial, we will show you how to use the “trim” operation on your content. You should already be familiar with Hybrik’s JSON structure before going further. If not, please take a few minutes to read the Hybrik JSON Tutorial before continuing.
The Trim Operation
The trim operation is specified by adding it to the source element. Our normal (untrimmed) source element looks like this:
{
"uid": "source_file",
"kind": "source",
"payload": {
"kind": "asset_url",
"payload": {
"storage_provider": "s3",
"url": "s3://hybrik-examples/public/sources/sample1.mp4"
}
}
}
By adding a “trim” object, you can specify how you would like Hybrik to trim the source content. Here is the same example source file, but this time we have specified that we want create an output that is only 60 seconds long – starting from 5 seconds into the video:
{
"uid": "source_file",
"kind": "source",
"payload": {
"kind": "asset_url",
"payload": {
"storage_provider": "s3",
"url": "s3://hybrik-examples/public/sources/sample1.mp4",
"trim": {
"inpoint_sec": 5,
"outpoint_sec": 65
}
}
}
}
Trim Variations
Hybrik provides a variety of ways that you can specify the trim operation. For example, if you do not specify the outpoint, the trim will include the entirety of the source after the inpoint. This example uses everything after the first 6 seconds of the file:
"trim": {
"inpoint_sec": 6
}
Conversely, if you do not specify an inpoint, Hybrik will use the start of the file as the starting point. This example uses only the first 2 minutes of the source file:
"trim": {
"outpoint_sec": 120
}
You can also specify an inpoint and a duration. This example creates a 2 minute clip, starting at 1 minute into the source file:
"trim": {
"inpoint_sec": 60,
"duration_sec": 120
}
Frames and Timecode
In addition to specifying start and end points in seconds, you can also specify them by timecode. Here is an example using the timecode designation to trim out a 2 minute clip starting at 20 seconds into the source file:
"trim": {
"inpoint_tc": "00:00:20:00",
"outpoint_tc": "00:02:20:00"
}
And finally, you can specify trimming using frame numbers. Here is an example using frame numbers in a 24 frame per second input video. This frame number designation trims out a 2 minute clip starting at 1 minute into the source file:
"trim": {
"inpoint_frame": 1440,
"outpoint_frame": 4320
}
Trimming an asset_complex
Sometimes you might be stitching components together, you can read more on this source type in our tutorial on Hybrik JSON Tutorial. The same trim operations can be applied to individual components in asset_components
.
By default, Hybrik will trim the audio to the duration of the video track. In the example below, even though our source audio track runs the full duration of the video clip, it will be trimmed to 30 seconds to match the trim in the video component.
"asset_versions": [
{
"version_uid": "video",
"asset_components": [
{
"kind": "name",
"component_uid": "video_source",
"name": "{{video_source}}",
"location": {
"storage_provider": "s3",
"path": "{{source_path}}"
},
"contents": [
{
"kind": "video"
}
],
"trim": {
"inpoint_sec": 0,
"outpoint_sec": 30
}
},
{
"kind": "name",
"component_uid": "stereo_audio",
"name": "{{audio_source}}",
"location": {
"storage_provider": "s3",
"path": "{{source_path}}"
},
"contents": [
{
"kind": "audio"
}
]
}
]
}
]
It is not possible to apply the trim to the asset_version
, but the above example shows how to effectively trim the asset_version.
If you want to trim the video to match the audio track duration, you can change the reference_media_track
that you want to trim to. In the next example, we apply a 30 second trim to our audio source and tell the video track to match.
"asset_versions": [
{
"version_uid": "video",
"asset_components": [
{
"kind": "name",
"component_uid": "video_source",
"name": "{{video_source}}",
"location": {
"storage_provider": "s3",
"path": "{{source_path}}"
},
"contents": [
{
"kind": "video"
}
],
"trim": {
"inpoint": "track_begin",
"reference_media_track": "audio"
}
},
{
"kind": "name",
"component_uid": "stereo_audio",
"name": "{{audio_source}}",
"location": {
"storage_provider": "s3",
"path": "{{source_path}}"
},
"contents": [
{
"kind": "audio"
}
],
"trim": {
"inpoint_sec": 0,
"outpoint_sec": 30
}
}
]
}
]
Trimming in the source_pipeline
Hybrik represents the combined media of an asset_complex
as a “virtual source”, or the Source Pipeline. Read the tutorial on source_pipeline
for a better explanation. You may want to apply your trim to the source_pipeline
when you have several asset_components
that you have stitched together and you want to trim them evenly. For example, if you have audio, video, and subtitles you could apply the trim to the entire composed source with a single trim in the source_pipeline
.
Another example is if you have a slate at the beginning of your video for 30 seconds before the content and you want to transcode a mezzanine version with the slate and a proxy version without the slate. If you applied the trim to the source, you could not generate the version with slate at all. Since the source_pipeline
trim is applied directly in the transcode
task, you would set up 1 transcode
task with the trim and 1 transcode task without the trim in the source pipeline.
source_pipeline
trims are applied in the transcode
task like this:
{
"uid": "transcode_task",
"kind": "transcode",
"payload": {
"source_pipeline": {
"trim": {
"inpoint_sec": 30
}
},
...
Examples: