Version 16

LibertyMime FLV Plugin

a LibertyMime plugin that converts videos of various formats to flashvideo

Created by: xing, Last modification: 12 Oct 2008 (07:43 UTC) by xing

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.php

If 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 flags
X, 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

$ 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


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

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.net

All 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 conversion results
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.
Page History
Date/CommentUserIPVersion
14 May 2009 (08:50 UTC)
Lester Caine81.138.11.13619
Current • Source
Lester Caine81.138.11.13618
View • Compare • Difference • Source
Lester Caine81.138.11.13617
View • Compare • Difference • Source
xing88.117.28.15616
View • Compare • Difference • Source
laetzer85.178.0.715
View • Compare • Difference • Source
Kozuch85.207.244.16014
View • Compare • Difference • Source
xing194.152.164.4512
View • Compare • Difference • Source
xing194.152.164.4511
View • Compare • Difference • Source
xing194.152.164.4510
View • Compare • Difference • Source
xing194.152.164.457
View • Compare • Difference • Source
xing194.152.164.456
View • Compare • Difference • Source
xing194.152.164.455
View • Compare • Difference • Source
xing194.152.164.454
View • Compare • Difference • Source
xing194.152.164.453
View • Compare • Difference • Source
xing194.152.164.452
View • Compare • Difference • Source
xing194.152.164.451
View • Compare • Difference • Source