Mux

The Mux Developer Hub

Welcome to the Mux developer hub. You'll find comprehensive guides and documentation to help you start working with Mux as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started

MP4 Support

Adding support for the MP4 video format to an asset.

MP4 Support refers to the ability of a Mux asset to be streamed or downloaded using the MPEG-4 (.mp4) video format. There are a handful of reasons why you might want to add MP4 support to a Mux video asset.

  • Allowing users to download a file for watching offline
  • Embedding a video in Open Graph cards for sharing on sites like Facebook and Twitter
  • Supporting very old devices, like Android < v4.0 (Less than 1% of Android users)

For these reasons we've added the option for MP4 support on Assets. In all other cases you'll want to use our default HLS (.m3u8) format which provides a better viewing experience by dynamically adjusting the quality level to the viewer's connection speed. The HLS version of a video will also be ready sooner than the MP4 versions, if time to ready is important.

There's no additional cost for creating and storing MP4 files (woo!). Delivery is the same price-per-minute of video as HLS delivery.

You can add MP4 support to an asset at Asset Creation time by including the "mp4_support": "standard" parameter.

{
  "input": "VIDEO_URL",
  "playback_policy": "public",
  "mp4_support": "standard"
}

You can also add it afterwards by updating the asset.

After adding MP4 support you'll see an additional key on the asset object: static_renditions. This is the object that will contain the information about which MP4s are available.

The static_renditions.status parameter refers to the current status of processing the MP4s. MP4s take longer to create than our default HLS version of the video, so they will not be ready immediately when the asset status is ready. Instead they will be ready when the static_renditions.status is ready, and a webhook of video.asset.static_renditions.ready is fired.

{
  ...all asset details...
  "mp4_support": "standard",
  "static_renditions": {
    "status": "preparing"
  }
}

When the static_renditions.status field is ready you will see the details of the MP4s available in an array under the files key.

Depending on the source video uploaded, you will have one or more options for MP4 renditions. If the source video had a low resolution (e.g. 240p) there will only be a low.mp4 file available. If the source video had a high resolution (HD, 720p+) you will have three options: low.mp4, medium.mp4, and high.mp4.

{
  ...all asset details...
  "mp4_support": "standard",
  "static_renditions": {
    "status": "ready",
    "files": [
      {
        "name": "low.mp4",
        "ext": "mp4",
        "height": {MP4_HEIGHT},
        "width":  {MP4_WIDTH},
        "bitrate":  {MP4_BITRATE},
        "filesize":  {MP4_FILESIZE}
      }
    ]
  }
}

To stream the MP4 file, use a stream.mux.com URL with the asset playback ID, then a slash, then the name of the MP4 you want to stream:

https://stream.mux.com/{PLAYBACK_ID}/{MP4_FILE_NAME}
--
ex. https://stream.mux.com/abcd1234/low.mp4

If you want browser to download the MP4 file rather than attempt to stream it, you can provide a file name for the MP4 to save as via the download query parameter:

https://stream.mux.com/{PLAYBACK_ID}/{MP4_FILE_NAME}?download={FILE_NAME}
--
ex. https://stream.mux.com/abcd1234/low.mp4?download=cats

This will return a response header of
    => Content-Disposition: attachment; filename="cats.mp4"

Technical Note for very large MP4 files (5GB+) we may include a 302 redirect from the file URL to a new location. For most use cases this won't be an issue, but Android MediaPlayer (the Android player prior to ExoPlayer) in older versions of Android may fail to follow the redirect. Get in touch if you're running into this issue.

Let us know if you have any questions or comments on this feature!

📘

Audio Only MP4 support

If you're using audio only assets with MP4 support, you'll need to craft the end of your URL as audio.m4a.

Updated about a month ago

MP4 Support


Adding support for the MP4 video format to an asset.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.