# Mux

<https://stream.mux.com/cGt3J9UVqb0000cguqw01Su00AyufLaqRUdq.m3u8>

Throw video at an endpoint and get a url that will allow a great viewing experience

[Upload Chunks](https://github.com/muxinc/upchunk)

## Bash

1. Get API Token and Secret
2. Send file to Mux

```
curl https://api.mux.com/video/v1/assets \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{ "input": "http://movietrailers.apple.com/movies/wb/the-lego-ninjago-movie/the-lego-ninjago-movie-trailer-2_h720p.mov", "playback_policy": "public" }' \
  -u {MUX_TOKEN_ID}:{MUX_TOKEN_SECRET} | json_pp
```

Response

```
{
   "data" : {
   		//asset id
      "id" : "ymDhKE00YZ12XxJLFo76DIVqCzL15bVf2", 
      "created_at" : "1517531451",
      "playback_ids" : [
         {
            "id" : "EsxKJmzkfLvGV01cbThYHDcEz7TKcbR31",
            "policy" : "public"
         }
      ],
      "status" : "preparing"
   }
}
```

1. Wait for ready with a webhook or polling with asset\_id

```
curl -X GET https://api.mux.com/video/v1/assets/ymDhKE00YZ12XxJLFo76DIVqCzL15bVf2 \
  -u cb3d37fc-1583-4883-94b4-b04577044c54:9aLDt17JBT7pKeeLIE2ox5rkJt0IjfXsNCP/GD+0RMTU+PKlPZD7aCuFJ4DYOgvzBVQ7mCqhkPD | json_pp
```

1. Use the playback\_id you got when creating the asset for the playback url

```
https://stream.mux.com/EsxKJmzkfLvGV01cbThYHDcEz7TKcbR31.m3u8
```

### Create Mp4

1.

```bash
curl https://api.mux.com/video/v1/assets/{ASSET_ID}/mp4-support \
  -H "Content-Type: application/json" \
  -X PUT \
  -d '{ "mp4_support": "standard" }' \
  -u ${MUX_TOKEN_ID}:${MUX_TOKEN_SECRET}
```

Then

```
https://stream.mux.com/EsxKJmzkfLvGV01cbThYHDcEz7TKcbR31/medium.mp4
```

## Languages

#### [Elixir](https://mux.com/for/elixir)

#### Node

waiting => asset\_created

Server

```js
  let upload = await MuxVideo.Uploads.create({
    cors_origin: conf.get("CLIENT_URL"),
    new_asset_settings: { playback_policy: "public" }
  });

//Send upload.url to client
//....

  let updatedUpload;
  while (!updatedUpload || !updatedUpload.asset_id) {
    updatedUpload = await MuxVideo.Uploads.get(upload.id);
    await snooze(500);
  }
  debug("Asset_id:", updatedUpload.asset_id);
  let asset;
  while (!asset || asset.status !== "ready") {
    asset = await MuxVideo.Assets.get(updatedUpload["asset_id"]);
    debug({
      status: asset.status,
      playback_url: `https://stream.mux.com/${asset.playback_ids[0].id}.m3u8`
    });
    await snooze(750);
  }
```

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://openai.gitbook.io/code-cheatsheets/all/apis/mux.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
