From f40276ece98f0b211a78552b2f1fd963196c4057 Mon Sep 17 00:00:00 2001 From: mdn-bot <108879845+mdn-bot@users.noreply.github.com> Date: Mon, 2 Dec 2024 01:31:34 +0000 Subject: [PATCH 1/4] zh-cn: sync translated content --- files/zh-cn/_redirects.txt | 1 + files/zh-cn/_wikihistory.json | 8 ++++---- .../formats}/configuring_servers_for_ogg_media/index.md | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) rename files/zh-cn/web/{http => media/formats}/configuring_servers_for_ogg_media/index.md (98%) diff --git a/files/zh-cn/_redirects.txt b/files/zh-cn/_redirects.txt index 55d2e3205f96a3..bc33308fb4cfac 100644 --- a/files/zh-cn/_redirects.txt +++ b/files/zh-cn/_redirects.txt @@ -2442,6 +2442,7 @@ /zh-CN/docs/Web/HTTP/Basics_of_HTTP/选择_www_或非_www_URL_作为域名 /zh-CN/docs/Web/URI/Authority/Choosing_between_www_and_non-www_URLs /zh-CN/docs/Web/HTTP/CORS/Errors/CORS错误允许凭证 /zh-CN/docs/Web/HTTP/CORS/Errors/CORSMIssingAllowCredentials /zh-CN/docs/Web/HTTP/Caching_FAQ /zh-CN/docs/Web/HTTP/Caching +/zh-CN/docs/Web/HTTP/Configuring_servers_for_Ogg_media /zh-CN/docs/Web/Media/Formats/Configuring_servers_for_Ogg_media /zh-CN/docs/Web/HTTP/Content_negotiation/Accept_默认值 /zh-CN/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values /zh-CN/docs/Web/HTTP/Feature_Policy /zh-CN/docs/Web/HTTP/Permissions_Policy /zh-CN/docs/Web/HTTP/HTTP_Strict_Transport_Security /zh-CN/docs/Web/HTTP/Headers/Strict-Transport-Security diff --git a/files/zh-cn/_wikihistory.json b/files/zh-cn/_wikihistory.json index bd49aacc0df3f3..719d3c7e18a576 100644 --- a/files/zh-cn/_wikihistory.json +++ b/files/zh-cn/_wikihistory.json @@ -22544,10 +22544,6 @@ "modified": "2019-09-19T06:11:16.911Z", "contributors": ["leah_humlelu", "Trendymen", "xianweics", "WayneCui"] }, - "Web/HTTP/Configuring_servers_for_Ogg_media": { - "modified": "2019-12-27T03:08:09.838Z", - "contributors": ["Syaki"] - }, "Web/HTTP/Connection_management_in_HTTP_1.x": { "modified": "2019-11-07T04:16:26.733Z", "contributors": [ @@ -31168,6 +31164,10 @@ "modified": "2019-10-28T06:26:59.997Z", "contributors": ["jswisher"] }, + "Web/Media/Formats/Configuring_servers_for_Ogg_media": { + "modified": "2019-12-27T03:08:09.838Z", + "contributors": ["Syaki"] + }, "Web/Media/Formats/Image_types": { "modified": "2020-10-28T06:58:07.754Z", "contributors": ["hylashyla", "RainSlide"] diff --git a/files/zh-cn/web/http/configuring_servers_for_ogg_media/index.md b/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md similarity index 98% rename from files/zh-cn/web/http/configuring_servers_for_ogg_media/index.md rename to files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md index 6d449f3938e65c..e3a0065647009d 100644 --- a/files/zh-cn/web/http/configuring_servers_for_ogg_media/index.md +++ b/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md @@ -1,6 +1,7 @@ --- title: Configuring servers for Ogg media -slug: Web/HTTP/Configuring_servers_for_Ogg_media +slug: Web/Media/Formats/Configuring_servers_for_Ogg_media +original_slug: Web/HTTP/Configuring_servers_for_Ogg_media --- {{HTTPSidebar}} From 9c9dac11dabbceae773aa23817db16dafe9a7c64 Mon Sep 17 00:00:00 2001 From: Jason Ren <40999116+jasonren0403@users.noreply.github.com> Date: Mon, 2 Dec 2024 01:44:13 +0000 Subject: [PATCH 2/4] related content updates --- files/zh-cn/web/html/element/video/index.md | 2 +- .../index.md | 41 ++++--------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/files/zh-cn/web/html/element/video/index.md b/files/zh-cn/web/html/element/video/index.md index db6bf80bcbb1e8..4bfe8020d536dc 100644 --- a/files/zh-cn/web/html/element/video/index.md +++ b/files/zh-cn/web/html/element/video/index.md @@ -531,4 +531,4 @@ AddType video/webm .webm - {{htmlelement("audio")}} - [使用 HTML 音频和视频](/zh-CN/docs/Learn/HTML/Multimedia_and_embedding/Video_and_audio_content) - [使用 canvas 处理视频](/zh-CN/docs/Web/API/Canvas_API/Manipulating_video_using_canvas) -- [Ogg 格式媒体文件的服务器配置](/zh-CN/docs/Web/HTTP/Configuring_servers_for_Ogg_media) +- [Ogg 格式媒体文件的服务器配置](/zh-CN/docs/Web/Media/Formats/Configuring_servers_for_Ogg_media) diff --git a/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md b/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md index e3a0065647009d..6e910d6f7698e0 100644 --- a/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md +++ b/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md @@ -1,16 +1,15 @@ --- -title: Configuring servers for Ogg media +title: 为 Ogg 媒体配置服务器 slug: Web/Media/Formats/Configuring_servers_for_Ogg_media -original_slug: Web/HTTP/Configuring_servers_for_Ogg_media --- -{{HTTPSidebar}} +{{QuickLinksWithSubpages("/zh-CN/docs/Web/Media")}} HTML {{HTMLElement("audio")}} 和 {{HTMLElement("video")}} 标签无需用户安装任何插件或软件即可播放媒体文件。本指南包括了一些服务器配置修改,这些修改对于 web 服务器提供 Ogg 媒体文件是必要的。这些信息在遇到服务器未配置为可识别的其他媒体类型文件时也可能提供帮助。 ## 为媒体提供正确的 MIME 类型 -`*.ogg` 和 `*.ogv` 文件包含了视频 (也可能带有音频),应该和 `video/ogg` MIME 类型一起提供。 `*.oga` 和 `*.ogg` 只含音频的文件应该与 `audio/ogg` MIME 类型一起提供。 +`*.ogg` 和 `*.ogv` 文件包含了视频(也可能带有音频),应该和 `video/ogg` MIME 类型一起提供。 `*.oga` 和 `*.ogg` 只含音频的文件应该与 `audio/ogg` MIME 类型一起提供。 如果不确定 Ogg 文件是否包含音频或视频,可以和 MIME 类型 `application/ogg`一起提供,浏览器会将其视为视频文件。 @@ -18,15 +17,15 @@ HTML {{HTMLElement("audio")}} 和 {{HTMLElement("video")}} 标签无需用户安 对于 Apache,可添加如下配置: -```plain +```apacheconf AddType audio/ogg .oga AddType video/ogg .ogv AddType application/ogg .ogg ``` -你可以在 [guide to media types and formats on the web](/zh-CN/docs/Web/Media/Formats) 找到有关可能的媒体文件类型以及其中使用的编解码器的特定信息。特别是,关于配置媒体服务器正确托管媒体 [media container formats](/zh-CN/docs/Web/Media/Formats/Containers) 特别有用。 +在配置服务器以正确托管媒体时,[媒体容器格式](/zh-CN/docs/Web/Media/Formats/Containers)这篇文章尤其有帮助。 -## Handle HTTP 1.1 byte range requests correctly +## Handle range requests correctly In order to support seeking and playing back regions of the media that aren't yet downloaded, Gecko uses HTTP 1.1 byte-range requests to retrieve the media from the seek target position. In addition, Gecko uses byte-range requests to seek to the end of the media (assuming you serve the {{HTTPHeader("Content-Length")}} header) in order to determine the duration of the media. @@ -49,28 +48,7 @@ The HTML {{HTMLElement("audio")}} and {{HTMLElement("video")}} elements provide `preload` is off by default, so if getting to video is the point of your web page, your users may appreciate it if you include `preload` in your video elements. using `preload="metadata"` will preload the media file's metadata and possibly the first few frames of video. Setting `payload` to `auto` tells the browser to automatically begin downloading the media as soon as the page is loaded, under the assumption that the user will play it. -## Configuration for older Firefox versions - -### Serve X-Content-Duration headers - -> [!NOTE] -> As of [Firefox 41](/zh-CN/Firefox/Releases/41), the `X-Content-Duration` header is no longer supported. See [Firefox bug 1160695](https://bugzil.la/1160695) for more details. - -The Ogg format doesn't encapsulate the duration of media, so for the progress bar on the video controls to display the duration of the video, Gecko needs to determine the length of the media using other means. - -There are two ways Gecko can do this. The best way is to offer an `X-Content-Duration` header when serving Ogg media files. This header provides the duration of the video in seconds (**not** in HH:MM:SS format) as a floating-point value. - -For example, if the video is 1 minute and 32.6 seconds long, this header would be: - -```plain -X-Content-Duration: 92.6 -``` - -If your server provides the `X-Content-Duration` header when serving Ogg media, Gecko doesn't have to do any extra HTTP requests to seek to the end of the file to calculate its duration. This makes the entire process much more efficient as well as more accurate. - -As an inferior alternative, Gecko can estimate the video length based on the Content-Length. See next point. - -### Don't use HTTP compression for media files +## Don't use HTTP compression for Ogg media One common way to reduce the load on a web server is to use [gzip or deflate compression](http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/) when serving to a supporting web browser. @@ -78,11 +56,11 @@ Although it's unlikely, it's possible the browser may advertise that it supports Another probelm with allowing HTTP compression for media streaming: Apache servers don't send the {{HTTPHeader("Content-Length")}} response header if gzip encoding is used. -### Getting the duration of Ogg media +## Getting the duration of Ogg media You can use the `oggz-info` tool to get the media duration; this tool is included with the [`oggz-tools`](http://www.xiph.org/oggz/) package. The output from `oggz-info` looks like this: -```plain +```bash $ oggz-info /g/media/bruce_vs_ironman.ogv Content-Duration: 00:01:00.046 @@ -109,6 +87,5 @@ It's important to note that it appears that `oggz-info` makes a read pass of the ## See also -- [Guide to media types and formats on the web](/zh-CN/docs/Web/Media/Formats) - [Video and audio content](/zh-CN/docs/Learn/HTML/Multimedia_and_embedding/Video_and_audio_content) - [The "codecs" parameter in common media types](/zh-CN/docs/Web/Media/Formats/codecs_parameter) From 04d555b235c0c4ef9fa9d9057347071fdbd37901 Mon Sep 17 00:00:00 2001 From: Jason Ren <40999116+jasonren0403@users.noreply.github.com> Date: Mon, 2 Dec 2024 02:13:02 +0000 Subject: [PATCH 3/4] update 'configuring servers for ogg media' --- .../index.md | 88 ++++++++++--------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md b/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md index 6e910d6f7698e0..21af977c9cd1c1 100644 --- a/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md +++ b/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md @@ -1,6 +1,8 @@ --- title: 为 Ogg 媒体配置服务器 slug: Web/Media/Formats/Configuring_servers_for_Ogg_media +l10n: + sourceCommit: 4d12b3e4f9afb311f2656641260e42c0b6f8f4c6 --- {{QuickLinksWithSubpages("/zh-CN/docs/Web/Media")}} @@ -9,9 +11,10 @@ HTML {{HTMLElement("audio")}} 和 {{HTMLElement("video")}} 标签无需用户安 ## 为媒体提供正确的 MIME 类型 -`*.ogg` 和 `*.ogv` 文件包含了视频(也可能带有音频),应该和 `video/ogg` MIME 类型一起提供。 `*.oga` 和 `*.ogg` 只含音频的文件应该与 `audio/ogg` MIME 类型一起提供。 +如果不确定 Ogg 文件是否包含音频或视频,可以使用 MIME 类型 `application/ogg` 提供,浏览器会将其视为视频文件。 -如果不确定 Ogg 文件是否包含音频或视频,可以和 MIME 类型 `application/ogg`一起提供,浏览器会将其视为视频文件。 +- 包含视频轨的 `*.ogg` 和 `*.ogv` 文件(通常也会包含音频轨),应当使用 MIME 类型 `video/ogg`。 +- 只包含音频轨的 `*.oga` 和 `*.ogg` 文件应当使用 MIME 类型 `audio/ogg`。 默认情况下,大多数服务器不为 Ogg 媒体提供正确的 MIME 类型,因此可能需要为此添加适当的配置。 @@ -25,67 +28,68 @@ AddType application/ogg .ogg 在配置服务器以正确托管媒体时,[媒体容器格式](/zh-CN/docs/Web/Media/Formats/Containers)这篇文章尤其有帮助。 -## Handle range requests correctly +## 正确处理范围请求 -In order to support seeking and playing back regions of the media that aren't yet downloaded, Gecko uses HTTP 1.1 byte-range requests to retrieve the media from the seek target position. In addition, Gecko uses byte-range requests to seek to the end of the media (assuming you serve the {{HTTPHeader("Content-Length")}} header) in order to determine the duration of the media. +为了支持搜索和播放尚未下载的媒体区域,你可以使用[范围请求](/zh-CN/docs/Web/HTTP/Range_requests)从搜索目标位置检索媒体。此外,它还会使用字节范围请求寻址到媒体的末尾(假设提供了 {{HTTPHeader("Content-Length")}} 标头),以确定媒体的时长。 -Your server should accept the {{HTTPHeader("Accept-Ranges")}}`: bytes` HTTP header if it can accept byte-range requests. It must return {{HTTPStatus("206")}}`: Partial content` to all byte range requests; otherwise, browsers can't be sure you actually support byte range requests. +如果服务器可以接受范围请求,则应接受 {{HTTPHeader("Accept-Ranges")}} 标头。它必须向所有范围请求返回 {{HTTPStatus("206", "206 Partial Content")}},否则浏览器无法判断服务器是否支持范围请求。服务器也必须为请求 `Range: bytes=0-` 返回 `206: Partial Content`。 -Your server must also return `206: Partial Content` for the request `Range: bytes=0-` as well. +参见[范围请求](/zh-CN/docs/Web/HTTP/Range_requests)以了解更多信息。 -## Include regular key frames +## 包含常规关键帧 -When the browser seeks through Ogg media to a specified time, it has to seek to the nearest key frame before the seek target, then download and decode the video from there until the requested target time. The farther apart your key frames are, the longer this takes, so it's helpful to include key frames at regular intervals. +当浏览器搜索 Ogg 媒体到指定时间时,它必须搜索到目标前最近的关键帧,然后从那里下载并解码视频,直到要求的目标时间。关键帧之间的距离越远,所需的时间就越长,因此在固定的时间间隔内加入关键帧会很有帮助。 -By default, [`ffmpeg2theora`](http://v2v.cc/~j/ffmpeg2theora/) uses one key frame every 64 frames (or about every 2 seconds at 30 frames per second), which works pretty well. +默认情况下,[`ffmpeg2theora`](https://gitlab.xiph.org/xiph/ffmpeg2theora) 每 64 帧(或以每秒 30 帧计算,约每 2 秒)使用一个关键帧,效果相当不错。 > [!NOTE] -> Of course, the more key frames you use, the larger your video file is, so you may need to experiment a bit to get the right balance between file size and seek performance. +> 当然,使用的关键帧越多,视频文件就越大,因此您可能需要进行一些试验,才能在文件大小和搜索性能之间取得适当的平衡。 -## Consider using the preload attribute +## 考虑使用 preload 属性 -The HTML {{HTMLElement("audio")}} and {{HTMLElement("video")}} elements provide the `preload` attribute, which tells the browser to attempt to download the entire media when the page loads. Without `preload`, the browser only downloads enough of the media to display the first video frame, and to determine the media's duration. +HTML {{HTMLElement("audio")}} 和 {{HTMLElement("video")}} 元素提供了 `preload` 属性,它告诉浏览器在页面加载时尝试下载整个媒体。如果没有 `preload` 属性,浏览器将下载足够显示第一个视频帧的媒体,并确定媒体的时长。 -`preload` is off by default, so if getting to video is the point of your web page, your users may appreciate it if you include `preload` in your video elements. using `preload="metadata"` will preload the media file's metadata and possibly the first few frames of video. Setting `payload` to `auto` tells the browser to automatically begin downloading the media as soon as the page is loaded, under the assumption that the user will play it. +- 默认情况下,`preload` 是关闭的,因此如果进入视频是网页的重点,在视频元素中加入 `preload` 可能会更受用户喜爱。 +- 使用 `preload="metadata"` 会预载媒体文件的元数据,可能还会预载视频的前几帧。将 `payload` 设置为 `auto`,浏览器就会在页面加载完成后自动开始下载媒体文件,前提是用户会播放该文件。 -## Don't use HTTP compression for Ogg media +## 不要对 Ogg 媒体使用 HTTP 压缩 -One common way to reduce the load on a web server is to use [gzip or deflate compression](http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/) when serving to a supporting web browser. +减少 web 服务器负载的一个常用方法是在向支持的 web 浏览器提供服务时使用 [gzip 或 deflate 压缩](https://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/)。 -Although it's unlikely, it's possible the browser may advertise that it supports HTTP compression (gzip/deflate) using the `Accept-Encoding: gzip,deflate` header when requesting media files. Your server should be configured to not do so. The data in media files is already compressed, so you won't get any real benefit from compression, and the use of compression makes it impossible for the browser to properly seek the video or determine its duration. +虽然可能性不大,但浏览器可能会在请求媒体文件时使用 `Accept-Encoding: gzip,deflate` 标头宣称其支持 HTTP 压缩(gzip/deflate)。服务器不应该配置如此;媒体文件中的数据已被压缩,因此你不会从压缩中获得任何真正的好处,而且使用压缩会使浏览器无法正确搜索视频或确定其持续时间。 -Another probelm with allowing HTTP compression for media streaming: Apache servers don't send the {{HTTPHeader("Content-Length")}} response header if gzip encoding is used. +允许对媒体流进行 HTTP 压缩的另一个问题:如果使用 gzip 编码,Apache 服务器不会发送 {{HTTPHeader("Content-Length")}} 响应标头。 -## Getting the duration of Ogg media +## 获取 Ogg 媒体的时长 -You can use the `oggz-info` tool to get the media duration; this tool is included with the [`oggz-tools`](http://www.xiph.org/oggz/) package. The output from `oggz-info` looks like this: +你可以使用 `oggz-info` 工具来获取媒体时长;这个工具包含在 [`oggz-tools`](https://www.xiph.org/oggz/) 软件包中。`oggz-info` 的输出如下: ```bash - $ oggz-info /g/media/bruce_vs_ironman.ogv - Content-Duration: 00:01:00.046 - - Skeleton: serialno 1976223438 - 4 packets in 3 pages, 1.3 packets/page, 27.508% Ogg overhead - Presentation-Time: 0.000 - Basetime: 0.000 - - Theora: serialno 0170995062 - 1790 packets in 1068 pages, 1.7 packets/page, 1.049% Ogg overhead - Video-Framerate: 29.983 fps - Video-Width: 640 - Video-Height: 360 - - Vorbis: serialno 0708996688 - 4531 packets in 167 pages, 27.1 packets/page, 1.408% Ogg overhead - Audio-Samplerate: 44100 Hz - Audio-Channels: 2 +$ oggz-info /g/media/bruce_vs_ironman.ogv +Content-Duration: 00:01:00.046 + +Skeleton: serialno 1976223438 + 4 packets in 3 pages, 1.3 packets/page, 27.508% Ogg overhead + Presentation-Time: 0.000 + Basetime: 0.000 + +Theora: serialno 0170995062 + 1790 packets in 1068 pages, 1.7 packets/page, 1.049% Ogg overhead + Video-Framerate: 29.983 fps + Video-Width: 640 + Video-Height: 360 + +Vorbis: serialno 0708996688 + 4531 packets in 167 pages, 27.1 packets/page, 1.408% Ogg overhead + Audio-Samplerate: 44100 Hz + Audio-Channels: 2 ``` -Note that you can't simply serve up the reported Content-Duration line reported by `oggz-info`, because it's reported in HH:MM:SS format. You'll need to convert it to seconds only, then serve that as your `X-Content-Duration` value. Just parse out the HH, MM, and SS into numbers, then do (HH\*3600)+(MM\*60)+SS to get the value you should report. +请注意,你不能直接使用由 `oggz-info` 报告的 Content-Duration 行,因为它是以 `HH:MM:SS` 格式报告的。需要将其转换为秒,然后将其作为 `X-Content-Duration` 值提供。为此,可以解析 `HH`、`MM` 和 `SS` 段,然后转换为 `(HH * 3600) + (MM * 60) + SS` 作为应该报告的值。 -It's important to note that it appears that `oggz-info` makes a read pass of the media in order to calculate its duration, so it's a good idea to store the duration value in order to avoid lengthy delays while the value is calculated for every HTTP request of your Ogg media. +值得注意的是,`oggz-info` 似乎会对媒体进行一次读取以计算其时长,因此存储时长是个好主意,这样可以避免在每次对 Ogg 媒体进行 HTTP 请求时都要计算时长而造成长时间的延迟。 -## See also +## 参见 -- [Video and audio content](/zh-CN/docs/Learn/HTML/Multimedia_and_embedding/Video_and_audio_content) -- [The "codecs" parameter in common media types](/zh-CN/docs/Web/Media/Formats/codecs_parameter) +- [视频和音频内容](/zh-CN/docs/Learn/HTML/Multimedia_and_embedding/Video_and_audio_content) +- [常用媒体类型的编解码器](/zh-CN/docs/Web/Media/Formats/codecs_parameter) From 3201c867236b1e4a0790b2f58195dbe78153ca71 Mon Sep 17 00:00:00 2001 From: Jason Ren <40999116+jasonren0403@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:15:59 +0800 Subject: [PATCH 4/4] Apply suggestions from code review --- .../media/formats/configuring_servers_for_ogg_media/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md b/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md index 21af977c9cd1c1..c3b414b0817712 100644 --- a/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md +++ b/files/zh-cn/web/media/formats/configuring_servers_for_ogg_media/index.md @@ -43,7 +43,7 @@ AddType application/ogg .ogg 默认情况下,[`ffmpeg2theora`](https://gitlab.xiph.org/xiph/ffmpeg2theora) 每 64 帧(或以每秒 30 帧计算,约每 2 秒)使用一个关键帧,效果相当不错。 > [!NOTE] -> 当然,使用的关键帧越多,视频文件就越大,因此您可能需要进行一些试验,才能在文件大小和搜索性能之间取得适当的平衡。 +> 当然,使用的关键帧越多,视频文件就越大,因此可能需要进行一些试验,才能在文件大小和搜索性能之间取得适当的平衡。 ## 考虑使用 preload 属性