Video Filter is a highly flexible and easy extendable filter module to embed any type of video in your site using a simple tag. Other modules can add video sites/formats (called codecs) using an easy plug-in architecture.

Installation

Enable the module on the modules page. By default all codecs will work. You may enable/disable individual codecs on the text formats settings page.

Drupal 7, 8:

Go to admin/config/content/formats and configure the text format(s) that should be allowed to use this filter. Check the box to enable Video Filter and save. Some simple settings are available if you configure the text format. There you can change the default size and auto play settings.

All:

Make sure that Video Filter is processed before "Convert URLs to links". You can do this by dragging and dropping Video Filter to the top of the processing order list. Do this even if it's already on top, just to make sure!

If you're using the "Limit allowed HTML tags" filter, make sure Video Filter is processed after that filter.

To enable WYSIWYG support, go to the WYSIWYG settings for each input format and enable the Video Filter button. If you use CKeditor without the Wysiwyg module you need to take some extra steps. See the README in video_filter/editors/ckeditor.

Usage

Single video:

[video:url]

This will output the video using the default settings.

Random video from multiple URL's:

[video:url,url,url]

This will output one of the specified videos each time. This can be disable in each text format settings.

With parameters:

[video:url width:X height:Y align:left/right autoplay:1/0]

This will override the default settings for this video. More options provided by codecs and plugins (Drupal 8).

Included codecs

Developers

Drupal 8

See video_filter/modules/video_filter_example module to see how to add your own plugins and extend Video Filter module.

Drupal 7

This module calls hook_codec_info(), so you can add your own codecs.

Example:

function MODULE_codec_info() {
  $codecs = array();
  // You can offer multiple video formats in one module.
  $codecs['youtube'] = array(
    // Will be used some day in user information.
    'name' => t('YouTube'),

    // The callback that will output the right embed code.
    'callback' => 'MODULE_youtube',

    // Regexp can be an array. $video['codec']['delta'] will be set to the key.
    'regexp' => '/youtube\.com\/watch\?v=([a-z0-9]+)/i',

    // Ratio for resizing within user-given width and height (ratio = width / height)
    'ratio' => 425 / 355,
  );
  return $codecs;
}

And this will be your callback function:

function MODULE_youtube($video) {
  // $video contains the video URL in source, the codec (as above) and also [code][matches] with the result of the regexp and [codec][delta] with the key of the matched regexp.
  $video['source'] = 'http://www.youtube.com/v/'.$video['codec']['matches'][1].($video['autoplay'] ? '&autoplay=1' : '');
  
  // Outputs a general <object...> for embedding flash players. Needs width, height, source and optionally align (left or right) and params (a list of <param...> attributes)
  return video_filter_flash($video);
}

Comments

rofsky’s picture

I wrote a codec for Brightcove if anyone needs it:

  $codecs['brightcove'] = array(
  	'name' => t('Brightcove'), 
	'sample_url' => 'http://link.brightcove.com/services/player/bcpid1077328347001?bctid=10734535994001',
	'callback' => 'video_filter_brightcove',
    'regexp' => '/link\.brightcove\.com\/services\/player\/([a-z0-9\-_]+).*bctid=([a-z0-9]+)/i',
    'ratio' => 425 / 355,
  );

I have a callback function name video_filter_brightcove, but it could use a lil more finesse, ill post a link to it on my site after I get it done., the above should get you started, $video['codec']['matches'][2] is the video id, and $video['codec']['matches'][1] would be the playerid.

kpm’s picture

Is this something basic or one of those "if I have to ask..."
Thanks

Anonymous’s picture

Here's an example of integrating an Adobe Flash Media server.

Create a custom module with the following code:

function flashmedia_video_filter_codec_info() {
	$codecs['flashmedia'] = array(
	  'name' => t('Flash Media Server'),
	  'sample_url' => 'rtmp://flash.example.com/subdir/subdir/samplevideo.flv',
	  'callback' => 'flashmedia_video_filter_flashmedia',
		'regexp' => '/flash\.example\.com\/subdir\/subdir\/([a-zA-Z0-9]+)/',
	  'ratio' => 480 / 360,
	);
	return $codecs;	
}

function flashmedia_video_filter_flashmedia($video) {
  $video['source'] = 'http://example.com/sites/all/libraries/mediaplayer/player.swf';

  $params = array(
		'allowscriptaccess' => 'always', 
		);
  $params['flashvars'] = 'file=' . urlencode('/' . $video['codec']['matches'][1]);
  $params['flashvars'] .= '&streamer=' . urlencode('rtmp://flash.example.com/subdir/subdir/');
  $params['flashvars'] .= '&type=rtmp';
  $params['flashvars'] .= '&width=' . $video['width'] ;
  $params['flashvars'] .= '&height=' . $video['height'] ;
  $params['flashvars'] .= '&autostart=false';

  return video_filter_flash($video, $params);
}