Here is the code I’m using to trim the video:
<?php
require 'vendor/autoload-2.php';
include("config.php");
use Shotstack\Client\Api\EditApi;
use Shotstack\Client\Configuration;
use Shotstack\Client\Model\Edit;
use Shotstack\Client\Model\Output;
use Shotstack\Client\Model\Timeline;
use Shotstack\Client\Model\Track;
use Shotstack\Client\Model\Clip;
use Shotstack\Client\Model\VideoAsset;
$stime = $_POST['stime'];
$etime = $_POST['etime'];
$userID = $_POST['userID'];
$videoURL = $_POST['videoURL'];
$videoKey = $_POST['videoKey'];
$source = str_replace(' ', '%20', $videoURL);
$vidLength = $etime - $stime;
class TrimDemo
{
protected $apiKey;
protected $apiUrl = 'https://api.shotstack.io/stage';
public function __construct()
{
$this->apiKey = 'MY API KEY';
}
public function render()
{
$config = Configuration::getDefaultConfiguration()
->setHost($this->apiUrl)
->setApiKey('x-api-key', $this->apiKey);
echo $this->apiUrl.'<br>';
echo $this->apiKey.'<br><br>';
$client = new EditApi(null, $config);
$videoAsset = new VideoAsset();
$videoAsset
->setSrc($GLOBALS['source'])
->setTrim($GLOBALS['stime']);
$videoClip = new Clip();
$videoClip
->setAsset($videoAsset)
->setLength($GLOBALS['vidLength'])
->setStart(0);
$track = new Track();
$track->setClips([$videoClip]);
$timeline = new Timeline();
$timeline->setTracks([$track]);
$output = new Output();
$output
->setFormat('mp4')
->setResolution('hd');
$edit = new Edit();
$edit
->setTimeline($timeline)
->setOutput($output);
try {
$response = $client->postRender($edit)->getResponse();
} catch (Exception $e) {
die('Request failed: ' . $e->getMessage());
}
$video = $client->getRender($response->getId())->getResponse();
if ($video->getStatus() === 'done') {
echo $video->getUrl().'<br>';
}
global $videoID;
$videoID = $response->getId();
}
}
$editor = new TrimDemo();
$editor->render();
$finalID = $videoID;
?>
I’m getting the following error thrown at me:
Request failed: [400] Client error: POST https://api.shotstack.io/stage/render
resulted in a 400 Bad Request
response: {“success”:true,“message”:“Bad Request”,“response”:{“error”:{“name”:“ValidationError”,“details”:[{“message”:"“trim” mu (truncated…)
Can anyone please help?