Draft
<?php
class Process{
private $pid;
private $command;
public function __construct($cl=false){
if ($cl != false){
$this->command = $cl;
$this->runCom();
}
}
private function runCom(){
$command = 'nohup '.$this->command.' > /dev/null 2>&1 & echo $!';
exec($command ,$op);
$this->pid = (int)$op[0];
}
public function setPid($pid){
$this->pid = $pid;
}
public function getPid(){
return $this->pid;
}
public function status(){
$command = 'ps -p '.$this->pid;
exec($command,$op);
if (!isset($op[1]))return false;
else return true;
}
public function start(){
if ($this->command != '')$this->runCom();
else return true;
}
public function stop(){
$command = 'kill '.$this->pid;
exec($command);
if ($this->status() == false)return true;
else return false;
}
}
function stream($path) {
// CLEAN ALL PROCESSES ...
// exec("ps aux | grep streamer/tmp/linuxmce | awk '{print $2}' | xargs kill -9");
// SET VARS ...
$user = 'linuxmce';
$file = preg_replace('/[^A-Za-z0-9\-]/', '', end(explode("/", $path)));
$tmp = "/var/www/streamer/tmp/$user/" . $file;
$url = "http://192.168.80.1/streamer/tmp/$user/" . $file . '/stream.m3u8';
if(!is_dir("$tmp")) {
exec("mkdir -p $tmp/");
}
// START STREAMING PROCESS ...
$process = new Process();
$pid = exec("pgrep -f $file");
$process->setPid($pid);
if($process->status()) {
$msg = "Transcoding already running ...";
} else {
$process = new Process("/usr/local/bin/ffmpeg -i $path -r 25 -c:a libfaac -ab:a 48k -ac:a 2 -c:v libx264 -s:v 320x240 -b:v 150k -aspect:v 16:9 -map 0 -vbsf h264_mp4toannexb -flags -global_header -f segment -segment_time 4 -segment_list $tmp/stream.m3u8 -segment_format mpegts " . $tmp . "/stream%05d.ts");
$msg = "Start process ...";
}
// RETURN VALUES
$return = array('filename' => $file,
'url' => $url,
'msg' => $msg,
// 'tmp' => $tmp,
// 'pid' => $process->getPid());
);
// var_dump($return);
return json_encode($return);
}
$huhu = json_decode(stream('/mnt/device/36/Blow/Blow.2001.German.AC3.BDRip.XviD-iNCEPTiON.avi'));
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script src="mediaelement-and-player.js"></script>
<link rel="stylesheet" href="mediaelementplayer.css" />
</head>
<body>
<h1>HLS Wrapper</h1>
<video width="640" height="360" id="player1">
<source type="application/x-mpegURL" src="<?php echo $huhu->url; ?>" />
</video>
<script>
$('video').mediaelementplayer({
success: function(media, node, player) {
$('#' + node.id + '-mode').html('mode: ' + media.pluginType);
}
});
</script>
</body>
</html>