PHP code example of vimqu / php-sdk

1. Go to this page and download the library: Download vimqu/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vimqu / php-sdk example snippets


use Vimqu\Vimqu\Task\TaskManager;
use Vimqu\Vimqu\Outputs\VideoOutput;

$task = TaskManager::withToken('your_access_token')
    ->setInputFromStorage('your_storage_id', '/birds.mp4');
	// or
    ->setInputFromUrl('https://<your_file>.mp4');

$video = (new VideoOutput('h264', 'mp4'))
    ->setStorage('your_storage_id', '/outputs/videos')
    ->setReferenceId('your_reference_id')
    ->subtitle(true)
    ->resize(300, null)
    ->clip(2, duration: 45)
    ->crop(300, 300, 15, 15);

$task->addOutput($video);
$result = $task->send();

$status = $result->getStatus(); // the status will be "active".
$id = $result->getId(); 

use Vimqu\Vimqu\Task\Search;

// This query will give you the "TaskDto" instance again.
$task = Search::withToken('xxxx xxxx')->getById($id);


use Vimqu\Vimqu\Outputs\HlsOutput;

$hls = (new HlsOutput)
    ->setStorage('your_storage_id', '/outputs/hls')
    ->setReferenceId('your_reference_id')
    ->subtitle(true)
    ->clip(2, 45)
    ->crop(300, 300, 15, 15)
    ->overlayImage('https://your_overlay_image.png', 50, 50, 0, 20)
    ->addVariant('240p')
    ->addVariant('480p')
    ->addVariant('720p')
    ->addVariant('1080p');

// $task is instance of TaskManager, we created it before.
$task->addOutput($hls);
$task->send();

use Vimqu\Vimqu\Outputs\DashOutput;

$dash = (new DashOutput)
    ->setStorage('your_storage_id', '/outputs/dash')
    ->setReferenceId('your_reference_id')
    ->subtitle(true)
    ->clip(2, 45)
    ->crop(300, 300, 15, 15)
    ->addVariant('720p')
    ->addVariant('1080p');

$task->addOutput($dash);
$task->send();

use Vimqu\Vimqu\Outputs\VideoOutput;

$video = (new VideoOutput('h264', 'mp4'))
    ->setStorage('your_storage_id', '/outputs/videos')
    ->setReferenceId('your_reference_id')
    ->subtitle(true)
    ->resize(300, null)
    ->clip(2, duration: 45)
    ->crop(300, 300, 15, 15);

$task->addOutput($video);
$task->send();

use Vimqu\Vimqu\Outputs\ThumbnailBySeconds;

$thumbnailBySeconds = (new ThumbnailBySeconds([4, 22, 400, 650]))
    ->setStorage('your_storage_id', '/outputs/thumbnails/seconds')
    ->setReferenceId('your_reference_id')
    ->resize(300, null);

$task->addOutput($thumbnailBySeconds);
$task->send();

use Vimqu\Vimqu\Outputs\ThumbnailByNumber;

$thumbnailByNumber = (new ThumbnailByNumber(5, 'jpg'))
    ->setStorage('your_storage_id', '/outputs/thumbnails/number')
    ->setReferenceId('your_reference_id')
    ->resize(300, 500, true);

$task->addOutput($thumbnailByNumber);
$task->send();

use Vimqu\Vimqu\Outputs\ThumbnailByInterval;

$thumbnailByInterval = (new ThumbnailByInterval(10, 'png'))
    ->setStorage('your_storage_id', '/outputs/thumbnails/interval')
    ->setReferenceId('your_reference_id')
    ->resize(null, 150);

$task->addOutput($thumbnailByInterval);
$task->send();

use Vimqu\Vimqu\Storage;

$storages = Storage::withToken($token)->all();
// [
//    [
//         'name' => 'my_storage',
//         'id' => 'xxxx xxxx xxxx',
//         'driver' => 's3' // it can be ftp, gcs, azure
//    ]
// ]

use Vimqu\Vimqu\Task\Search;

$tasks = Search::withToken($token)->search();

$tasks = Search::withToken($token)->search(
	['hls', 'thumbnail', 'dash'],
	'your_reference_id',
	'completed'
);

foreach($tasks as $task) {

    $taskStatus = $task->getStatus();
    $id = $task->getId();

    foreach($task->getOutputs() as $output) {

        $reference = $output->getReferenceId();

        foreach($output->getFiles() as $file){
            $filePath = $file->getPath();
        }
    }
}