<?php

namespace PHPVideoToolkit;

include_once './includes/bootstrap.php';
try {
    $video = new Video($example_video_path);
    $process = $video->extractSegment(new Timecode(10), new Timecode(20))->save('./output/test-' . time() . '.mp3', null, Media::OVERWRITE_EXISTING);
    echo '<h1>Executed Command</h1>';
    Trace::vars($process->getExecutedCommand());
    echo '<hr /><h1>FFmpeg Process Messages</h1>';
    Trace::vars($process->getMessages());
    echo '<hr /><h1>Buffer Output</h1>';
    Trace::vars($process->getBuffer(true));
    echo '<hr /><h1>Resulting Output</h1>';
    Trace::vars($process->getOutput()->getMediaPath());
} 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));
    }
} catch (Exception $e) {
    echo '<h1>Error</h1>';
    Trace::vars($e->getMessage());
<?php

namespace PHPVideoToolkit;

include_once './includes/bootstrap.php';
try {
    $video = new Video($example_video_path);
    //  $process->setProcessTimelimit(1);
    $process = $video->extractSegment(new Timecode(10), new Timecode(20))->save('./output/big_buck_bunny.flv', null, Media::OVERWRITE_EXISTING);
    echo '<h1>Executed Command</h1>';
    Trace::vars($process->getExecutedCommand());
    echo '<hr /><h1>FFmpeg Process Messages</h1>';
    Trace::vars($process->getMessages());
    echo '<hr /><h1>Buffer Output</h1>';
    Trace::vars($process->getBuffer(true));
    echo '<hr /><h1>Resulting Output</h1>';
    Trace::vars($process->getOutput()->getMediaPath());
} 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));
    }
} catch (Exception $e) {
    echo '<h1>Error</h1>';
<?php

namespace PHPVideoToolkit;

include_once './includes/bootstrap.php';
echo '<a href="?method=blocking">Blocking</a> | <a href="?method=non-blocking">Non blocking</a><br />';
try {
    $video = new Video($example_video_path);
    $video->extractSegment(new Timecode(10), new Timecode(30));
    $process = $video->getProcess();
    $multi_output = new MultiOutput();
    $flv_output = './output/big_buck_bunny.multi1.ogg';
    $format = Format::getFormatFor($flv_output, null, 'VideoFormat');
    $format->setVideoDimensions(VideoFormat::DIMENSION_SQCIF);
    $multi_output->addOutput($flv_output, $format);
    $threegp_output = './output/big_buck_bunny.multi2.3gp';
    $format = Format::getFormatFor($threegp_output, null, 'VideoFormat');
    $format->setVideoDimensions(VideoFormat::DIMENSION_XGA);
    $multi_output->addOutput($threegp_output, $format);
    $threegp_output = './output/big_buck_bunny.multi3.3gp';
    $format = Format::getFormatFor($threegp_output, null, 'VideoFormat');
    $format->setVideoDimensions(VideoFormat::DIMENSION_XGA);
    $multi_output->addOutput($threegp_output, $format);
    if (isset($_GET['method']) === true && $_GET['method'] === 'blocking') {
        echo '<h2>Blocking Method</h2>';
        // If you use a blocking save but want to handle the progress during the block, then assign a callback within
        // the constructor of the progress handler.
        // IMPORTANT NOTE: most modern browser don't support output buffering any more.
        $progress_data = array();
        $progress_handler = new ProgressHandlerNative(function ($data) use(&$progress_data) {
            // do something here like log to file or db.
            $config->gif_transcoder = 'gifsicle';
        } else {
            if ($gif_transcoder === 'gifsicle-with-convert') {
                $config->convert = $convert;
                $config->gif_transcoder = 'gifsicle';
            } else {
                if ($gif_transcoder === 'convert') {
                    $config->convert = $convert;
                    $config->gif_transcoder = 'convert';
                }
            }
        }
        $output_format = Format::getFormatFor($output_path, $config, 'ImageFormat');
        $output_format->setVideoFrameRate(12);
        $video = new Video($example_video_path, $config);
        $process = $video->extractSegment(new Timecode(10), new Timecode(30))->save($output_path, $output_format, Media::OVERWRITE_EXISTING);
        $length = microtime_float() - $start;
        echo '<h1>' . str_replace('-', ' ', $gif_transcoder) . '</h1>';
        echo 'File = ' . $output_path . '<br />';
        echo 'Time to encode = ' . $length . '<br />';
        echo 'File size = ' . filesize($output_path) / 1024 / 1024 . ' MB<br />';
    }
} catch (FfmpegProcessOutputException $e) {
    echo '<h1>Error</h1>';
    Trace::vars($e->getMessage());
    echo '<h2>FfmpegProcessOutputException</h2>';
    Trace::vars($e);
    $process = $video->getProcess();
    if ($process->isCompleted()) {
        echo '<hr /><h2>Executed Command</h2>';
        Trace::vars($process->getExecutedCommand());
<?php

namespace PHPVideoToolkit;

include_once './includes/bootstrap.php';
try {
    $video = new Video($example_video_path);
    $video->extractSegment(new Timecode(15));
    $process = $video->save('./output/big_buck_bunny.my_silly_custom_file_extension', new ImageFormat_Jpeg('output'), Media::OVERWRITE_EXISTING);
    echo '<h1>Executed Command</h1>';
    Trace::vars($process->getExecutedCommand());
    echo '<hr /><h1>FFmpeg Process Messages</h1>';
    Trace::vars($process->getMessages());
    echo '<hr /><h1>Buffer Output</h1>';
    Trace::vars($process->getBuffer(true));
    echo '<hr /><h1>Resulting Output</h1>';
    Trace::vars($process->getOutput()->getMediaPath());
} 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));
    }
} catch (Exception $e) {
    echo '<h1>Error</h1>';
<?php

namespace PHPVideoToolkit;

include_once './includes/bootstrap.php';
ob_start();
echo '<p>This is an example to chain processing on from one output to another to another and so on.</p><hr />';
echo '<p>.mov status: <strong id="status-1">---</strong></p>';
echo '<p>resize mov status: <strong id="status-2">---</strong></p>';
echo '<p>jpeg from resized mov status: <strong id="status-3">---</strong></p>';
ob_flush();
try {
    $video = new Video($example_video_path);
    $progress_handler = new ProgressHandlerNative();
    $process = $video->extractSegment(new Timecode(10), new Timecode(20))->saveNonBlocking('./output/big_buck_bunny.mov', null, Media::OVERWRITE_EXISTING, $progress_handler);
    $dot_count = -1;
    while ($progress_handler->completed !== true) {
        $dot_count += 1;
        $data = $progress_handler->probe(true);
        if ($data['started'] === true) {
            echo '<script>document.getElementById("status-1").innerHTML = ' . json_encode('Encoding to mov ' . $data['percentage'] . '% ' . str_pad('', $dot_count, '.')) . '</script>';
            echo '&nbsp;';
            ob_flush();
            //sleep(1);
            if ($dot_count > 10) {
                $dot_count = -1;
            }
        } else {
            echo '<script>document.getElementById("status-1").innerHTML = ' . json_encode('Waiting for encoding to start') . '</script>';
            echo '&nbsp;';
            ob_flush();
<?php

namespace PHPVideoToolkit;

include_once './includes/bootstrap.php';
try {
    $video = new Video($example_video_path);
    //  $process->setProcessTimelimit(1);
    $process = $video->extractSegment(new Timecode(10), new Timecode(20))->save('./output/big_buck_bunny.ogg');
    echo '<h1>Executed Command</h1>';
    Trace::vars($process->getExecutedCommand());
    echo '<hr /><h1>FFmpeg Process Messages</h1>';
    Trace::vars($process->getMessages());
    echo '<hr /><h1>Buffer Output</h1>';
    Trace::vars($process->getBuffer(true));
    echo '<hr /><h1>Resulting Output</h1>';
    Trace::vars($process->getOutput()->getMediaPath());
} 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));
    }
} catch (Exception $e) {
    echo '<h1>Error</h1>';
<?php

namespace PHPVideoToolkit;

include_once './includes/bootstrap.php';
try {
    $video = new Video($example_video_path);
    //  $process->setProcessTimelimit(1);
    $process = $video->extractSegment(new Timecode(10), new Timecode(20))->save('./output/big_buck_bunny.mp3', new AudioFormat_Mp3('output'), Media::OVERWRITE_EXISTING);
    echo '<h1>Executed Command</h1>';
    Trace::vars($process->getExecutedCommand());
    echo '<hr /><h1>FFmpeg Process Messages</h1>';
    Trace::vars($process->getMessages());
    echo '<hr /><h1>Buffer Output</h1>';
    Trace::vars($process->getBuffer(true));
    echo '<hr /><h1>Resulting Output</h1>';
    Trace::vars($process->getOutput()->getMediaPath());
} 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));
    }
} catch (Exception $e) {
    echo '<h1>Error</h1>';