PHPackages                             cranbri/livepeer-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. cranbri/livepeer-laravel

ActiveLibrary[API Development](/categories/api)

cranbri/livepeer-laravel
========================

Laravel integration for Livepeer Studio API

027PHPCI passing

Since May 9Pushed 1y agoCompare

[ Source](https://github.com/cranbri/livepeer-laravel)[ Packagist](https://packagist.org/packages/cranbri/livepeer-laravel)[ RSS](/packages/cranbri-livepeer-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Livepeer Laravel
================

[](#livepeer-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/589782f69facb3dc5d2a9c80801d1dcdc5b9574b248b1c868e86da5da12bc9f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372616e6272692f6c697665706565722d6c61726176656c2e737667)](https://packagist.org/packages/cranbri/livepeer-laravel)[![Total Downloads](https://camo.githubusercontent.com/7af42b035480e304ef8e6e6e1b86c66c0dad78752c5c0ae57952bfa0f0ddc1ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6372616e6272692f6c697665706565722d6c61726176656c2e737667)](https://packagist.org/packages/cranbri/livepeer-laravel)[![License](https://camo.githubusercontent.com/6e082e8e175da2733d8a75b9207cc3028f738ac3cc0bcd6b6ebf8136eda4d57e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6372616e6272692f6c697665706565722d6c61726176656c)](LICENSE.md)

A Laravel integration for the [Livepeer Studio API](https://docs.livepeer.org/reference/api/overview). This package provides a convenient way to integrate Livepeer's video streaming and processing services into your Laravel application, including webhook handling.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Basic Usage](#basic-usage)
    - [Working with Assets](#working-with-assets)
    - [Working with Livestreams](#working-with-livestreams)
    - [Working with Multistreaming](#working-with-multistreaming)
    - [Working with Sessions and Playback](#working-with-sessions-and-playback)
    - [Working with Webhooks](#working-with-webhooks)
    - [Working with Access Control](#working-with-access-control)
    - [Working with Analytics](#working-with-analytics)
- [Webhook Jobs](#webhook-jobs)
    - [Generating Webhook Job Classes](#generating-webhook-job-classes)
    - [Automatic Config Updates](#automatic-config-updates)
    - [Available Webhook Events](#available-webhook-events)
- [Advanced Usage](#advanced-usage)
    - [Stream Profiles](#stream-profiles)
    - [Playback Policies](#playback-policies)
    - [Error Handling](#error-handling)
    - [Custom HTTP Client](#custom-http-client)
- [Testing](#testing)
- [Contributing](#contributing)
- [Credits &amp; Acknowledgements](#credits-and-acknowledgements)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require cranbri/livepeer-laravel
```

The package will automatically register the service provider and facade.

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Cranbri\Laravel\Livepeer\LivepeerServiceProvider" --tag="livepeer-config"
```

Add your Livepeer API key to your `.env` file:

```
LIVEPEER_API_KEY=your-api-key

```

If you plan to use webhooks, also add a webhook signing secret:

```
LIVEPEER_WEBHOOK_SECRET=your-webhook-signing-secret

```

Next, you must publish the migration with:

```
php artisan vendor:publish --provider="Spatie\WebhookClient\WebhookClientServiceProvider" --tag="webhook-client-migrations"
```

After the migration has been published you can create the `webhook_calls` table by running the migrations:

```
php artisan migrate
```

Finally, take care of the routing: In the Livepeer dashboard you must configure at what url Livepeer webhooks should hit your app. In the routes file of your app you must pass that route to `Route::livepeerWebhooks`:

```
Route::livepeerWebhooks('webhooks/livepeer');
```

Behind the scenes this will register a `POST` route to a controller provided by this package. Because Livepeer has no way of getting a csrf-token, you must add that route to the `except` array of the `VerifyCsrfToken` middleware:

```
// Laravel 11+
$middleware->validateCsrfTokens(except: [
    'webhooks/*',
]);
```

```
// Laravel 10 and lower
protected $except = [
    'webhooks/livepeer',
];
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

This package provides a Facade for easy access to the Livepeer API:

```
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

// List all assets
$assets = Livepeer::listAssets();

// Get a specific asset
$asset = Livepeer::getAsset('asset-id');
```

You can also inject the Livepeer client directly:

```
use Cranbri\Livepeer\Livepeer;

class VideoController extends Controller
{
    public function index(Livepeer $livepeer)
    {
        $assets = $livepeer->listAssets();

        return view('videos.index', compact('assets'));
    }
}
```

### Working with Assets

[](#working-with-assets)

Upload an asset from a URL:

```
use Cranbri\Livepeer\Data\Asset\UrlUploadAssetData;
use Cranbri\Livepeer\Data\PlaybackPolicyData;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

$data = new UrlUploadAssetData(
    name: 'My Video',
    url: 'https://example.com/video.mp4',
    playbackPolicy: PlaybackPolicyData::public()
);

$response = Livepeer::uploadAssetFromUrl($data);
```

Request an upload URL for direct upload:

```
use Cranbri\Livepeer\Data\Asset\UploadAssetData;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

$data = new UploadAssetData(
    name: 'My Video',
    staticMp4: true
);

$response = Livepeer::requestAssetUpload($data);

// The response contains the upload URL and asset details
$uploadUrl = $response['url'];
$assetId = $response['asset']['id'];
```

Update an asset:

```
use Cranbri\Livepeer\Data\Asset\UpdateAssetData;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

$data = new UpdateAssetData(name: 'Updated Video Name');
$response = Livepeer::updateAsset('asset-id', $data);
```

Delete an asset:

```
$response = Livepeer::deleteAsset('asset-id');
```

### Working with Livestreams

[](#working-with-livestreams)

Create a new livestream:

```
use Cranbri\Livepeer\Data\Livestream\CreateLivestreamData;
use Cranbri\Livepeer\Data\PlaybackPolicyData;
use Cranbri\Livepeer\Data\StreamProfileData;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

$data = new CreateLivestreamData(
    name: 'My Livestream',
    playbackPolicy: PlaybackPolicyData::public(),
    profiles: [
        StreamProfileData::hd720(),
        StreamProfileData::sd480()
    ],
    record: true
);

$response = Livepeer::createLivestream($data);

// The response contains stream details
$streamId = $response['id'];
$streamKey = $response['streamKey'];
$playbackId = $response['playbackId'];
```

List all livestreams:

```
$livestreams = Livepeer::listLivestreams();

// With filters
$activeStreams = Livepeer::listLivestreams([
    'streamsonly' => true,
    'filters' => ['active']
]);
```

Update a livestream:

```
use Cranbri\Livepeer\Data\Livestream\UpdateLivestreamData;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

$data = new UpdateLivestreamData(
    name: 'Updated Stream Name',
    record: true
);

$response = Livepeer::updateLivestream('stream-id', $data);
```

Terminate a livestream:

```
$response = Livepeer::terminateLivestream('stream-id');
```

Create a clip from a livestream:

```
use Cranbri\Livepeer\Data\Livestream\CreateClipData;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

$data = new CreateClipData(
    playbackId: 'playback-id',
    startTime: 60000,  // in milliseconds
    endTime: 120000,   // in milliseconds
    name: 'My Clip'
);

$response = Livepeer::createClip($data);
```

### Working with Multistreaming

[](#working-with-multistreaming)

Create a multistream target:

```
use Cranbri\Livepeer\Data\Multistream\CreateTargetData;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

$data = new CreateTargetData(
    url: 'rtmp://example.com/live',
    name: 'YouTube Target'
);

$response = Livepeer::createMultistreamTarget($data);
```

Add a multistream target to a livestream:

```
use Cranbri\Livepeer\Data\AddMultistreamTargetData;
use Cranbri\Livepeer\Data\Livestream\CreateMultistreamTargetData;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

// Use an existing target
$data = new AddMultistreamTargetData(
    profile: 'source',
    id: 'target-id'
);

// Or create a new target inline
$data = new AddMultistreamTargetData(
    profile: 'source',
    spec: new CreateMultistreamTargetData(
        url: 'rtmp://example.com/live',
        name: 'Facebook Target'
    )
);

$response = Livepeer::addMultistreamTarget('stream-id', $data);
```

Remove a multistream target:

```
$response = Livepeer::removeMultistreamTarget('stream-id', 'target-id');
```

### Working with Sessions and Playback

[](#working-with-sessions-and-playback)

Get session details:

```
$session = Livepeer::getSession('session-id');
```

List all sessions:

```
$sessions = Livepeer::listSessions();
```

List recorded sessions for a stream:

```
$recordedSessions = Livepeer::listRecordedSessions('stream-id');
```

Get playback information:

```
$playbackInfo = Livepeer::getPlaybackInfo('playback-id');
```

### Working with Webhooks

[](#working-with-webhooks)

Register a webhook endpoint in your routes:

```
// routes/web.php or routes/api.php
Route::livepeerWebhooks('webhooks/livepeer');
```

Create a webhook in Livepeer pointing to your endpoint:

```
use Cranbri\Livepeer\Data\Webhook\CreateWebhookData;
use Cranbri\Livepeer\Enums\WebhookEvent;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

$data = new CreateWebhookData(
    name: 'My Webhook',
    url: 'https://example.com/webhooks/livepeer',
    events: [
        WebhookEvent::STREAM_STARTED,
        WebhookEvent::STREAM_IDLE,
        WebhookEvent::RECORDING_READY
    ]
);

$response = Livepeer::createWebhook($data);
```

Update a webhook:

```
use Cranbri\Livepeer\Data\Webhook\UpdateWebhookData;
use Cranbri\Livepeer\Enums\WebhookEvent;

$data = new UpdateWebhookData(
    name: 'Updated Webhook',
    url: 'https://example.com/webhooks/livepeer',
    events: [
        WebhookEvent::STREAM_STARTED,
        WebhookEvent::STREAM_IDLE,
        WebhookEvent::RECORDING_READY,
        WebhookEvent::ASSET_READY
    ]
);

$response = Livepeer::updateWebhook('webhook-id', $data);
```

List all webhooks:

```
$webhooks = Livepeer::listWebhooks();
```

Delete a webhook:

```
$response = Livepeer::deleteWebhook('webhook-id');
```

### Working with Access Control

[](#working-with-access-control)

Create a signing key:

```
$key = Livepeer::createSigningKey();
```

List signing keys:

```
$keys = Livepeer::listSigningKeys();
```

Update a signing key:

```
use Cranbri\Livepeer\Data\AccessControl\UpdateSigningKeyData;

$data = new UpdateSigningKeyData(
    name: 'Updated Key',
    disabled: false
);

$response = Livepeer::updateSigningKey('key-id', $data);
```

### Working with Analytics

[](#working-with-analytics)

Query realtime viewership:

```
$viewers = Livepeer::queryRealtimeViewership([
    'playbackId' => 'playback-id',
    'breakdownBy' => 'country'
]);
```

Query viewership metrics:

```
$viewershipMetrics = Livepeer::queryViewershipMetrics([
    'fromTime' => '2024-01-01T00:00:00Z',
    'toTime' => '2024-01-31T23:59:59Z',
    'playbackId' => 'playback-id',
    'breakdownBy' => 'browser'
]);
```

Query usage metrics:

```
$usageMetrics = Livepeer::queryUsageMetrics([
    'fromTime' => '2024-01-01T00:00:00Z',
    'toTime' => '2024-01-31T23:59:59Z',
    'timeStep' => '1d'
]);
```

Webhook Jobs
------------

[](#webhook-jobs)

This package includes a convenient command to generate job classes for handling Livepeer webhook events.

### Generating Webhook Job Classes

[](#generating-webhook-job-classes)

To generate job classes for handling Livepeer webhook events, run:

```
php artisan livepeer:webhook-jobs
```

This will prompt you to select which webhook events you want to generate job classes for. You can select multiple events by providing a comma-separated list of numbers.

To generate job classes for all webhook events:

```
php artisan livepeer:webhook-jobs --all
```

By default, the job classes will be created in the `app/Jobs/Livepeer` directory. You can specify a custom path using the `--path` option:

```
php artisan livepeer:webhook-jobs --path=app/Jobs/Custom/Path
```

You can also specify a custom namespace for the job classes:

```
php artisan livepeer:webhook-jobs --namespace="App\\Jobs\\CustomNamespace"
```

### Automatic Config Updates

[](#automatic-config-updates)

The command can automatically update your `config/livepeer.php` file to register the generated job classes:

```
php artisan livepeer:webhook-jobs --auto-update-config
```

This will add or update the `webhook_jobs` array in your config file with the appropriate class mappings.

You can combine multiple options:

```
php artisan livepeer:webhook-jobs --all --auto-update-config --path=app/Jobs/Custom
```

If you don't use the `--auto-update-config` flag, the command will ask if you want to update the config file automatically after generating the job classes.

### Available Webhook Events

[](#available-webhook-events)

Livepeer supports the following webhook events:

- `stream.started` - Fired when a livestream starts
- `stream.idle` - Fired when a livestream becomes idle
- `recording.ready` - Fired when a recording is ready
- `recording.started` - Fired when a recording starts
- `recording.waiting` - Fired when a recording is waiting
- `multistream.connected` - Fired when a multistream target connects
- `multistream.error` - Fired when there's an error with a multistream target
- `multistream.disconnected` - Fired when a multistream target disconnects
- `playback.accessControl` - Fired for playback access control events
- `asset.created` - Fired when an asset is created
- `asset.updated` - Fired when an asset is updated
- `asset.failed` - Fired when asset processing fails
- `asset.ready` - Fired when an asset is ready
- `asset.deleted` - Fired when an asset is deleted
- `task.spawned` - Fired when a task is spawned
- `task.updated` - Fired when a task is updated
- `task.completed` - Fired when a task is completed
- `task.failed` - Fired when a task fails

Advanced Usage
--------------

[](#advanced-usage)

### Stream Profiles

[](#stream-profiles)

Livepeer allows you to specify transcoding profiles for your streams:

```
use Cranbri\Livepeer\Data\StreamProfileData;
use Cranbri\Livepeer\Enums\EncoderType;

// Use predefined profiles
$profiles = [
    StreamProfileData::hd720(),
    StreamProfileData::sd480(),
    StreamProfileData::hd1080(),
    StreamProfileData::uhd4k()
];

// Or create custom profiles
$customProfile = new StreamProfileData(
    bitrate: 2500000,
    name: 'custom-720p',
    width: 1280,
    height: 720,
    fps: 30,
    encoder: EncoderType::H264
);
```

### Playback Policies

[](#playback-policies)

Control who can access your content with playback policies:

```
use Cranbri\Livepeer\Data\PlaybackPolicyData;
use Cranbri\Livepeer\Enums\PlaybackPolicyType;

// Public playback (default)
$publicPolicy = PlaybackPolicyData::public();

// JWT playback (requires signing key)
$jwtPolicy = PlaybackPolicyData::jwt();

// Webhook playback
$webhookPolicy = PlaybackPolicyData::webhook(
    webhookId: 'webhook-id',
    webhookContext: ['user' => 'user-123']
);

// With custom allowed origins
$customPolicy = new PlaybackPolicyData(
    type: PlaybackPolicyType::PUBLIC,
    allowedOrigins: ['https://example.com', 'https://app.example.com']
);
```

### Error Handling

[](#error-handling)

All API errors are converted to `LivepeerException` instances:

```
use Cranbri\Livepeer\Exceptions\LivepeerException;
use Cranbri\Laravel\Livepeer\Facades\Livepeer;

try {
    $asset = Livepeer::getAsset('invalid-asset-id');
} catch (LivepeerException $e) {
    report($e);

    return back()->withError('Unable to retrieve asset: ' . $e->getMessage());
}
```

For webhook errors, the package includes a `WebhookFailed` exception:

```
use Cranbri\Laravel\Livepeer\Exceptions\WebhookFailed;

try {
    // Process webhook
} catch (WebhookFailed $e) {
    report($e);

    return response()->json(['error' => $e->getMessage()], 400);
}
```

Testing
-------

[](#testing)

```
composer test
```

Credits and Acknowledgements
----------------------------

[](#credits-and-acknowledgements)

### Webhook Implementation

[](#webhook-implementation)

The webhook handling functionality in this package is heavily inspired by [Spatie's Laravel Stripe Webhooks](https://github.com/spatie/laravel-stripe-webhooks) package. We've adapted their excellent approach specifically for Livepeer webhooks, building on their proven architecture for secure and reliable webhook processing.

Key features adapted from Spatie's Stripe webhook implementation include:

- Secure webhook signature validation
- Queued webhook processing
- Webhook storage and retry functionality
- Job-based architecture for processing webhook events

Our implementation uses [Spatie's Laravel Webhook Client](https://github.com/spatie/laravel-webhook-client) as its foundation, which is the same underlying library that powers their Stripe webhooks package.

We highly recommend checking out Spatie's other Laravel packages at [spatie.be/open-source](https://spatie.be/open-source).

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Tom Burman](https://github.com/just-tom)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9d47d3153558ce1f9e345d91e2a0421eeecbbb433587b08134ccb88559d8c87?d=identicon)[just-tom](/maintainers/just-tom)

### Embed Badge

![Health badge](/badges/cranbri-livepeer-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/cranbri-livepeer-laravel/health.svg)](https://phpackages.com/packages/cranbri-livepeer-laravel)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M271](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[microsoft/microsoft-graph

The Microsoft Graph SDK for PHP

65723.5M96](/packages/microsoft-microsoft-graph)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
