大网数据广告活动
Web 标准与前端开发

MediaRecorder: mimeType property

· 52CE 我爱测

The **`mimeType`** read-only property of the MediaRecorder interface returns the MIME media type that was specified when creating the MediaRecorder object, or, if none was specified, which was chosen by the browser. This is the file format of the file that would result from writi

MediaStream Recording

The mimeType read-only property of the MediaRecorder interface returns the MIME media type that was specified when creating the MediaRecorder object, or, if none was specified, which was chosen by the browser. This is the file format of the file that would result from writing all of the recorded data to disk.

Keep in mind that not all codecs are supported by a given container; if you write media using a codec that is not supported by a given media container, the resulting file may not work reliably if at all when you try to play it back. See our media type and format guide for information about container and codec support across browsers.

[!NOTE] The term "MIME type" is officially considered to be historical; these strings are now officially known as media types. MDN Web Docs content uses the terms interchangeably.

Value

The MIME media type which describes the format of the recorded media, as a string. This string may include the codecs parameter, giving details about the codecs and the codec configurations used by the media recorder.

The media type strings are standardized by the Internet Assigned Numbers Authority (IANA). For their official list of defined media type strings, see the article Media Types on the IANA site. See also media types to learn more about media types and how they're used in web content and by web browsers.

Examples

if (navigator.mediaDevices) {
  console.log("getUserMedia supported.");

  const constraints = { audio: true, video: true };
  const chunks = [];

  navigator.mediaDevices
    .getUserMedia(constraints)
    .then((stream) => {
      const options = {
        audioBitsPerSecond: 128000,
        videoBitsPerSecond: 2500000,
        mimeType: "video/mp4",
      };
      const mediaRecorder = new MediaRecorder(stream, options);
      m = mediaRecorder;

      m.mimeType; // would return 'video/mp4'
      // …
    })
    .catch((error) => {
      console.error(error.message);
    });
}

Changing the mimeType in options to 'video/mp4; codecs="avc1.424028, mp4a.40.2"' causes MediaRecorder to try to use AVC Constrained Baseline Profile Level 4 for video and AAC-LC (Low Complexity) for audio, which is good for mobile and other possible resource-constrained situations.

Assuming this configuration is acceptable to the user agent, the value returned later by m.mimeType would then be video/mp4; codecs="avc1.424028, mp4a.40.2".

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。