Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $digits = 4;
- $path = "/tmp/capture/";
- $prefix = "";
- $extension = "ts";
- $log_file = "/tmp/ffmpeg.log";
- $buffer_size = 5;
- function getChunkName($id, $path = ""){
- global $digits;
- global $prefix;
- global $extension;
- global $path;
- return $path.$prefix.str_pad($id+ 1, $digits, "0", STR_PAD_LEFT).".".$extension;
- }
- function writeLog( $data ){
- global $log_file;
- file_put_contents( $log_file, $data."\n", FILE_APPEND);
- }
- function displayChunk( $file_path ){
- writeLog($file_path);
- if( is_file ( $file_path ) ){
- readfile( $file_path );
- }else{
- writeLog( "ERROR ! Invalid path ".$file_path );
- }
- }
- $fileList = array();
- $current = 0;
- $d = opendir($path);
- if ( ! $d) {
- die( "Failed to load source directory $path content" );
- }
- while (($c = readdir($d))!==false) {
- if (is_file($path."/".$c)) {
- $c = intval($c);
- $fileList[] = $c;
- }
- }
- closedir($d);
- sort($fileList);
- $current = 0;
- if( count($fileList) > 1 ){
- $current = $fileList[count($fileList)-1];
- }
- if( count($fileList) < $buffer_size ){
- $buffer_size = count( $fileList);
- }
- $fileList = array_slice($fileList,count($fileList)-$buffer_size,$buffer_size-1);
- // Now we read the X latest files (fill the buffer in ...)
- writeLog("Filling the buffer");
- foreach($fileList as $k) {
- displayChunk( getChunkName($k), $path );
- }
- $timeout = 60;
- $noactivity = 0;
- // Endless stream loop
- while ( true ) {
- $file_path = getChunkName($current);
- if (file_exists($file_path)) {
- displayChunk( $file_path);
- // Update log record
- $current++;
- $noactivity = 0;
- } else {
- sleep(1);
- $noactivity++;
- writeLog( $file_path.":".$noactivity);
- // go home live, you're finished
- if ($noactivity >= $timeout) {
- die();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement