Ogg Theora Cook Book

Hosting on your own site

Like images or HTML pages you can put your Theora videos on your own webserver. 

Mime Types

For videos to work they have to be served with the right mime type.

A mime type is the name given to a way of identifying different file types delivered over the Internet. This information is usually delivered with the data. The extra information identifying what kind of information is being delivered is usually not readable by humans, but is interpreted by software so that the right kind of data is delivered and processed by the right kind of software. The information is sent in the header of the transported data.

A header is a small amount of meta data sent by one software to another which describes the kind of information being transported. Typical header information includes the length, destination, mime type etc.

Mime types have two parts - the type and subtype (although the two together is just referred to simply as a 'type'). The type is written in the form type/subtype. There are only four categories of type - audio, video, text, and application. There are innumerable subtypes.

The right mime type for Theora video is 'video/ogg'.

A current server should send the right information.  If your server does not send the right headers, you have to change the configuration of your webserver. However, you should first consider if you know enough about configuring web services. If you are not feeling confident about this then perhaps enlist the support of a friendly techie. Assuming you are using the Apache webserver (the most popular webserver on the web), and you feel confident to change the server configuration, there are two ways you can do this :

  1. you can add two lines to your Apache webserver configuration
  2. you might be able to provide the extra settings by placing a .htaccess file in your video folder

For the first strategy you need access to your web server configuration file (httpd.conf). In this case all files being delivered by your webserver will send the correct information. This is the best solution. However if you do not have access to your webserver configuration files (for example, if you are using a shared hosting service) then you may wish to try the second strategy. The second strategy will only effect the video being served from the same folder that you put the .htaccess file.

For both strategies you need to enter this information in the appropriate file:

AddType video/ogg          .ogv
AddType application/ogg    .ogg

For httpd.conf and .htaccess files you can place this information at the end of the file.  If you do not have an .htaccess file you can just create a blank file and add this information (no other information is required).



Using Apache you can also get a lot more sophisticated. You can, for example, enable the use of URLs that reference and playback only part of any given Theora video file. If you want to include only parts of your video in your webpage or allow linking to a specific time in the video,  you can use oggz-chop on the server. With oggz-chop installed you can address segments of the video by providing an offset parameter in the url. To include second 23 to second 42, of your video you would use

 <video src="../http://example.com/video.ogv?t=23.0/42.0"></video>

Installing oggz-chop requires the action module to be enabled in Apache and oggz-chop installed on the server. Describing how to enable the action module is beyond the scope of this document, so you may better consult with an Apache guru, or read some documentation on this subject before attempting it.

However...if you know you have Apache2 installed and you have administrator access to your server you could try this command to install the actions module :

 sudo a2enmod actions

Try it at your own risk...

oggz-chop is part of oggz-tools, you can (probably) install that with :

sudo apt-get install oggz-tools

With those installed you have to enable oggz-chop with those two lines in your Apache configuration or .htaccess file:

ScriptAlias /oggz-chop /usr/bin/oggz-chop
Action    video/ogg    /oggz-chop

Allowing Remote Access

Videos, unlike images, can not be embedded from remote sites, if those sites do not specifically allow this.  To allow other sites to include your videos on their domain add this line to your Apache configuration or .htaccess file:

Header Set Access-Control-Allow-Origin "*"
With this setting, the server responds with an additional header 'Access-Control-Allow-Origin: *' which means that the videos can be embedded in any webpage. If you want to restrict access to the videos (for example, to be only accessible from http://example.org) you have to change it to:
Header Set Access-Control-Allow-Origin "http://example.org"

Note that now, your videos can not be embedded on domains other than example.org. The Access-Control-Allow-Origin header can also contain a comma separated list of acceptable domains.
https://developer.mozilla.org/En/HTTP_access_control has a more detailed description of http access control.

Serving Videos via a Script

As a final strategy. If you do not have control over your hosting setup but want to use videos anyway, it is possible to use a small PHP or CGI script to set the right headers and serve the video. Such a script could look like this:

$video = basename($_GET['name']);
if (file_exists($video)) {
  $fp = fopen($video, 'rb');
  header('Access-Control-Allow-Origin: *');
  header('Content-Type: video/ogg');
  header('Content-Length: ' . filesize($video));
} else {
  echo "404 - video not found";
If this script is placed as index.php in your video folder, you would use http://example.com/videos/?name=test.ogv instead of directly linking to your video (http://example.com/videos/test.ogv).
 <video src="../http://example.com/videos/?name=test.ogv"></video>