LibertyMime FLV Plugin
a LibertyMime plugin that converts videos of various formats to flashvideo
Created by: xing, Last modification: 14 May 2009 (08:50 UTC) by Lester Caine
The flv plugin is a video handler for Liberty. It will convert videos of various formats including .avi, .mpg, .mov and more to flashvideo and allows you to conveniently view the converted video from within your browser. A site that uses a similar process is youtube.
Installation
The flv plugin for Liberty is quite sophisticated. You need to install software on your server (you might even have to compile some binaries yourself), optionally install some PHP extension and install or activate a few files in bitweaver.The conversion process can be lengthy and therefore it is possible to run the conversion using a cron job. The cron PHP file is already present and all that needs to be done is add the appropriate cron job to your cron file, and set the cron option in Liberty. This plugin also requires a recent version of ffmpeg. In fact, you need to compile the SVN version of ffmpeg as other versions don't support conversion to .flv files (luckily, gentoo users only need to emerge --sync and compile the regular version of ffmpeg).
The plugin also supports the use of ffmpeg-php. This extension is not required but will enable bitweaver to extract video information such as video duration and other useless but handy information to improve processing and therefor final result.
Example of serverside converted videos
ffmpeg (required)
You can find some more help in liberty/plugins/cron.flv.phpIf you want to make use of the flv plugin, you need to install the SVN version of ffmpeg. Only the latest version of ffmpeg supports the .flv format. Your distribution might already include a version that supports .flv.
Install
You will need the SVN version of ffmpeg and you will have to compile this yourself:Some distros as examples:
Gentoo
ffmpeg and available USE flagsX, a52, aac, altivec, amr, debug, doc, dts, encode, ieee1394, imlib, mmx, network, ogg, oss, sdl, test, theora, threads, truetype, v4l, vorbis, x264, xvid, zlib
adjust USE flags as you wish. install using something like:
<?php
USE="a52 aac altivec amr dts encode mmx ogg oss theora vorbis x264 xvid"; emerge -av ffmpeg
?>
This will give you support for most audio and video codecs supported by the use flags. If the version of ffmpeg in portage is not recent enough for you, you can try installing ffmpeg from the berkano overlay.
Ubuntu
Fedora Core 6
at the time of writing this, the version in livna was faulty - i used the one in freshrpms:
# rpm -ihv http://ayo.freshrpms.net/fedora/linux/6/i386/RPMS.freshrpms/freshrpms-release-1.1-1.fc.noarch.rpm
# yum install ffmpeg
Generic instructions getting ffmpeg from svn for Linux
$ svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
$ cd ffmpeg
$ ./configure --help | grep enable
$ ./configure --enable-libmp3lame --enable-gpl
$ make
# make install
Depending on the system, you might be able to support more formats.
./configure --enable-mp3lame --enable-gpl --enable-a52 --enable-libogg --enable-vorbis --enable-xvid
./configure --enable-mp3lame --enable-gpl --enable-a52 --enable-libogg --enable-vorbis --enable-xvid
Windows using binary builds
Links to various pages relating to using ffmpeg on Windows but it lacks information on use with php.Unofficial Win32 Builds provides a complete package that can be used with windows. It's not been fully tested as yet, but does seem to be functioning the same as the Linux builds.
It seems that everybody is having problems with a windows binary for php, but a current set of notes can be found here. This references a rather large download for the php_ffmpeg files, but the relevant files are available here and at some point, a package similar to the PEAR compilation is available on the bitweaver archive .
Apart from the php_ffmpeg.dll, for convenience the rest of the files are best copied to \WINDOWS\System32\ directory. See the Windows installation notes page for more details of location files in Windows.
Setting up cron jobs
Processing video files can take a while and this process is therefore designed as a cron job. Set up a cron job similar to the following. This will check for open conversion jobs every minute:
* * * * * apache /path/to/php -q /path/to/cron.flv.php [number of videos to process] >> /path/to/log/file.log
- make sure apache is your apache user - you can check the 'User' setting in your apache.conf file (usually located at /etc/apache2/httpd.conf)
- number of videos to process is optional, default is 3
( Need to add notes on handling cron jobs on windows )
ffmpeg-php (optional)
ffmpeg-php is a php extension that makes it possible to easily access video information from within php. Please view the official site on how to add ffmpeg-php to your php setup: http://ffmpeg-php.sourceforge.netAll it allows us to do is check the aspect ratio and video length. This allows us to extract more appropriate video images and make more accurate conversions.
If you compile it as an extension, it should be recognised by this script. If you decide to compile it into your php, please modify the plugin where it says:
Modification required if ffmpeg has been compiled as part of PHP
<?php
if( extension_loaded( 'ffmpeg' )) {
}
?>
Plugins
Once the software is in place you need to make sure the flv plugin is active in the Liberty plugin admin screen. Please make sure you visit the plugin settings screen by clicking on the edit icon.Plugin settings
In the Liberty plugin admin screen there are a few flv-specific options you can set. Please make sure that the suggested path to ffmpeg is correct. Without this no videos will be converted. The video and audio settings are basically: the higher the better the quality but also the larger the download.Video conversion results
Here are some basic tests i made using a 60 second high quality divx film. I only include 2 bitrates and I've removed a few sizes to reduce table size.Video bitrate (bits/s) | Audio bitrate (bits/s) | Audio samplerate (Hz) | Video size (pixel x pixel) | File size (bytes) | Encoding time (s) |
---|---|---|---|---|---|
200 | 32 | 22050 | 320x180 | 1724 (1.7M) | 10 |
200 | 32 | 22050 | 480x270 | 1820 (1.8M) | 15 |
200 | 32 | 22050 | 640x360 | 2128 (2.1M) | 22 |
200 | 32 | 44100 | 320x180 | 2148 (2.1M) | 13 |
200 | 32 | 44100 | 480x270 | 2244 (2.2M) | 17 |
200 | 32 | 44100 | 640x360 | 2552 (2.5M) | 22 |
200 | 64 | 22050 | 320x180 | 1724 (1.7M) | 10 |
200 | 64 | 22050 | 480x270 | 1820 (1.8M) | 16 |
200 | 64 | 22050 | 640x360 | 2128 (2.1M) | 20 |
200 | 64 | 44100 | 320x180 | 2148 (2.1M) | 12 |
200 | 64 | 44100 | 480x270 | 2244 (2.2M) | 17 |
200 | 64 | 44100 | 640x360 | 2552 (2.5M) | 23 |
400 | 32 | 22050 | 320x180 | 2780 (2.8M) | 11 |
400 | 32 | 22050 | 480x270 | 2844 (2.8M) | 16 |
400 | 32 | 22050 | 640x360 | 2864 (2.8M) | 21 |
400 | 32 | 44100 | 320x180 | 3204 (3.2M) | 17 |
400 | 32 | 44100 | 480x270 | 3268 (3.2M) | 17 |
400 | 32 | 44100 | 640x360 | 3288 (3.3M) | 23 |
400 | 64 | 22050 | 320x180 | 2780 (2.8M) | 11 |
400 | 64 | 22050 | 480x270 | 2844 (2.8M) | 15 |
400 | 64 | 22050 | 640x360 | 2864 (2.8M) | 21 |
400 | 64 | 44100 | 320x180 | 3204 (3.2M) | 13 |
400 | 64 | 44100 | 480x270 | 3268 (3.2M) | 17 |
400 | 64 | 44100 | 640x360 | 3288 (3.3M) | 26 |
Video conversion test script
#!/bin/sh
# Path to video file to convert
videofile="video.avi"
# Aspect ratio of the video
aspect="16:9"
# Various sizes bitweaver can create - width is set by bitweaver, calculate video hight as determined by the aspect ratio of the video
size="240x136 320x180 480x270 640x360"
# Settings
video_bitrate="160000 240000 320000 400000"
audio_samplerate="11025 22050 44100"
audio_bitrate="16 32 64 96"
echo '{| style="text-align:right"
|+ Full results table
! Video bitrate (bits/s)
! Audio samplerate (Hz)
! Audio bitrate (bits/s)
! Video size (pixel x pixel)
! File size (bytes)
! Encoding time (s)' > results.wiki
for b in $video_bitrate; do
for ar in $audio_samplerate; do
for ab in $audio_bitrate; do
for z in $size; do
begin=`date +%s`
name="flv-$b-$ar-$ab-$z"
ffmpeg -i $videofile -acodec mp3 -b $b -ar $ar -ab $ab -f flv -s $z -aspect $aspect -y $name
now=`date +%s`
duration=$(($now - $begin))
bytes=`ls -s $name | sed 's/ .*$//'`
hbytes=`ls -sh $name | sed 's/ .*$//'`
echo "|-" >> results.wiki
echo "|$b || $ar || $ab || $z || $bytes ($hbytes) || $duration" >> results.wiki
mv $name "$name-$duration.flv"
done
done
done
done
echo "|}" >> results.wiki
Feel free to run your own tests and post your results here or append them as a comment.
Comments
great doc
mysoogal
mysoogal
Most of what bitweaver is and does happens automatically; and, considering it's complexity, bitweaver does it quite well. However, as with any Open Source CMS, various modules are at different stages of development - some rough as a cob, some smooth as a baby's bottom.
That's the great thing about Open Source - you can get the code and tweak it to your heart's content.
I see xing's instructions as "These are the things that need to happen. How you make them happen depends on your individual setup."
Adding this plugin is the same for any other bitweaver plugin. Much of the above instructions are for the behind the scenes action to support the plugin and process files.
Most of the initial developer documentation for any function is in the comments embedded in the source code. User-land documentation, of the "Go HERE, do THIS, to get THAT" sort, is (IMHO) not at the same level of completion as the source code