PHP code example of cosmonova-rnd / caspar-cg
1. Go to this page and download the library: Download cosmonova-rnd/caspar-cg 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/ */
cosmonova-rnd / caspar-cg example snippets
$client = new \CosmonovaRnD\CasparCG\Client();
$response = $client->send('play 1-1 test');
if($response->success()) {
echo 'OK';
} else {
echo 'Failed';
}
$client = new \CosmonovaRnD\CasparCG\Client();
$playCmdBuilder = new \CosmonovaRnD\CasparCG\Command\Basic\Builder\PlayBuilder();
$playCmdBuilder->channel(1);
$playCmdBuilder->layer(10);
$playCmdBuilder->clip('test');
$playCmdBuilder->loop();
$response = $client->send($playCmdBuilder->build());
if($response->success()) {
echo 'OK';
} else {
echo 'Failed';
}
$server = new \CosmonovaRnD\CasparCG\Server('127.0.0.1', 6250);
$server->start();
$parser = new \CosmonovaRnD\CasparCG\OSC\Parser();
// You can use simple built-in event manager to handle messages
$eventManager = new \CosmonovaRnD\CasparCG\EventManager();
$listener = new MyTestFrameMsgListener(); // Must implement \CosmonovaRnD\CasparCG\ListenerInterface
// Listen all \CosmonovaRnD\CasparCG\OSC\Message\Producer\FFmpeg\Frame messages
$eventManager->listen(\CosmonovaRnD\CasparCG\OSC\Message\Producer\FFmpeg\Frame::class, $listener);
while (false !== $msg = $server->read()) {
$rawMsg = $parser->parse($msg);
if ($rawMsg instanceof Bundle) {
foreach ($rawMsg->getMessages() as $bundleMsg) {
\CosmonovaRnD\CasparCG\OSC\Message\Producer\FFmpeg\Frame::create($bundleMsg, $eventManager);
}
} else {
\CosmonovaRnD\CasparCG\OSC\Message\Producer\FFmpeg\Frame::create($rawMsg, $eventManager);
}
}
$server->stop();