PHP Classes

File: examples/progress-handler-portability.php

Recommend this page to a friend!
  Classes of Oliver Lillie   PHP Video Toolkit   examples/progress-handler-portability.php   Download  
File: examples/progress-handler-portability.php
Role: Example script
Content type: text/plain
Description: .
Class: PHP Video Toolkit
Manipulate and convert videos with ffmpeg program
Author: By
Last change: switched session process ids in examples to prevent naming conflict between two portable progress handler examples
fixed issues with portable progress handler
updated examples to use default config instance for ease of reading examples
added default namespace to examples as it makes them clearer
Date: 1 year ago
Size: 3,024 bytes
 

Contents

Class file image Download
<?php

   
namespace PHPVideoToolkit;

    include_once
'./includes/bootstrap.php';
   
   
session_start();

    echo
'<a href="?reset=1">Reset Process</a>';

    try
    {
       
// important to not that this doesn't affect the actual process and that still carries on in the background regardless.
       
if(isset($_GET['reset']) === true)
        {
            unset(
$_SESSION['process_id_single']);
        }
       
        if(isset(
$_SESSION['process_id_single']) === true)
        {
           list(
$temp_id, $boundary, $time_started, $expected_duration) = explode('.', $_SESSION['process_id_single']);
           
Trace::vars('Process ID found in session...', $_SESSION['process_id_single'], array(
               
'$temp_id' => $temp_id,
               
'$boundary' => $boundary,
               
'$time_started' => $time_started,
               
'$expected_duration' => $expected_duration,
            ));
           
           
$handler = new ProgressHandlerPortable($_SESSION['process_id_single']);

           
Trace::vars('Probing progress handler...');
           
           
$probe = $handler->probe();
           
Trace::vars($probe);
            if(
$probe['finished'] === true)
            {
               
Trace::vars('Process has completed.');
                unset(
$_SESSION['process_id_single']);
                echo
'<a href="?reset=1">Restart Process</a>';
                exit;
            }
           
            echo
'<meta http-equiv="refresh" content="1; url=?'.time().'">';
            echo
'<a href="?reset=1">Reset Process</a>';
       
            exit;
        }
       
       
Trace::vars('Starting new encode...');
       
       
$video = new Video($example_video_path);
       
$process = $video->saveNonBlocking('./output/big_buck_bunny.mp4', null, Video::OVERWRITE_EXISTING);

       
$id = $video->getPortableId();
       
$_SESSION['process_id_single'] = $id;
       
        echo
'<h1>Process ID</h1>';
       
Trace::vars($id);
       
        echo
'<h1>Executed Command</h1>';
       
Trace::vars($process->getExecutedCommand());
       
       
        echo
'<meta http-equiv="refresh" content="1; url=?'.time().'">';
       
        exit;
    }
    catch(
FfmpegProcessOutputException $e)
    {
        echo
'<h1>Error</h1>';
       
Trace::vars($e);

       
$process = $video->getProcess();
        if(
$process->isCompleted())
        {
            echo
'<hr /><h2>Executed Command</h2>';
           
Trace::vars($process->getExecutedCommand());
            echo
'<hr /><h2>FFmpeg Process Messages</h2>';
           
Trace::vars($process->getMessages());
            echo
'<hr /><h2>Buffer Output</h2>';
           
Trace::vars($process->getBuffer(true));
        }
       
        echo
'<a href="?reset=1">Reset Process</a>';
    }
    catch(
Exception $e)
    {
        echo
'<h1>Error</h1>';
       
Trace::vars($e->getMessage());
        echo
'<h2>Exception</h2>';
       
Trace::vars($e);

        echo
'<a href="?reset=1">Reset Process</a>';
    }