.< I KNEW I had come across that problem in the past but couldn't remember how I resolved it last time and I have been searching for hours to try to find an answer 😃
Time to test it out finally I DO however have another code BUT it is giving yet another stupid error which I've again had in the past.
Ok it got a lot further this time but says it can't find something or other, I think I would prefer a little help with the other version that I followed a guide to BUT came across another stupid db error, Yes db is on sql etc but it's a undefined error.
Fatal error: Call to undefined function dbConnect() in C:\xampp\htdocs\sqlupload\index.php on line 4
if (!dbConnect())
{
echo mysql_error();
}
And from what I can see it SHOULD be working???
Index.php
<?php
require_once('/include/config/config.ini.php');
if (!dbConnect())
{
echo mysql_error();
}
$where = array(
'status' => 'finished'
);
$videos = getVideos(/*$where*/);
$pageTitle = 'Video Gallery';
require_once('templates/index.php');
?>
Config.ini.php
<?php
// set to allow error messages, comment out for live
ini_set('error_reporting', E_ALL | E_NOTICE | E_STRICT);
ini_set('display_errors', 'On');
ini_set('display_startup_errors', 'On');
//Database configs
// File path and Database settings
define('BASE_PATH', realpath(dirname(__FILE__)) . '/../../');
define('HOST_NAME', 'localhost');
define('USER_NAME', 'root');
define('USER_PASS', 'Password');
define('DB_NAME', 'MyDB');
// path to ffmpeg and qt-faststart binary
defined('FFMPEG_BINARY') || define('FFMPEG_BINARY', '../ffmpeg/bin/ffmpeg');
defined('QT_FASTSTART_BINARY') || define('QT_FASTSTART_BINARY', '../ffmpeg/bin/qt-faststart');
defined('FLVTOOL2_BINARY') || define('FLVTOOL2_BINARY', '../ffmpeg/bin/flvtool2');
// require necessary functions for database and conversion scripts
require_once(BASE_PATH . 'include/functions/functions.php');
// configuration options for VideoConverter.php class
$config = array(
'uploadPath' => BASE_PATH . 'data/video/uploads/',
'outputPath' => BASE_PATH . 'data/video/output/',
'thumbPath' => BASE_PATH . 'data/video/thumbnails/',
'conversionLog' => BASE_PATH . 'data/logs/conversionLog.log',
'errorLog' => BASE_PATH . 'data/logs/errorLog.log',
'conversionScript' => BASE_PATH . 'include/scripts/processVideo.php',
'outputFormat' => 'flv', // either 'mp4' or 'flv'
'bitRate' => 32000,
'sampleRate' => 22050,
'videoMaxWidth' => 320,
'videoMaxHeight' => 240,
'thumbMaxWidth' => 320,
'thumbMaxHeight' => 240,
'minDuration' => 1,
'videoThumbDepth' => 25, // in %
'showCommand' => false,
);
Functions.php
function dbConnect()
{
$link = mysql_connect(HOST_NAME, USER_NAME, USER_PASS);
if (!$link) {
return false;
}
if (!mysql_select_db(DB_NAME)) {
mysql_close($link);
return false;
}
return true;
}
function insertVideo($details = array())
{
if (count($details) == 0) {
return false;
}
$query = sprintf('insert into videos (filename, title, duration, format, width, height) values ("%s", "%s", "%s", "%s", %s, %s)',
basename($details['filename']),
$details['title'],
$details['duration'],
$details['format'],
$details['width'],
$details['height']
);
$result = mysql_query($query) or die(mysql_error());
return mysql_insert_id();
}
function getVideos($where = array())
{
$query = 'select * from videos ';
if (count($where) > 0) {
$i = 0;
foreach ($where as $column => $value) {
if ($i == 0) {
$query .= sprintf('where %s = "%s" ', $column, $value);
} else {
$query .= sprintf('and %s = "%s" ', $column, $value);
}
$i++;
}
}
$query .= 'order by ts_uploaded DESC';
$result = mysql_query($query);
// format each required into array
$items = array();
while ($row = mysql_fetch_object($result)) {
$items[$row->id]['id'] = $row->id;
$items[$row->id]['filename'] = $row->filename;
$items[$row->id]['status'] = $row->status;
$items[$row->id]['format'] = $row->format;
$items[$row->id]['title'] = $row->title;
$items[$row->id]['duration'] = $row->duration;
$items[$row->id]['thumbnail'] = getThumbname($row->filename);
$items[$row->id]['width'] = $row->width;
$items[$row->id]['height'] = $row->height;
}
return $items;
}
function getVideoById($id)
{
$query = sprintf('select * from videos where id = %d',
$id);
$result = mysql_query($query);
return mysql_fetch_assoc($result);
}
function deleteVideoById($id)
{
$query = sprintf('delete from videos where id = "%s" limit 1',
$id
);
$result = mysql_query($query);
return mysql_affected_rows() > 0;
}
function updateVideo($update = array())
{
if (count($update) == 0) {
return false;
}
$updates = array();
$query = 'update videos set ';
foreach ($update as $key => $value) {
if ($key != 'id') {
$updates[] = sprintf('%s = "%s" ', $key, $value);
// $query .= implode(', ', $updates);
}
}
$query .= implode(', ', $updates);
$query .= sprintf(' where id = "%s"', $update['id']);
$query .= ' limit 1';
$result = mysql_query($query);
return mysql_affected_rows() > 0;
}
function getThumbname($filename)
{
return getBasename($filename) . '.jpg';
}
function getBasename($filename)
{
return substr($filename, 0, strrpos($filename, '.'));
}
function buildFfmpegCommand($config = array(), $video = array())
{
if (count($video) == 0 || count($config) == 0) {
return false;
}
if ($video['format'] == 'flv') {
$command = FFMPEG_BINARY . " -y -i " . $config['uploadPath'] . getBasename($video['filename']) . '.* ';
$command .= "-s " . $video['width'] . "x" . $video['height'] . " ";
$command .= " -sameq -ab " . $config['bitRate'];
$command .= " -ar " . $config['sampleRate'];
$command .= " -f flv " . $config['outputPath'] . $video['filename'] . ' ';
$command .= '> ' . $config['conversionLog'] . ' 2>&1';
// $command .= ' | flvtool2 -U ' . $this->_outputFile . ' &';
} else if ($video['format'] == 'mp4') {
$command = FFMPEG_BINARY . " -y -i ". $config['uploadPath'] . getBasename($video['filename']) . '.* ';
$command .= "-acodec libfaac -ab " . $config['bitRate'] . " ";
$command .= "-s " . $video['width'] . "x" . $video['height'] . " ";
$command .= "-vcodec libx264 -vpre fast -crf 22 -threads 0 -g 15 ";
$command .= $config['outputPath'] . "temp-" . $video['filename'] . " ";
$command .= "> " . $config['conversionLog'] . " 2>&1";
}
return $command;
}
function buildQtFaststartCommand($config = array(), $video = array())
{
if (count($video) == 0 || count($config) == 0) {
return false;
}
return QT_FASTSTART_BINARY . ' ' . $config['outputPath'] . "temp-" . $video['filename']
. ' ' . $config['outputPath'] . $video['filename'];
}
function buildFlvtool2Command($config = array(), $video = array())
{
if (count($video) == 0 || count($config) == 0) {
return false;
}
return FLVTOOL2_BINARY . ' -U ' . $config['outputPath'] . $video['filename'];
}