GVPS (Grails Video Pseudo Streaming) Plugin - Reference Documentation
Authors: Ryan Vanderwerf, Peter N. Steinmetz
Version: 0.3
Table of Contents
1 Introduction
This plugin provides facilities for converting video formats and streaming videos from a Grails application.To do so, it provides the following primary functions:- A
Moviedomain object to represent movies which are stored on the local file system. - A tag library to display videos on a page as well as include required libraries.
- Controllers and views for uploading, managing, and showing movies.
- A
VideoServiceto manage movie files stored on the file system, convert movie formats, and stream their contents to clients.
Credits.
This plugin was originally developed as the Cantina Consulting pre-1.0 Grails Plugin, and was converted to be compatible with Grails 2 by Ryan Vanderwerf and Burt Beckwith.2 Prerequisites
Thegvps plugin uses several helper applications to perform functions such as converting videos or retrieving information about the video files.
ffmpeg. This is a widely used video format conversion program which is available at ffmpeg.org. It is available in package format for most major operating systems and distributions. This program is required to convert videos using the gvps plugin.ffprobe. This program, which is normally installed along withffmpeg, retrieves metadata, such as length, for a video file. It is required to convert videos using the gvps plugin.qt-faststart. This program is an optional install included with the source of the ffmpeg program. It is often available as a separate package. It is required if thegvpsplugin will be serving MP4 files.yamdi. This program injects metadata into FLV video files. It is available at yamdi.sourceforge.net and is often available in packaged form. It is required if thegvpsplugin will be serving FLV files.
gvps plugin can be used without these helper programs if no video file conversions will be performed by the plugin. An example would be when files are uploaded by a separate mechanism onto the server in the correct format.
3 Getting Started
This section will guide you through creating a basic application to store and stream videos. It assumes that the Prerequesites are installed on the server where the Grails application is running.Installing the plugin.
For Grails 2.x add the following toBuildConfig.groovy:grails.project.dependency.resolution = {
plugins {
compile ">>
}
}install-plugin gvps.Configuration.
The plugin is configured using a block in theConfig.groovy file. Insert the following:video {
location = "/tmp/" // location for storage of videos, can be on a shared drive
yamdi {
path = "/usr/bin/yamdi" // FLV metadata injector (IF TYPE= FLV)
}
ffmpeg {
fileExtension = "flv" // use flv or mp4
conversionArgs = "-b 600k -r 24 -ar 22050 -ab 96k"
path = "/usr/bin/ffmpeg"
makethumb = "-an -ss 00:00:03 -an -r 2 -vframes 1 -y -f mjpeg"
}
ffprobe {
path = "/usr/bin/ffprobe" // finds length of movie
params = ""
}
flowplayer {
version = "3.1.2" // use empty string for no version on file
}
swfobject {
version = "" // used for jw-flv player, empty to not specify version
}
qtfaststart {
path = "/usr/sbin/qt-faststart" // if ffmpeg.fileExtension == mp4 used to rearrange metadata
}
}Run the application.
At this point, you should have a basic running application which will allow creation, conversion, and viewing of videos. First run the application withgrails run-app, then access the MovieController to create a video. This should then appear in the Movie List and be viewable.
4 Configuration
The operation of thegvps plugin is configured in a stanza within the Config.groovy file. The primary items to be configured are whether the plugin will work with FLV or MP4 files and the locations of the helper programs (see Prerequisites.A sample configuration is as follows.video {
location = "/tmp/" // location for storage of videos, can be on a shared drive
yamdi {
path = "/usr/bin/yamdi" // FLV metadata injector (IF TYPE= FLV)
}
ffmpeg {
fileExtension = "flv" // use flv or mp4
conversionArgs = "-b 600k -r 24 -ar 22050 -ab 96k"
path = "/usr/bin/ffmpeg"
makethumb = "-an -ss 00:00:03 -an -r 2 -vframes 1 -y -f mjpeg"
}
ffprobe {
path = "/usr/bin/ffprobe" // finds length of movie
params = ""
}
flowplayer {
version = "3.1.2" // use empty string for no version on file
}
swfobject {
version = "" // used for jw-flv player, empty to not specify version
}
qtfaststart {
path = "/usr/sbin/qtfaststart" // if type == mp4 used to rearrange metadata
}
}5 Using Videos with Tags
Thegvps plugin provides a tag library which is one of the primary methods of using the plugin after the Movie domain objects have been created. All tags for this plugin are available in the vid: namespace.Two tags in a gsp are required to display a video. The first is the includes tag, which is placed in the <head> of the page to pull in the appropriate video player library. The specific library used is specified with the player attribute, which must be set to either 'jwflv' or 'flowplayer'. Use the 'jwflv' setting if the 'ffmpeg.fileExtension' configuration variable is set to 'flv' and the 'flowplayer' setting if 'ffmpeg.fileExtension' is set to 'mp4'.The second tag is the display tag, which is inserted into the markup of the body to render the player object. The player attribute is again used to specify the type of player and the id or movie attribute is used to specify the video to be displayed. Additional attributes are used to specify whether to stream the video and its size.Lastly, the convertVideoPlaytime tag is used to render video play times in readable form.
6 Using the VideoService
Thegvps plugin provides a VideoService object with methods to convert and serve video files. It can be injected into a controller with a statement like def videoService.You can stream the content for a Movie object using either the streamFlv or streamMp4 methods.The putMovie method is used to add a new Movie to the database and the convertVideo method is used to convert the video to serve-able files on the file system. The convertNewVideo method will convert all Movies whose status 'new'.
7 Administrative Interface
Thegvps plugin provides a MovieController and several views for an administrative interface to create, rename, update, and delete Movie objects.To use this interface, access the <ctx>/MovieController URL, which should direct you to the Movie list. From here you can modify existing Movie objects or create a new one.The show action for a Movie object shows the fields of the object as well as 5 views of the movie:
- A view shown with the JW-FLV player and pseudo-streaming flv content.
- A view shown with the JW-FLV player and downloading flv content.
- A view shown with Flowplayer and pseudo-streaming mp4 content.
- A view shown with Flowplayer and downloading mp4 content.
- A view shown with the JW-FLV player with captioning turned on.
8 Security
Security can provided for the the actions of the MovieController, the administrative interface, or specific Movie objects.Securing MovieController Actions.
It is important to secure the MovieController actions as these will be available by default when thegvps plugin is installed. When using the SpringSecurity plugins, one method of doing this is to override the 'streamFlv' or 'streamMp4' actions and add an annotation:@Secured(["isAuthenticated()"]) def streamflv = { def movie = Movie.get(params.id) if (movie.status != Movie.STATUS_CONVERTED) return videoService.streamflv(params,request,response,movie) }
Map in the Config.groovy file (see Simple Map in Config.groovy) or adding RequestMap entries to the database (see Requestmap Instances Stored in the Database.Securing the Administrative Interface.
While securing theMovieController streamFlv or streamMp4 actions will prevent viewing of video content itself, it will often be important to secure even the listings of the available videos and their metadata. Since other actions on the MovieController, such as list, edit, and show are available by default, it is also important to secure these actions.Although overrides such as described above can be implemented with attached security annotations, the use of a Map in Config.groovy or RequestMap objects in the database may be easier for most applications.Securing Movie Objects.
Securing access to specificMovie objects will in general require the use of access control lists. The spring-security-acl plugin plugin provides this level of fine-grained control.
9 Miscellaneous
The following are a number of additional pieces of information which may be useful to users or developers of thegvps plugin.Conversion parameters.
Thegvps plugin uses ffmpeg to perform conversion to the video formats which are used to serve video content. The parameters for the conversions are defined in the video.ffmpeg.conversionArgs setting, and are typically set as '-b 600k -r 24 -ar 22050 -ab 96k'.The meanings of these are as follows| Setting | Meaning |
|---|---|
| -b 600k | set video bitrate of video to 600kbps |
| -r 24 | set framerate to 24 fps |
| -ar 22050 | audio sampling frequency rate |
| -ab 96k | audio bit rate |
ffmpeg you have installed.How to Help
Currently we need someone more familiar with flowplayer to upgrade the taglib to use the current version, which has changed significantly.Other items to be improved:- toggle related binary-based domain object so actual videos can be stored in DB (or no-SQL db) instead of FS
- toggle temp files being stored in working table in database, to avoid needing shared filesystem to process videos
- update html and styles on admin screens
- write actual unit tests
- convert taglibs to use gsp includes for flowplayer/jw-flv html
- add support for latest flowplayer versions