Skip to Content
Mux Docs: Home
Welcome to the new Mux Docs.
The old version is still available here

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 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.

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?