api.video is an API that encodes on the go to facilitate immediate playback, enhancing viewer streaming experiences across multiple devices and platforms. You can stream live or on-demand online videos within minutes.
composer require api-video/php-api-client
Due to PHP PSR support, you must initialize the client with 3 to 5 arguments:
- Base URI, which can be either
https://sandbox.api.video
orhttps://ws.api.video
- Your API key, available on your account
- HTTP client
- (Request factory)
- (Stream factory)
Note : If the HTTP client also implements RequestFactoryInterface and StreamFactoryInterface, then it is not necessary to pass this object in 4th and 5th argument.
The Symfony HTTP client has the triple advantage of playing the role of HTTP client, but also of request factory and stream factory. It is therefore sufficient to pass it as an argument 3 times.
$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new \ApiVideo\Client(
'https://sandbox.api.video',
'YOUR_API_TOKEN',
$httpClient
);
Some endpoints don't require authentication. These one can be called with a Client instantiated with a null
API token:
$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new \ApiVideo\Client(
'https://sandbox.api.video',
null,
$httpClient
);
In the following examples the $client
must already be initialized.
$payload = (new VideoCreationPayload())
->setTitle('Test video creation');
$video = $client->videos()->create($payload);
$payload = (new VideoCreationPayload())
->setTitle('Test video creation');
$video = $client->videos()->create($payload);
$this->client->videos()->upload(
$video->getVideoId(),
new SplFileObject(__DIR__.'/../earth.mp4')
);
The video is automatically split into 1 Mb chunks.
To modify the size of the chunks, fill in the last argument $contentRange
as follows:
bytes 0-{size}/0
where{size}
is the size of the chunk.
For example : bytes 0-500000/0
for 500 Kb chunks.
All URIs are relative to https://ws.api.video
.
// The $client must already be initialized
$captions = $client->captions();
Method | HTTP request | Description |
---|---|---|
delete | DELETE /videos/{videoId}/captions/{language} |
Delete a caption |
list | GET /videos/{videoId}/captions |
List video captions |
get | GET /videos/{videoId}/captions/{language} |
Show a caption |
update | PATCH /videos/{videoId}/captions/{language} |
Update caption |
upload | POST /videos/{videoId}/captions/{language} |
Upload a caption |
// The $client must already be initialized
$chapters = $client->chapters();
Method | HTTP request | Description |
---|---|---|
delete | DELETE /videos/{videoId}/chapters/{language} |
Delete a chapter |
list | GET /videos/{videoId}/chapters |
List video chapters |
get | GET /videos/{videoId}/chapters/{language} |
Show a chapter |
upload | POST /videos/{videoId}/chapters/{language} |
Upload a chapter |
// The $client must already be initialized
$liveStreams = $client->liveStreams();
Method | HTTP request | Description |
---|---|---|
delete | DELETE /live-streams/{liveStreamId} |
Delete a live stream |
deleteThumbnail | DELETE /live-streams/{liveStreamId}/thumbnail |
Delete a thumbnail |
list | GET /live-streams |
List all live streams |
get | GET /live-streams/{liveStreamId} |
Show live stream |
update | PATCH /live-streams/{liveStreamId} |
Update a live stream |
create | POST /live-streams |
Create live stream |
uploadThumbnail | POST /live-streams/{liveStreamId}/thumbnail |
Upload a thumbnail |
// The $client must already be initialized
$playerThemes = $client->playerThemes();
Method | HTTP request | Description |
---|---|---|
delete | DELETE /players/{playerId} |
Delete a player |
deleteLogo | DELETE /players/{playerId}/logo |
Delete logo |
list | GET /players |
List all players |
get | GET /players/{playerId} |
Show a player |
update | PATCH /players/{playerId} |
Update a player |
create | POST /players |
Create a player |
uploadLogo | POST /players/{playerId}/logo |
Upload a logo |
// The $client must already be initialized
$rawStatistics = $client->rawStatistics();
Method | HTTP request | Description |
---|---|---|
listLiveStreamSessions | GET /analytics/live-streams/{liveStreamId} |
List live stream player sessions |
listSessionEvents | GET /analytics/sessions/{sessionId}/events |
List player session events |
listVideoSessions | GET /analytics/videos/{videoId} |
List video player sessions |
// The $client must already be initialized
$uploadTokens = $client->uploadTokens();
Method | HTTP request | Description |
---|---|---|
deleteToken | DELETE /upload-tokens/{uploadToken} |
Delete an upload token |
list | GET /upload-tokens |
List all active upload tokens. |
getToken | GET /upload-tokens/{uploadToken} |
Show upload token |
createToken | POST /upload-tokens |
Generate an upload token |
// The $client must already be initialized
$videos = $client->videos();
Method | HTTP request | Description |
---|---|---|
delete | DELETE /videos/{videoId} |
Delete a video |
get | GET /videos/{videoId} |
Show a video |
getStatus | GET /videos/{videoId}/status |
Show video status |
list | GET /videos |
List all videos |
update | PATCH /videos/{videoId} |
Update a video |
pickThumbnail | PATCH /videos/{videoId}/thumbnail |
Pick a thumbnail |
uploadWithUploadToken | POST /upload |
Upload with an upload token |
create | POST /videos |
Create a video |
upload | POST /videos/{videoId}/source |
Upload a video |
uploadThumbnail | POST /videos/{videoId}/thumbnail |
Upload a thumbnail |
// The $client must already be initialized
$webhooks = $client->webhooks();
Method | HTTP request | Description |
---|---|---|
delete | DELETE /webhooks/{webhookId} |
Delete a Webhook |
get | GET /webhooks/{webhookId} |
Show Webhook details |
list | GET /webhooks |
List all webhooks |
create | POST /webhooks |
Create Webhook |
- AccessToken
- Account
- AccountQuota
- AuthenticatePayload
- BadRequest
- BytesRange
- Caption
- CaptionsListResponse
- CaptionsUpdatePayload
- Chapter
- ChaptersListResponse
- Link
- LiveStream
- LiveStreamAssets
- LiveStreamCreationPayload
- LiveStreamListResponse
- LiveStreamSession
- LiveStreamSessionClient
- LiveStreamSessionDevice
- LiveStreamSessionLocation
- LiveStreamSessionReferrer
- LiveStreamSessionSession
- LiveStreamUpdatePayload
- Metadata
- NotFound
- Pagination
- PaginationLink
- PlayerSessionEvent
- PlayerTheme
- PlayerThemeAssets
- PlayerThemeCreationPayload
- PlayerThemeUpdatePayload
- PlayerThemesListResponse
- Quality
- RawStatisticsListLiveStreamAnalyticsResponse
- RawStatisticsListPlayerSessionEventsResponse
- RawStatisticsListSessionsResponse
- RefreshTokenPayload
- TokenCreationPayload
- TokenListResponse
- UploadToken
- Video
- VideoAssets
- VideoCreationPayload
- VideoSession
- VideoSessionClient
- VideoSessionDevice
- VideoSessionLocation
- VideoSessionOs
- VideoSessionReferrer
- VideoSessionSession
- VideoSource
- VideoSourceLiveStream
- VideoSourceLiveStreamLink
- VideoStatus
- VideoStatusEncoding
- VideoStatusEncodingMetadata
- VideoStatusIngest
- VideoThumbnailPickPayload
- VideoUpdatePayload
- VideosListResponse
- Webhook
- WebhooksCreationPayload
- WebhooksListResponse
In order to run the PhpUnit tests, it is necessary to enter two variables in the command line:
BASE_URI
(for example :https://sandbox.api.video
)API_KEY
These identifiers must belong to a real Api.video account.
$ BASE_URI="" API_KEY="..." vendor/bin/phpunit