Skip to content

Commit

Permalink
cron/transcoder.php : support use of ffmpeg (over libav)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGoodwin committed May 19, 2014
1 parent f619b73 commit 32b46fa
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions cron/transcoder.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
<?php

require_once __DIR__ . '/../config.php';
/**
* Older versions of XOT allowed LO authors to upload .flv videos for embedding with the Learning Object.
* Unfortunately, flv videos aren't compatible with HTML5 based templates and will not display on e.g. tablets as
* Adobe Flash is not available.
* This cron job, when run will look for all videos which do not have an '.mp4' extension, and attempt to transcode (i.e. reformat) them.
* the original file is left as is - so if you start with :
*
* USER-FILES/2-Test-Nottingham/media/something.flv
*
* you'll end up with :
*
* USER-FILES/2-Test-Nottingham/media/something.flv
* USER-FILES/2-Test-Nottingham/media/something.mp4
*
* When the script runs it looks to see if a .mp4 variant of the file already exists, and if it does, it does nothing.
*
* Note, depending on your media files, running this may consume quite a lot of CPU / disk resource.
* No 'intelligence' is included to cope with duplicated source media files - to reduce resource usage.
*
*
* You'll need to have something like 'avconv' or 'ffmpeg' installed. See comments inline below.
* It'll probably work best with ffmpeg. Perhaps.
*
*/
require_once dirname(__FILE__) . '/../config.php';

if(!is_file('/usr/bin/avconv') && !is_File('/usr/bin/ffmpeg')) {
die("Cannot run; /usr/bin/avconv or /usr/bin/ffmpeg does not appear to be present");
}

$finfo = new finfo(FILEINFO_MIME_TYPE);
$files = glob($xerte_toolkits_site->users_file_area_full . '*/media/*');

$files = glob($xerte_toolkits_site->users_file_area_full . '*/media/*');

foreach ($files as $filename) {

Expand All @@ -31,16 +59,21 @@ function add_transcode_job($inputFilename, $outputFilename)
{
// Ubuntu 14.04 - libav-tools, libavcodec-extra-54

$cmd = 'avconv '
. '-i ' . escapeshellarg($inputFilename) // input filename
. ' -c:v h264 ' // video codec
. '-b:v 2000k ' // video bitrate
. '-c:a aac ' // audio codec
. '-b:a 196k ' // audio bitrate
. '-f mp4 ' // file format
. '-strict experimental ' // enable aac codec
. escapeshellarg($outputFilename) // output filename
. ' 2>&1';
if(is_file('/usr/bin/ffmpeg')) {
$cmd = 'ffmpeg -i ' . escapeshellarg($inputFilename) . ' -sameq -ar 22050 -vcodec libx264 ' . escapeshellarg($outputFilename) . ' 2>&1' ;
}
else {
$cmd = 'avconv '
. '-i ' . escapeshellarg($inputFilename) // input filename
. ' -c:v h264 ' // video codec
. '-b:v 2000k ' // video bitrate
. '-c:a aac ' // audio codec
. '-b:a 196k ' // audio bitrate
. '-f mp4 ' // file format
. '-strict experimental ' // enable aac codec
. escapeshellarg($outputFilename) // output filename
. ' 2>&1';
}

_debug("Running: $cmd");

Expand Down

0 comments on commit 32b46fa

Please sign in to comment.