Extension:FlvHandler

From MediaWiki.org

Jump to: navigation, search

                 

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
FlvHandler

Release status: beta

Flv-embedded.png
Implementation  Media
Description Flash video image handler
Author(s)  Adam Nielsen (MalvineousTalk)
Last Version  r3 (2009-09-18)
MediaWiki  1.13
License GPL
Download Download snapshot

Subversion [Help]
Browse source code

Example  [[Image:Movie.flv]]

check usage (experimental)

Contents

[edit] What can this extension do?

This extension adds support for using Flash video (.flv) files in exactly the same way as images are normally used, i.e. [[Image:Movie.flv]]. This allows users to upload Flash videos and add them to articles using a method they are already familiar with.

[edit] Usage

Once uploading of .flv files has been permitted, Flash videos can be uploaded and then embedded in an article page in the same manner as with images:

[[Image:My Movie.flv]]

[edit] Features

Features which make this extension stand out from other .flv extensions:

  • .flv files can be uploaded and displayed like any other image
  • .flv files can be categorised and thumbnails of the video shown on category pages (just like with ordinary images)
  • An image gallery can include .flv files

[edit] Installation

[edit] Requirements

  1. ffmpeg: This extension uses ffmpeg to extract the first frame from the video file, for use as a thumbnail. If you do not have the command-line ffmpeg binary available on your web host, you will not see any preview frames. You will however still be able to embed videos, but your site visitors will not know what the video is until they start playing it.
  2. flowplayer: This extension uses the GPL'd flowplayer Flash applet to play the FLV files. A future version will probably extend this to include other players as well (especially if someone sends me the HTML code to embed a particular player.)
  3. File uploads must already be working on your wiki. If not, see Manual:Configuring file uploads.

[edit] Download

Download the extension from the Subversion repository and save it into the extensions/FlvHandler directory of your wiki. If you have shell access to your server, you may do the following to download the extension.

Warning: Before you download read Requirements or you might install the wrong version:

cd extensions
svn co http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/FlvHandler

Download flowplayer v3.0.3 and unzip it into extensions/FlvHandler/flowplayer/ or alternatively set $wgFlashPlayer to the URL of flowplayer's .swf file. If you do not use flowplayer version 3.0.3 you will need to set $wgFlashPlayer as the default will point to the wrong filename version (see below.) Add the following to LocalSettings.php:

// Allow .flv files to be uploaded
$wgFileExtensions[] = 'flv';
 
include_once("$IP/extensions/FlvHandler/FlvHandler.php");
// Place any FlvHandler configuration options here

[edit] Configuration parameters

All these parameters are optional, and suitable defaults are selected if omitted.

  • $wgFlashPlayer - URL of the flowplayer .swf file. Default is $wgServer . $wgScriptPath . '/extensions/FlvHandler/flowplayer/flowplayer-3.0.3.swf'
  • $wgMinFLVSize - Minimum size of the playback window. Default is array(250, 250) (250 pixels wide by 250 pixels tall) which is about as small as flowplayer will go before the controls start being drawn on top of each other.
  • $wgFLVConverter - program to use to extract first frame of video for thumbnails. Default is 'ffmpeg' (currently the only available option.) This is not a filename, rather the value is used to decide which command line options should be used to get the desired output.
  • $wgFLVConverterPath - Path to conversion binary (ffmpeg executable) if not in the system path.

[edit] How it works

If you're writing an extension and you think you might get some clues from how FlvHandler is written, then read on - this section briefly explains how the extension does its job.

There are two parts to the extension. The first is an image handler, which registers itself in the same way as the SVG handler. The idea of an image handler is to convert an unsupported image format into one that is widely supported (usually .png). Whenever a request comes through to display the .flv file, the handler steps in, calls FFmpeg to generate a thumbnail of the video (if one hasn't already been created), and then returns that thumbnail in .png format. This thumbnail is then displayed as requested. If this was the only part of the plugin in use, then .flv files would appear everywhere as still images. It is this part of the plugin that allows .flv files to be used anywhere images are, such as in categories and image galleries. It is also this part of the plugin which relies on FFmpeg being available to generate the thumbnails.

The second part of the plugin uses the ImageBeforeProduceHTML hook to step in whenever an image is about to be rendered in an article (read: whenever an <img> tag is about to be printed.) If the image tag is a thumbnail (or not a Flash video) then further processing is cancelled, and the tag is rendered as per normal (and in the case of a thumbnail, the other part of the plugin takes over and generates a still frame as the thumbnail.) If instead the image is a Flash video, then the extension takes over and generates the HTML code necessary to embed the flash player in the page.

[edit] To do

This is a list of things planned for the extension that aren't currently there:

  • Support for multiple Flash playing applets (only flowplayer is currently implemented)
  • Extra code around the embedded player so that there is a link to the .flv's article page (like what happens when you click on an embedded image, and you are taken to the image's article page.)
  • Preview on the .flv's article page, so you can watch the video from there (currently you have to embed it in a page before you can watch it.)
  • Support for some of the flash player's tags (abstracted so it works with any flash player) - e.g. autostart
  • Ability to specify (in the [[Image]] tag) which frame to use as the thumbnail - currently it is hard-coded as the first frame

[edit] Troubleshooting

If ffmpeg won't generate thumbnails, try removing -vcodec png from this line in FlvHandler.php:

$wgFLVConverters = array(
        'ffmpeg' => '$path/ffmpeg -vcodec png -i $input -ss 0 -vframes 1 -s $widthx$height -f image2 $output'
);

This parameter is required for early (~2007) versions of ffmpeg, but seems to cause problems for recent (~2009) versions.

[edit] See also

There are quite a few other Flash player extensions listed on the Video player extensions category, though at the time of writing they all use custom tags which users will need to learn before they can embed Flash videos.