Installations
npm install sanity-plugin-mux-input
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Min. Node Version
>=18
Node Version
22.13.1
NPM Version
10.9.0
Releases
Contributors
Languages
TypeScript (97.44%)
CSS (1.81%)
JavaScript (0.75%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
1,031,491
Last Day
2,010
Last Week
12,293
Last Month
54,804
Last Year
480,377
GitHub Statistics
MIT License
63 Stars
515 Commits
63 Forks
26 Watchers
19 Branches
50 Contributors
Updated on Feb 06, 2025
Bundle Size
1.64 MB
Minified
457.01 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.5.0
Package Id
sanity-plugin-mux-input@2.5.0
Unpacked Size
1.20 MB
Size
293.98 kB
File Count
104
NPM Version
10.9.0
Node Version
22.13.1
Published on
Feb 06, 2025
Total Downloads
Cumulative downloads
Total Downloads
1,031,491
Last Day
-26.8%
2,010
Compared to previous day
Last Week
-5.7%
12,293
Compared to previous week
Last Month
47.2%
54,804
Compared to previous month
Last Year
123.9%
480,377
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
16
Peer Dependencies
4
Dev Dependencies
30
Mux Video Input Sanity Plugin
This is a Sanity Studio v3 plugin. For the v2 version, please refer to the v2-branch.
This plugin lets you use Mux video assets in your Sanity studio.
The Mux plugin for Sanity allows you to easily upload and preview videos.
Read our blog post about this plugin.
Not familiar with Sanity? Visit www.sanity.io
Installation
npm install sanity-plugin-mux-input
or
yarn add sanity-plugin-mux-input
Quick start
- While in your project folder, run
npm i sanity-plugin-mux-input
. Read more about using plugins in Sanity here.
-
Make a schema type that uses the plugin's type
mux.video
, for example:1export default { 2 title: 'Video blog post', 3 name: 'videoBlogPost', 4 type: 'document', 5 fields: [ 6 {title: 'Title', name: 'title', type: 'string'}, 7 { 8 title: 'Video file', 9 name: 'video', 10 type: 'mux.video', 11 }, 12 ], 13}
- Add the
muxInput
import to your plugins:
1import {defineConfig} from 'sanity' 2import {muxInput} from 'sanity-plugin-mux-input' 3 4export default defineConfig({ 5 plugins: [muxInput()], 6})
- Add the
Read more about schemas in Sanity here.
- Get an API Access Token and enter it into the setup screen First time you use the plugin you will be asked to enter your Mux credentials.
The Mux Video API uses an Access Token and Secret Key for authentication.
If you haven't already, generate a new Access Token in the Access Token settings of your Mux account dashboard, and make sure it got permission to both read and write video and read data.
The token is stored in the dataset as a document of the type mux.apiKey
with the id secrets.mux
.
Having the ID be non-root ensures that only editors are able to see it.
The Mux plugin will find its access tokens by fetching this document.
Fetching playback IDs and understanding the data structure
When a Mux video is uploaded/chosen in a document via this plugin, it gets stored as a reference to the video document:
1// example document 2{ 3 _type: 'exampleSchemaWithVideo', 4 // Example video field 5 myVideoField: { 6 _type: 'mux.video', 7 asset: { 8 _type: 'reference', 9 _weak: true, 10 _ref: '4e37284e-cec2-406d-973c-fdf9ab1e5598', // 👈 ID of the document holding the video's Mux data 11 }, 12 }, 13}
Before you can display videos in your frontend, you need to follow these references to fetch the asset's playback ID, which will be used to create a player. Here's an example GROQ query to expand the video reference in the example data above:
1// Example for fetching data above 2*[ _type == "exampleSchemaWithVideo" ] { 3 myVideoField { 4 asset-> { 5 playbackId, 6 assetId, 7 filename, 8 } 9 } 10}
💡 For more information on querying references, refer to the documentation on Writing GROQ queries for references or on Sanity's GraphQL API.
For reference, here's an example mux.videoAsset
document:
1{ 2 _id: '4e37284e-cec2-406d-973c-fdf9ab1e5598', 3 _type: 'mux.videoAsset', 4 assetId: '7ovyI76F92n02H00mWP7lOCZMIU00N4iysDiQDNppX026HY', 5 filename: 'mux-example-video.mp4', 6 status: 'ready', 7 playbackId: 'YA02HBpY02fKWHDRMNilo301pdH02LY3k9HTcK43ItGJLWA', 8 thumbTime: 65.82, 9 // Full Mux asset data: 10 data: { 11 encoding_tier: 'smart', 12 max_resolution_tier: '1080p', 13 aspect_ratio: '16:9', 14 created_at: '1706645034', 15 duration: 25.492133, 16 status: 'ready', 17 master_access: 'none', 18 max_stored_frame_rate: 29.97, 19 playback_ids: [ 20 { 21 id: 'YA02HBpY02fKWHDRMNilo301pdH02LY3k9HTcK43ItGJLWA', 22 policy: 'signed', 23 }, 24 ], 25 resolution_tier: '1080p', 26 ingest_type: 'on_demand_url', 27 max_stored_resolution: 'HD', 28 tracks: [ 29 { 30 max_channel_layout: 'stereo', 31 max_channels: 2, 32 id: '00MKMC73SYimw1YTh0102lPJJp9w2R5rHddpNX1N9opAMk', 33 type: 'audio', 34 primary: true, 35 duration: 25.45, 36 }, 37 { 38 max_frame_rate: 29.97, 39 max_height: 1080, 40 id: 'g1wEph3CVvbJL01YNKzAWMyH8N1SxW00WeECGjqwEHW9g', 41 type: 'video', 42 duration: 25.4254, 43 max_width: 1920, 44 }, 45 ], 46 id: '7ovyI76F92n02H00mWP7lOCZMIU00N4iysDiQDNppX026HY', 47 mp4_support: 'none', 48 }, 49}
Playing videos in the frontend
We recommend using Mux Player to properly display your videos, through packages like @mux/mux-player
and @mux/mux-player-react
. Here's an example of how you can use the Mux Player to display a video in a React component:
1'use client' 2 3import MuxPlayer from '@mux/mux-player-react' 4 5export default function MuxVideo({playbackId, title}: {playbackId?: string; title?: string}) { 6 if (!playbackId) return null 7 8 return <MuxPlayer playbackId={playbackId} metadata={title ? {video_title: title} : undefined} /> 9}
💡 You can try these recommendations through the Codesandbox example.
Configuring Mux Video uploads
Signed URLs (private playbacks)
To enable signed URLs with content uploaded to Mux, you will need to check the "Enable Signed Urls" option in the Mux Plugin configuration. This feature requires you to set the API Access Token and Secret Key (as per the Quick start section).
📌 Note: When the signed URL option is triggered, the plugin will cache a signingKeyPrivate
in a private document in the dataset. This key is used by Mux to sign the uploads, and if it's incorrect your uploads will fail. If that's the case, you can delete the secrets document and try again:
1# Using the Sanity CLI, delete the secrets, then re-open the plugin and configure it again 2sanity documents delete secrets.mux
More information on signed URLs is available on Mux's docs
MP4 support (downloadable videos or offline viewing)
To enable static MP4 renditions, add mp4_support: 'standard'
to the options
of your mux.video
schema type.
1import {muxInput} from 'sanity-plugin-mux-input' 2 3export default defineConfig({ 4 plugins: [muxInput({mp4_support: 'standard'})], 5})
If MP4 support is enabled in the plugin's configuration, editors can still choose to enable MP4 renditions on a per-video basis when uploading new assets.
MP4 allows users to download videos for later or offline viewing. More information can be found on Mux's documentation.
Video resolution (max_resolution_tier)
To edit max_resolution_tier to support other resolutions other than 1080p, add max_resolution_tier: '1080p' | '1440p' | '2160p'
to the options
of your mux.video
schema type. Defaults to 1080p
.
1import {muxInput} from 'sanity-plugin-mux-input' 2 3export default defineConfig({ 4 plugins: [muxInput({max_resolution_tier: '2160p'})], 5})
When uploading new assets, editors can still choose a lower resolution for each video than configured globally. This option controls the maximum resolution encoded or processed for the uploaded video. The option is particularly important to manage costs when uploaded videos are higher than 1080p
resolution. More information on the feature is available on Mux's docs. Also, read more on this feature announcement on Mux's blog.
Encoding tier (smart or baseline)
The encoding tier informs the cost, quality, and available platform features for the asset. You can choose between smart
and baseline
at the plugin configuration. Defaults to smart
.
1import {muxInput} from 'sanity-plugin-mux-input' 2 3export default defineConfig({ 4 plugins: [muxInput({encoding_tier: 'baseline'})], 5})
If encoding_tier: 'smart'
, editors can still choose to use the baseline
encoding tier on a per-video basis when uploading new assets.
More information on the feature is available on Mux's documentation. Also, read more on the feature announcement on Mux's blog
Auto-generated subtitles and captions
If you've enabled smart encoding, you can use Mux's auto-generated subtitles feature. Unless you pass disableTextTrackConfig: true
to the configuration, users will be able to choose a language to auto-generate subtitles for uploaded videos. Refer to Mux's documentation for the list of supported languages.
You can also define a default language for the upload configuration form:
1import {muxInput} from 'sanity-plugin-mux-input'
2
3export default defineConfig({
4 plugins: [
5 muxInput({
6 encoding_tier: 'smart',
7 defaultAutogeneratedSubtitleLang: 'en', // choose from one of the supported languages
8 }),
9 ],
10})
If your videos are always spoken in a specific language and you want to include captions by default, you can use disableTextTrackConfig: true
together with defaultAutogeneratedSubtitleLang
to transcribe captions for every uploaded asset without needing user interaction.
Contributing
Issues are actively monitored and PRs are welcome. When developing this plugin the easiest setup is:
- Fork this repo.
- Create a studio v3 project:
npm create sanity@dev-preview
. Follow the prompts, starting out with the blog template is a good way to go. cd
into your project directory, runnpm install && npm start
- your sanity studio should be running on http://localhost:3333.cd
into theplugins
directory of your project.- Fork this repo and clone your fork into the
plugins
directory inside your projectgit clone git@github.com:your-fork/sanity-plugin-mux-input.git
. - Open
sanity.json
, go to theplugins
array and addmux-input
. - Re-start the sanity studio server with
npm start
. - Edit
schemas/post.js
and add follow the plugin documentation to add amux.video
type field. - Your studio should reload, and now when you edit the plugin code it should reload the studio, when you're done creating a branch, put in a PR and a maintainer will review it. Thank you!
Publishing
You can run the "CI and Release" workflow. Make sure to select the main branch and check "Release new version".
Semantic release will only release on configured branches, so it is safe to run release on any branch.
On the studio-v2 branch this will result in:
- a new version on the
latest
dist-tag. - running
yarn add sanity-plugin-mux-input
ornpm i sanity-plugin-mux-input
will fetch the new version. - running
sanity install mux-input
will fetch the new version. - studio-v3 users are unaffected.
On the main branch this will result in:
- a new prerelease version on the
studio-v3
dist-tag. - running
yarn add sanity-plugin-mux-input@studio-v3
ornpm i sanity-plugin-mux-input@studio-v3
will fetch the new version. - running
sanity install mux-input
won't fetch the new version.
After Studio v3 turns stable this behavior will change. The v2 version will then be available on the studio-v2
dist-tag, and studio-v3
is upgraded to live on latest
.
Develop & test
You can run the example locally by doing the following:
- run
npm install
andnpm dev
on the root of the repo - In the terminal, a command with
yalc
will be shown, that command will allow you to run the version that you have locally directly on the example or on your own app. - run
npm install
andnpm dev
on the/example
directory where the app with the example exists or in your own app - the studio and app should auto reload with your changes in the plugin package you have locally
Release new version
Run "CI & Release" workflow. Make sure to select the main branch and check "Release new version".
Semantic release will only release on configured branches, so it is safe to run release on any branch.
License
MIT-licensed. See LICENSE.

No vulnerabilities found.
Reason
26 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/sanity-io/.github/SECURITY.md:1
- Info: Found linked content: github.com/sanity-io/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/sanity-io/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/sanity-io/.github/SECURITY.md:1
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/main.yml:96
Reason
4 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-7m27-7ghc-44w9
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/sanity-io/sanity-plugin-mux-input/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/sanity-io/sanity-plugin-mux-input/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:88: update your workflow using https://app.stepsecurity.io/secureworkflow/sanity-io/sanity-plugin-mux-input/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:89: update your workflow using https://app.stepsecurity.io/secureworkflow/sanity-io/sanity-plugin-mux-input/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:108: update your workflow using https://app.stepsecurity.io/secureworkflow/sanity-io/sanity-plugin-mux-input/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:113: update your workflow using https://app.stepsecurity.io/secureworkflow/sanity-io/sanity-plugin-mux-input/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/prettier.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/sanity-io/sanity-plugin-mux-input/prettier.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/prettier.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/sanity-io/sanity-plugin-mux-input/prettier.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:94
- Info: 0 out of 8 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 third-party GitHubAction dependencies pinned
- Info: 3 out of 4 npmCommand dependencies pinned
Reason
Found 5/24 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: topLevel 'contents' permission set to 'read': .github/workflows/main.yml:41
- Warn: no topLevel permission defined: .github/workflows/prettier.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact v2.5.0 not signed: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/198771696
- Warn: release artifact v2.4.1 not signed: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/198536171
- Warn: release artifact v2.4.0 not signed: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/185393029
- Warn: release artifact v2.3.6 not signed: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/160051477
- Warn: release artifact v2.3.5 not signed: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/159231236
- Warn: release artifact v2.5.0 does not have provenance: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/198771696
- Warn: release artifact v2.4.1 does not have provenance: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/198536171
- Warn: release artifact v2.4.0 does not have provenance: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/185393029
- Warn: release artifact v2.3.6 does not have provenance: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/160051477
- Warn: release artifact v2.3.5 does not have provenance: https://api.github.com/repos/sanity-io/sanity-plugin-mux-input/releases/159231236
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Score
5.4
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to sanity-plugin-mux-input
sanity-plugin-mux-input-v2-fixed
An input component that integrates Sanity Studio with Mux video encoding/hosting service.
@webcore-it/sanity-plugin-mux-input
An input component that integrates Sanity Studio with Mux video encoding/hosting service.
@els-studio/sanity-plugin-mux-input
An input component that integrates Sanity Studio with Mux video encoding/hosting service.
sanity-plugin-mux-input-private
An input component that integrates Sanity Studio with MUX.com video encoding/hosting service, uploads all videos as private.