From b9a6ef84796517427245d3012a873c3eb0af66e7 Mon Sep 17 00:00:00 2001 From: ToshY <31921460+ToshY@users.noreply.github.com> Date: Sun, 2 Mar 2025 15:13:59 +0100 Subject: [PATCH 1/2] Added Stream API endpoints for resolutions, cleanup and output codec --- docs/stream-api.md | 51 +++++++++++++ .../ManageVideos/AddOutputCodecToVideo.php | 29 ++++++++ .../DeleteUnconfiguredResolutions.php | 43 +++++++++++ .../ManageVideos/GetVideoResolutionsInfo.php | 29 ++++++++ src/StreamAPI.php | 73 +++++++++++++++++++ 5 files changed, 225 insertions(+) create mode 100644 src/Model/API/Stream/ManageVideos/AddOutputCodecToVideo.php create mode 100644 src/Model/API/Stream/ManageVideos/DeleteUnconfiguredResolutions.php create mode 100644 src/Model/API/Stream/ManageVideos/GetVideoResolutionsInfo.php diff --git a/docs/stream-api.md b/docs/stream-api.md index a2464d2..d27e1dd 100644 --- a/docs/stream-api.md +++ b/docs/stream-api.md @@ -255,6 +255,24 @@ $streamApi->reEncodeVideo( ); ``` +#### [Add output codec to video](https://docs.bunny.net/reference/video_reencodeusingcodec) + +```php +$streamApi->addOutputCodecToVideo( + libraryId: 1, + videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd', + outputCodecId: 0, +); +``` + +!!! note + + - The argument `outputCodecId` has the following possible values: + - `0` = x264 + - `1` = vp9 + - `2` = hevc + - `3` = av1 + #### [Repackage Video](https://docs.bunny.net/reference/video_repackage) ```php @@ -412,6 +430,39 @@ $streamApi->transcribeVideo( - The `language` is a [two-letter (set 1) language abbreviation](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) for transcribing the video. - Once a video has transcribed you need to set `force` to `true` in order to force a new transcription to be added. +#### [Video resolutions info](https://docs.bunny.net/reference/video_getvideoresolutions) + +```php +$streamApi->videoResolutionsInfo( + libraryId: 1, + videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd', +); +``` + +#### [Cleanup unconfigured resolutions](https://docs.bunny.net/reference/video_deleteresolutions) + +```php +$streamApi->cleanupUnconfiguredResolutions( + libraryId: 1, + videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd', + query: [ + 'resolutionsToDelete' => '240p,360p', + 'deleteNonConfiguredResolutions' => false, + 'deleteOriginal' => false, + 'deleteMp4Files' => false, + 'dryRun' => false, + ], +); +``` + +!!! note + + - The key `resolutionsToDelete` consists of comma separated resolutions. + +!!! tip + + Use the [Video Resolutions Info](#video-resolutions-info) endpoint to retrieve the resolutions for the video. + #### [Get OEmbed](https://docs.bunny.net/reference/oembed_getoembed) ```php diff --git a/src/Model/API/Stream/ManageVideos/AddOutputCodecToVideo.php b/src/Model/API/Stream/ManageVideos/AddOutputCodecToVideo.php new file mode 100644 index 0000000..0978f1b --- /dev/null +++ b/src/Model/API/Stream/ManageVideos/AddOutputCodecToVideo.php @@ -0,0 +1,29 @@ +client->request( + endpoint: $endpoint, + parameters: [$libraryId, $videoId, $outputCodecId], + ); + } + /** * @throws BunnyClientResponseException * @throws ClientExceptionInterface @@ -619,6 +644,54 @@ public function transcribeVideo( ); } + /** + * @throws ClientExceptionInterface + * @throws Exception\BunnyClientResponseException + * @throws Exception\JSONException + * @param int $libraryId + * @param string $videoId + * @return BunnyClientResponseInterface + */ + public function videoResolutionsInfo( + int $libraryId, + string $videoId, + ): BunnyClientResponseInterface { + $endpoint = new GetVideoResolutionsInfo(); + + return $this->client->request( + endpoint: $endpoint, + parameters: [$libraryId, $videoId], + ); + } + + /** + * @throws ClientExceptionInterface + * @throws Exception\BunnyClientResponseException + * @throws Exception\JSONException + * @throws Exception\InvalidTypeForKeyValueException + * @throws Exception\InvalidTypeForListValueException + * @throws Exception\ParameterIsRequiredException + * @param int $libraryId + * @param string $videoId + * @param array $query + * @return BunnyClientResponseInterface + */ + public function cleanupUnconfiguredResolutions( + int $libraryId, + string $videoId, + array $query, + ): BunnyClientResponseInterface { + $endpoint = new DeleteUnconfiguredResolutions(); + + ParameterValidator::validate($query, $endpoint->getQuery()); + + return $this->client->request( + endpoint: $endpoint, + parameters: [$libraryId, $videoId], + query: $query, + ); + } + /** * @throws ClientExceptionInterface * @throws Exception\BunnyClientResponseException From dab141ff1f07352f8f30b8a0a15826d10b6ce64c Mon Sep 17 00:00:00 2001 From: ToshY <31921460+ToshY@users.noreply.github.com> Date: Sun, 2 Mar 2025 16:18:26 +0100 Subject: [PATCH 2/2] [docs] stream api premium encoding feature needs to be enabled for outputCodecId to work --- docs/stream-api.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/stream-api.md b/docs/stream-api.md index d27e1dd..ec529f4 100644 --- a/docs/stream-api.md +++ b/docs/stream-api.md @@ -261,7 +261,7 @@ $streamApi->reEncodeVideo( $streamApi->addOutputCodecToVideo( libraryId: 1, videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd', - outputCodecId: 0, + outputCodecId: 2, ); ``` @@ -269,9 +269,13 @@ $streamApi->addOutputCodecToVideo( - The argument `outputCodecId` has the following possible values: - `0` = x264 - - `1` = vp9 - - `2` = hevc - - `3` = av1 + - `1` = vp9 (premium) + - `2` = hevc (premium) + - `3` = av1 (premium) + +!!! warning + + This endpoint will return a `400` status code if premium encoding is not enabled (even if the `outputCodecId` value `0` is given). #### [Repackage Video](https://docs.bunny.net/reference/video_repackage) @@ -463,6 +467,10 @@ $streamApi->cleanupUnconfiguredResolutions( Use the [Video Resolutions Info](#video-resolutions-info) endpoint to retrieve the resolutions for the video. +!!! warning + + This endpoint will return a `400` status code if all available resolutions for the video are passed to `resolutionsToDelete`, as there must be at least one resolution available after cleanup. + #### [Get OEmbed](https://docs.bunny.net/reference/oembed_getoembed) ```php