r40411 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40410‎ | r40411 | r40412 >
Date:23:32, 3 September 2008
Author:dale
Status:old
Tags:
Comment:
minnor multiple-instance fix
Modified paths:
  • /trunk/extensions/MetavidWiki/maintenance/transcode_to_flv.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/maintenance/transcode_to_flv.php
@@ -3,10 +3,10 @@
44 /*
55 ssh mounts commands:
66 sshfs dale@128.114.20.64:/metavid/video_archive /media/mv_ssh_oggMediaStorage/
7 - sshfs dale@mvbox2.cse.ucsc.edu:/metavid/video_archive /media/mv_ssh_oggMediaStorage/
 7+ sshfs dale@mvbox2.cse.ucsc.edu:/metavid/video_archive /media/mv_ssh_flvMediaStorage/
88
99 if running locally just link it ie on mvbox2:
10 - ln -s /metavid/video_archive /media/mv_ssh_oggMediaStorage/
 10+ ln -s /metavid/video_archive /media/mv_ssh_flvMediaStorage
1111 */
1212 $mvMountedSource = '/media/mv_ssh_oggMediaStorage/';
1313 //mvbox2.cse.ucsc.edu
@@ -20,7 +20,7 @@
2121
2222 define('MV_BASE_MEDIA_SERVER_PATH', 'http://mvbox2.cse.ucsc.edu/mvFlvServer.php/');
2323
24 -$flvEncodeCommand = 'ffmpeg -i $input -ar 22050 -aspect 4:3 -f flv -acodec mp3 -ac 1 -ab 32k -b 250k -s 400x300 $output';
 24+$flvEncodeCommand = 'ffmpeg -i $input -ar 22050 -aspect 4:3 -f flv -acodec libmp3lame -ac 1 -ab 32k -b 250k -s 400x300 $output';
2525
2626 $doneWithTrascode=false;
2727 while($doneWithTrascode==false){
@@ -38,49 +38,92 @@
3939 foreach($sorce_dir_ary as $source_file){
4040
4141 if(substr($source_file, -7)=='.HQ.ogg'){
42 - print "on HQ_File: $source_file \n";
 42+ print "on HQ_File: {$mvMountedSource}{$source_file} \n";
4343 //gennerate flash file name:
44 - $stream_name = substr( str_replace($mvMountedSource, '',$source_file),0,(strlen($source_file)-7));
 44+ $stream_name = substr( $source_file,0,(strlen($source_file)-7));
4545 $local_fl =$mvMountedDest . $stream_name . '.flv';
4646 if(!is_file($local_fl)){
4747 print "flv NOT found run trascode for: $source_file\n";
4848 //replace input:
49 - $flvEncodeCommand = str_replace('$input', $source_file, $flvEncodeCommand);
 49+ $flvEncodeCommand = str_replace('$input', $mvMountedSource . $source_file, $flvEncodeCommand);
5050 //replace output
51 - $flvEncodeCommand = str_replace('$output', $local_fl, $flvEncodeCommand);
 51+ $flvEncodeCommand = str_replace('$output', $local_fl, $flvEncodeCommand);
5252 $pid = simple_run_background($flvEncodeCommand);
5353 sleep(1); //give time for the proccess to start up
5454 while(is_process_running($pid)){
5555 clearstatcache();
56 - print "running trascode: ". filesize($local_fl);
 56+ print "running trascode: ". hr_bytes(filesize($local_fl)). "\n";
5757 sleep(10);
5858 }
59 - }
60 - //now it should be there
61 - if(is_file($local_fl)){
62 - //flv is found
63 - print "flv found: " . $mvMountedDest . $stream_name . ".flv \n";
64 - //check for .meta
65 - if(is_file($local_fl .META_DATA_EXT)){
66 - print " meta found \n";
67 - }else{
68 - echo "gennerating flv metadata for $local_fl \n";
69 - $flv = new MyFLV();
70 - try {
71 - $flv->open( $local_fl );
72 - } catch (Exception $e) {
73 - die("<pre>The following exception was detected while trying to open a FLV file:\n" . $e->getMessage() . "</pre>");
 59+ //now it should be there
 60+ if(is_file($local_fl)){
 61+ //flv is found
 62+ print "flv found: " . $mvMountedDest . $stream_name . ".flv \n";
 63+ //check for .meta
 64+ if(!is_file($local_fl .META_DATA_EXT)){
 65+ echo "gennerating flv metadata for $local_fl \n";
 66+ $flv = new MyFLV();
 67+ try {
 68+ $flv->open( $local_fl );
 69+ } catch (Exception $e) {
 70+ die("<pre>The following exception was detected while trying to open a FLV file:\n" . $e->getMessage() . "</pre>");
 71+ }
 72+ $flv->getMetaData();
 73+ echo "done with .meta (" . filesize($local_fl.META_DATA_EXT).") \n";
7474 }
75 - $flv->getMetaData();
76 - echo "done with .meta (" . filesize($local_fl.META_DATA_EXT).") \n";
 75+ //update db:
 76+ update_flv_pointer_db($stream_name);
 77+ break; //break out of forloop
7778 }
78 -
79 - }
 79+ }
8080 }
8181 }
82 - print "done with pass ... will run again in 5 seconds \n";
83 - sleep(5);
 82+ print "done with current pass ... will run again in 2 seconds \n";
 83+ sleep(2);
8484 }
 85+function update_flv_pointer_db($stream_name){
 86+ $dbr = wfGetDB(DB_READ);
 87+ $dbw = wfGetDB(DB_WRITE);
 88+
 89+ //get stream name:
 90+ $res = $dbr->select('mv_streams', '*', array( 'name'=>$stream_name));
 91+ $stream = $dbr->fetchObject($res);
 92+
 93+ $resFcheck = $dbr->select('mv_stream_files', '*', array(
 94+ 'stream_id'=>$stream->id,
 95+ 'file_desc_msg'=> 'mv_flash_low_quality'
 96+ )
 97+ );
 98+ if($dbr->numRows($resFcheck)==0){
 99+ //grab duration from mv_ogg_low_quality
 100+ $sql = " SELECT * FROM `mv_stream_files` WHERE `stream_id`='".$stream->id."' " .
 101+ " AND `file_desc_msg`='mv_ogg_low_quality'";
 102+ $rdur = $dbr->query($sql);
 103+ $dur_val =0;
 104+ if($dbr->numRows($rdur)){
 105+ $ogg_file = $dbr->fetchObject($rdur);
 106+ $dur_val = $ogg_file->duration;
 107+ }
 108+ $dbw->insert('mv_stream_files',
 109+ array('stream_id'=>$stream->id,
 110+ 'duration'=>$dur_val,
 111+ 'file_desc_msg'=>'mv_flash_low_quality',
 112+ 'path_type'=>'url_anx',
 113+ 'path'=>MV_BASE_MEDIA_SERVER_PATH . $stream->name .".flv")
 114+ );
 115+ print $dbw->lastQuery();
 116+ print "insert {$stream->name}.flv\n";
 117+ //$dbw->query($sql);
 118+ }else{
 119+ $file = $dbr->fetchObject($resFcheck);
 120+ $dbr->update('mv_stream_files',
 121+ array('path'=>MV_BASE_MEDIA_SERVER_PATH . $stream->name .'.flv'),
 122+ array('id'=>$file->id),
 123+ __METHOD__,
 124+ array('LIMIT'=>1));
 125+ $dbw->query($sql);
 126+ }
 127+}
85128 function simple_run_background($command){
86129 $PID = shell_exec("nohup $command > /dev/null & echo $!");
87130 return $PID;
@@ -91,5 +134,14 @@
92135 exec("ps $PID", $ProcessState);
93136 return(count($ProcessState) >= 2);
94137 }
95 -
 138+function hr_bytes($size) {
 139+ $size = (int)$size;
 140+ $a = array("B", "KB", "MB", "GB", "TB", "PB");
 141+ $pos = 0;
 142+ while ($size >= 1024) {
 143+ $size /= 1024;
 144+ $pos++;
 145+ }
 146+ return round($size,2)." ".$a[$pos];
 147+}
96148 ?>
\ No newline at end of file