Index: trunk/extensions/MetavidWiki/maintenance/transcode_to_flv.php |
— | — | @@ -3,10 +3,10 @@ |
4 | 4 | /* |
5 | 5 | ssh mounts commands: |
6 | 6 | 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/ |
8 | 8 | |
9 | 9 | 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 |
11 | 11 | */ |
12 | 12 | $mvMountedSource = '/media/mv_ssh_oggMediaStorage/'; |
13 | 13 | //mvbox2.cse.ucsc.edu |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | |
22 | 22 | define('MV_BASE_MEDIA_SERVER_PATH', 'http://mvbox2.cse.ucsc.edu/mvFlvServer.php/'); |
23 | 23 | |
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'; |
25 | 25 | |
26 | 26 | $doneWithTrascode=false; |
27 | 27 | while($doneWithTrascode==false){ |
— | — | @@ -38,49 +38,92 @@ |
39 | 39 | foreach($sorce_dir_ary as $source_file){ |
40 | 40 | |
41 | 41 | if(substr($source_file, -7)=='.HQ.ogg'){ |
42 | | - print "on HQ_File: $source_file \n"; |
| 42 | + print "on HQ_File: {$mvMountedSource}{$source_file} \n"; |
43 | 43 | //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)); |
45 | 45 | $local_fl =$mvMountedDest . $stream_name . '.flv'; |
46 | 46 | if(!is_file($local_fl)){ |
47 | 47 | print "flv NOT found run trascode for: $source_file\n"; |
48 | 48 | //replace input: |
49 | | - $flvEncodeCommand = str_replace('$input', $source_file, $flvEncodeCommand); |
| 49 | + $flvEncodeCommand = str_replace('$input', $mvMountedSource . $source_file, $flvEncodeCommand); |
50 | 50 | //replace output |
51 | | - $flvEncodeCommand = str_replace('$output', $local_fl, $flvEncodeCommand); |
| 51 | + $flvEncodeCommand = str_replace('$output', $local_fl, $flvEncodeCommand); |
52 | 52 | $pid = simple_run_background($flvEncodeCommand); |
53 | 53 | sleep(1); //give time for the proccess to start up |
54 | 54 | while(is_process_running($pid)){ |
55 | 55 | clearstatcache(); |
56 | | - print "running trascode: ". filesize($local_fl); |
| 56 | + print "running trascode: ". hr_bytes(filesize($local_fl)). "\n"; |
57 | 57 | sleep(10); |
58 | 58 | } |
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"; |
74 | 74 | } |
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 |
77 | 78 | } |
78 | | - |
79 | | - } |
| 79 | + } |
80 | 80 | } |
81 | 81 | } |
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); |
84 | 84 | } |
| 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 | +} |
85 | 128 | function simple_run_background($command){ |
86 | 129 | $PID = shell_exec("nohup $command > /dev/null & echo $!"); |
87 | 130 | return $PID; |
— | — | @@ -91,5 +134,14 @@ |
92 | 135 | exec("ps $PID", $ProcessState); |
93 | 136 | return(count($ProcessState) >= 2); |
94 | 137 | } |
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 | +} |
96 | 148 | ?> |
\ No newline at end of file |