Configuration de serveur pour les fichiers média Ogg

Cette traduction est incomplète. Aidez-nous à traduire cet article depuis l’anglais

Les éléments HTML <audio> et <video> permettent de gérer les éléments multimédia sans que l'utilisateur ait besoin d'installer des greffons ou un logiciel. Cet article détaille quelques éléments utiles pour qu'un serveur puisse gérer les fichiers média Ogg correctement.

Servir les fichiers média Ogg à l'aide du type MIME approprié

Les fichiers *.ogg et *.ogv contiennent des vidéos (pouvant inclure une piste audio). Ces fichiers doivent être transmis à l'aide du type MIME video/ogg. Les fichiers *.oga et *.ogg contenant uniquement une piste audio doivent être transmis avec le type MIME audio/ogg.

Si vous ne connaissez pas le contenu exact du fichier Ogg, il est possible de l'envoyer avec le type MIME application/ogg, Gecko le prendra en charge en tant que vidéo.

Par défaut, la plupart des serveurs ne servent pas les fichiers Ogg avec le type MIME approprié, voici quelques éléments de configuration à prendre en compte.

Pour Apache, vous pouvez ajouter les lignes suivantes au fichier de configuration :

AddType audio/ogg .oga
AddType video/ogg .ogv
AddType application/ogg .ogg

Handle HTTP 1.1 byte 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 Content-Length header) in order to determine the duration of the media.

Your server should accept the Accept-Ranges: bytes HTTP header if it can accept byte-range requests. It must return 206: Partial content to all byte range requests; otherwise, browsers can't be sure you actually support byte range requests.

Your server must also return "206: Partial Content" for the request "Range: bytes=0-" as well.

Include regular key frames

When Gecko 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.

By default, ffmpeg2theora uses one key frame every 64 frames (or about every 2 seconds at 30 frames per second), which works pretty well.

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

The HTML <audio> and <video> elements provide the preload attribute, which tells Gecko to attempt to download the entire media when the page loads. Without preload, Gecko only downloads enough of the media to display the first video frame, and to determine the media's duration.

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.

Configuration for older Firefox versions

Serve X-Content-Duration headers

Note: As of Firefox 41, the X-Content-Duration header is no longer supported. See bug 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:

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 gzip/deflate compression

One common way to reduce the load on a web server is to use gzip or deflate compression when serving to a supporting web browser. When Firefox requests an Ogg media, it advertises that it can handle a gzipped or deflated response; the HTTP request includes the Accept-Encoding: gzip,deflate header. But despite Firefox advertising that it supports gzip/deflate, you probably don't want to gzip or deflate Ogg media. If you serve an Ogg media compressed, Firefox won't be able to seek in the media, or determine its duration. Since the video/audio data in Ogg files is already compressed, gzip/deflate won't actually save you much bandwidth anyway, so you probably want to disable compression when serving Ogg files.

Also, Apache servers don't send the Content-Length response header if gzip encoding is used.

Note: Starting in Gecko 2.0, Gecko will no longer request gzip or deflate compression when downloading media. The above is only relevant for Firefox 3.5/3.6.

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 package. The output from oggz-info looks like this:

 $ 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.

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.

See also