Upload and play back your video files in your application using Mux in five minutes or less.
The Mux Video API uses a token key pair that consists of a Token ID and Token Secret for authentication. If you haven't already, generate a new Access Token in the Access Token settings of your Mux account dashboard.
You'll be presented with a form to create your new Access Token.
Now, click the Generate token button.
You'll be presented with your new Access Token ID and Secret Key.
Once you have your new Access Token ID and Secret Key, you're ready to upload your first video.
Videos stored in Mux are called assetsAPI. To create your first video asset, you need to send a POST request to the /assets endpointAPI and set the input
value to the URL of a video file that's accessible online.
Here are a few demo videos you can use that are stored on common cloud storage services:
To start making API requests to Mux, you might want to install one of our officially supported API SDKs. These are lightweight wrapper libraries that use your API credentials to make authenticated HTTP requests to the Mux API.
# mix.exs
def deps do
[
{:mux, "~> 1.8.0"}
]
end
For an example of how to make API Requests from your local environment, see the Make API Requests guide.
curl https://api.mux.com/video/v1/assets \
-H "Content-Type: application/json" \
-X POST \
-d '{ "input": "{INPUT_URL}", "playback_policy": "public", "video_quality": "basic" }' \
-u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}
The response will include an Asset ID and a Playback ID.
api.mux.com
(e.g. to read or delete an asset).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.{
"data": {
"status": "preparing",
"playback_ids": [
{
"policy": "public",
"id": "TXjw00EgPBPS6acv7gBUEJ14PEr5XNWOe"
}
],
"video_quality": "basic",
"mp4_support": "none",
"master_access": "none",
"id": "01itgOBvgjAbES7Inwvu4kEBtsQ44HFL6",
"created_at": "1607876845"
}
}
Mux does not store the original file in its exact form, so if your original quality files are important to you, don't delete them after submitting them to Mux.
ready
As soon as you make the POST
request, Mux begins downloading and processing the video. For shorter files, this often takes just a few seconds. Very large files over poor connections may take a few minutes (or longer).
When the video is ready for playback, the asset status
changes to ready
. You should wait until the asset status is ready
before you attempt to play the video.
The best way to be notified of asset status updates 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:
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.
To play back an asset, create a playback URL using the PLAYBACK_ID
you received when you created the asset.
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.
stream.new
Stream.new is an open source project by Mux that allows you to add a video and get a shareable link to stream it.
Go to stream.new/v/{PLAYBACK_ID}
to preview your video streaming. This URL is shareable and automatically generated using the video playback ID. Copy the link below and open it in a browser to view your video.
https://stream.new/v/{PLAYBACK_ID}
After you have everything working integrate Mux Data with your player for monitoring playback performance.
After you have assets created in your Mux environment, you may find some of these other endpoints handy:
More Video methods and descriptions are available at the API DocsAPI.