File: //home/httpd/mech_ftp/baretube.com/admin/cli/transcodeFlvToMP4.php
<?
//this script will transcode all flv videos to mp4.
require("../db.php");
if ($argv[1]) {
foreach ($argv as $arg) {
$e = explode("=", $arg);
if (count($e) == 2) {
$command = $e[0];
$param = $e[1];
} else {
$command = $e[0];
}
}
}
if(!$command) {
exit("This file will transcode all FLV videos stored on your site to MP4.\nIf you are sure you want to do this, please execute it as follows: php transcodeFlvToMP4.php imsure\n");
}
$counter = (int)0;
if($command == 'imsure') {
$result = mysqli_query($dbconn,"SELECT * FROM content WHERE filename LIKE '%.flv'");
while($row = mysqli_fetch_assoc($result)) {
$first = $row['filename'][0];
$second = $row['filename'][1];
$third = $row['filename'][2];
$forth = $row['filename'][3];
$fifth = $row['filename'][4];
$subdir = $first.'/'.$second.'/'.$third.'/'.$forth.'/'.$fifth.'/';
$currentFilename = $video_path."/".$subdir.$row['filename'];
if(stripos($row[filename],'.mp4') !== true) {
//$newFname = uniqid().'.mp4';
$newFname = str_ireplace(".flv",".mp4",$row['filename']);
$newFilename = $video_path."/".$subdir.$newFname;
if($encoder_software == 'handbrake') {
$q = "$handbrake_path -i \"$currentFilename\" -o \"$newFilename\" $handbrake_command ";
} else {
$q = "$ffmpeg_path -i \"$currentFilename\" $ffmpeg_command \"$newFilename\"";
}
shell_exec($q);
if(file_exists($newFilename) && filesize($newFilename) > 102400) {
dbQuery("UPDATE content SET filename = '$newFname' WHERE record_num = '$row[record_num]'");
unlink($currentFilename);
}
}
}
exit("Done! $counter files transcoded.\n");
} else {
exit("This file will transcode all FLV videos stored on your site to MP4.\nIf you are sure you want to do this, please execute it as follows: php transcodeFlvToMP4.php imsure\n");
}
?>