Skip to Content
Mux Docs: Home

Create clips from your videos

Learn how to create clips from your video files or live stream event recordings.

To drive higher viewer engagement with the videos already on your service, you can create additional videos from your existing library or catalog. These videos could:

  • Provide quick previews
  • Highlight key moments
  • Be polished versions of a live stream with the extra minutes trimmed from the beginning & end (aka preroll and postroll slates) for on-demand replays

Mux can now help you quickly create these kinds of videos using the Clipping functionality.

1Create a clip

When you POST a new video or start live streaming, Mux creates a new asset for the video file or live stream event recording. You can create a clip from an existing asset by making a POST request to /assets endpointAPI and defining the input object's clipping parameters.

  • url is defined with mux://assets/{asset_id} template where asset_id is the source Asset Identifier to create the clip from.
  • start_time is the time offset in seconds from the beginning of the video, indicating the clip's start marker. The default value is 0 when not included.
  • end_time is the time offset in seconds from the beginning of the video, indicating the clip's end marker. The default value is the duration of the video when not included.

A request and response might look something like this:

Request

curl https://api.mux.com/video/v1/assets \
-H "Content-Type: application/json" \
-X POST \
-d '{
"input": [
{
"url": "mux://assets/01itgOBvgjAbES7Inwvu4kEBtsQ44HFL6",
"start_time": 10.0,
"end_time": 51.10
}
],
"playback_policy": [
"public"
]
}' \
-u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}

Response

{
"data": {
"status": "preparing",
"playback_ids": [
{
"policy": "public",
"id": "TXjw00EgPBPS6acv7gBUEJ14PEr5XNWOe"
}
],
"mp4_support": "none",
"master_access": "none",
"id": "kcP3wS3pKcEPywS5zjJk7Q1Clu99SS1O",
"created_at": "1607876845",
"source_asset_id": "01itgOBvgjAbES7Inwvu4kEBtsQ44HFL6"
}
}

Mux creates a new asset for the clip. And the response will include an Asset ID and a Playback ID.

  • Asset IDs are used to manage assets using api.mux.com (e.g. to read or delete an asset).
  • Playback IDsAPI are used to stream an asset to a video player through stream.mux.com. You can add multiple playback IDs to an asset to create playback URLs with different viewing permissions, and you can delete playback IDs to remove access without deleting the asset.
  • source_asset_id is the video or live stream event recording asset used to create the clip. The source_asset_id can be useful for associating clips with the source video object in your CMS.

2Wait for "ready" event

When the clip is ready for playback, the asset "status" changes to "ready".

The best way to do this is via webhooks. Mux can send a webhook notification as soon as the asset is ready. See the webhooks guide for details.

If you can't use webhooks for some reason, you can manually poll the asset APIAPI to see asset status. Note that this only works at low volume. Try this example:

Auto-populate an example request:

curl https://api.mux.com/video/v1/assets/{ASSET_ID} \
-H "Content-Type: application/json" \
-u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}

Please don't poll this API more than once per second.

3Play your clip

To play back the video, create a playback URL using the PLAYBACK_ID you received when you created the clip.

https://stream.mux.com/{PLAYBACK_ID}.m3u8
implementation 'com.google.android.exoplayer:exoplayer-hls:2.X.X'
// Create a player instance.
SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();
// Set the media item to be played.
player.setMediaItem(MediaItem.fromUri("https://stream.mux.com/{PLAYBACK_ID}.m3u8"));
// Prepare the player.
player.prepare();

See the playback guide for more information about how to integrate with a video player.

FAQs

A few commonly asked questions:

How many clips can be created from a single source asset?

Unlimited! Mux creates a new asset for each clip. Hence, there is no limit to how many clips you can create.

Is there a cost to create clips?

Each clip is a new asset and is considered an on-demand video. On-Demand video pricing applies and that includes Encoding, Storage, and Delivery usage.

Can I use baseline encoding on clips?

At this time, only smart encoding can be applied to clips. If you want to use baseline encoding, you can create a new asset from the source asset and apply the baseline encoding to the new asset.

Can I create clips when adding new video files?

Mux only allows creating clips from existing videos in your account. That means, clipping specific parameters (start_time and end_time) added to Asset CreationAPI are only applicable for input.url with mux://assets/{asset_id} format.

Can I create clips from live streams?

Yes! Mux supports creating clips from the active asset being generated by a live stream while broadcasting. If you clip an asset while the broadcast is active, just remember that the active asset is still growing, so if you don't provide end_time, it will default to the end of the asset at the time of creation. As such, when clipping an active asset during the broadcast, for best results you should always provide an end_time.

My source asset has subtitles/captions text tracks. Will the clip have them?

Mux copies all the text tracks from the source asset to the new asset created for the clip. Mux also trims the text tracks to match the clip's start and end markers.

What other data is copied from the source asset?

Mux copies the captions and watermark image from the source asset to the clips created. If your source asset does not have a watermark image and you want your clipped asset to have a watermark, pass it through in overlay_settings. See more details in the watermark guide.

All other fields, such as passthrough, are not copied over.

What is the minimum duration for a clip?

Clips must have a duration of at least 500 milliseconds.

Was this page helpful?