/mux-php

Official Mux API wrapper for PHP projects, supporting both Mux Data and Mux Video.

Primary LanguagePHPMIT LicenseMIT

Mux PHP Banner

Mux PHP

Official Mux API wrapper for PHP projects, supporting both Mux Data and Mux Video.

Mux Video is an API-first platform, powered by data and designed by video experts to make beautiful video possible for every development team.

Mux Data is a platform for monitoring your video streaming performance with just a few lines of code. Get in-depth quality of service analytics on web, mobile, and OTT devices.

Not familiar with Mux? Check out https://mux.com/ for more information.

Requirements

PHP 7.1 or higher. Dependencies are managed using composer.

Installation

We publish Mux PHP to Packagist. You should depend on Mux PHP by adding us to your composer.json:

    {
        "require": {
            "muxinc/mux-php": ">=0.0.1"
        }
    }

Then install your dependencies:

    composer install

And then autoload in your code:

    require_once 'vendor/autoload.php';

Manual Installation

PLEASE NOTE: We don't really recommend manual installation and our ability to help if this route doesn't work is minimal. We include this mostly for purposes of completeness.

Download the files and include autoload.php:

<?php
require_once('/path/to/MuxPhp/vendor/autoload.php');

Getting Started

Overview

Mux PHP is a code generated lightweight wrapper around the Mux REST API and reflects them accurately. This has a few consequences you should watch out for:

  1. For almost all API responses, the object you're looking for will be in the data field on the API response object, as in the example below. This is because we designed our APIs with similar concepts to the JSON:API standard. This means we'll be able to return more metadata from our API calls (such as related entities) without the need to make breaking changes to our APIs. We've decided not to hide that in this library.

  2. We don't use a lot of object orientation. For example API calls that happen on a single asset don't exist in the asset class, but are API calls in the AssetsApi which require an asset ID.

Authentication

To use the Mux API, you'll need an access token and a secret. Details on obtaining these can be found here in the Mux documentation.

Its up to you to manage your token and secret. In our examples, we read them from MUX_TOKEN_ID and MUX_TOKEN_SECRET in your environment.

Example Usage

Below is a quick example of using mux-php to ingest a new Video in your Mux account.

    // Authentication Setup
    $config = MuxPhp\Configuration::getDefaultConfiguration()
        ->setUsername(getenv('MUX_TOKEN_ID'))
        ->setPassword(getenv('MUX_TOKEN_SECRET'));

    // API Client Initialization
    $assetsApi = new MuxPhp\Api\AssetsApi(
        new GuzzleHttp\Client(),
        $config
    );

    // Create Asset Request
    $input = new MuxPhp\Models\InputSettings(["url" => "https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4"]);
    $createAssetRequest = new MuxPhp\Models\CreateAssetRequest(["input" => $input, "playback_policy" => [MuxPhp\Models\PlaybackPolicy::PUBLIC_PLAYBACK_POLICY] ]);

    // Ingest
    $result = $assetsApi->createAsset($createAssetRequest);

    // Print URL
    print "Playback URL: https://stream.mux.com/" . $result->getData()->getPlaybackIds()[0]->getId() . ".m3u8\n"

Be sure to also checkout the examples directory:

There's also example usage of every API call (also used for testing):

Documentation

Be sure to check out the documentation in the docs directory.

Issues

If you run into problems, please raise a GitHub issue. We'll take a look as soon as possible.

Contributing

We now accept PRs against this package! Please make your modifications to the templates in gen/templates, not the code itself, or please open an issue.

License

MIT License. Copyright 2019 Mux, Inc.

API Endpoints

All URIs are relative to https://api.mux.com

Class Method HTTP request Description
AssetsApi createAsset POST /video/v1/assets Create an asset
AssetsApi createAssetPlaybackId POST /video/v1/assets/{ASSET_ID}/playback-ids Create a playback ID
AssetsApi createAssetTrack POST /video/v1/assets/{ASSET_ID}/tracks Create an asset track
AssetsApi deleteAsset DELETE /video/v1/assets/{ASSET_ID} Delete an asset
AssetsApi deleteAssetPlaybackId DELETE /video/v1/assets/{ASSET_ID}/playback-ids/{PLAYBACK_ID} Delete a playback ID
AssetsApi deleteAssetTrack DELETE /video/v1/assets/{ASSET_ID}/tracks/{TRACK_ID} Delete an asset track
AssetsApi getAsset GET /video/v1/assets/{ASSET_ID} Retrieve an asset
AssetsApi getAssetInputInfo GET /video/v1/assets/{ASSET_ID}/input-info Retrieve asset input info
AssetsApi getAssetPlaybackId GET /video/v1/assets/{ASSET_ID}/playback-ids/{PLAYBACK_ID} Retrieve a playback ID
AssetsApi listAssets GET /video/v1/assets List assets
AssetsApi updateAssetMasterAccess PUT /video/v1/assets/{ASSET_ID}/master-access Update master access
AssetsApi updateAssetMp4Support PUT /video/v1/assets/{ASSET_ID}/mp4-support Update MP4 support
DeliveryUsageApi listDeliveryUsage GET /video/v1/delivery-usage List Usage
DimensionsApi listDimensionValues GET /data/v1/dimensions/{DIMENSION_ID} Lists the values for a specific dimension
DimensionsApi listDimensions GET /data/v1/dimensions List Dimensions
DirectUploadsApi cancelDirectUpload PUT /video/v1/uploads/{UPLOAD_ID}/cancel Cancel a direct upload
DirectUploadsApi createDirectUpload POST /video/v1/uploads Create a new direct upload URL
DirectUploadsApi getDirectUpload GET /video/v1/uploads/{UPLOAD_ID} Retrieve a single direct upload's info
DirectUploadsApi listDirectUploads GET /video/v1/uploads List direct uploads
ErrorsApi listErrors GET /data/v1/errors List Errors
ExportsApi listExports GET /data/v1/exports List property video view export links
ExportsApi listExportsViews GET /data/v1/exports/views List available property view exports
FiltersApi listFilterValues GET /data/v1/filters/{FILTER_ID} Lists values for a specific filter
FiltersApi listFilters GET /data/v1/filters List Filters
IncidentsApi getIncident GET /data/v1/incidents/{INCIDENT_ID} Get an Incident
IncidentsApi listIncidents GET /data/v1/incidents List Incidents
IncidentsApi listRelatedIncidents GET /data/v1/incidents/{INCIDENT_ID}/related List Related Incidents
LiveStreamsApi createLiveStream POST /video/v1/live-streams Create a live stream
LiveStreamsApi createLiveStreamPlaybackId POST /video/v1/live-streams/{LIVE_STREAM_ID}/playback-ids Create a live stream playback ID
LiveStreamsApi createLiveStreamSimulcastTarget POST /video/v1/live-streams/{LIVE_STREAM_ID}/simulcast-targets Create a live stream simulcast target
LiveStreamsApi deleteLiveStream DELETE /video/v1/live-streams/{LIVE_STREAM_ID} Delete a live stream
LiveStreamsApi deleteLiveStreamPlaybackId DELETE /video/v1/live-streams/{LIVE_STREAM_ID}/playback-ids/{PLAYBACK_ID} Delete a live stream playback ID
LiveStreamsApi deleteLiveStreamSimulcastTarget DELETE /video/v1/live-streams/{LIVE_STREAM_ID}/simulcast-targets/{SIMULCAST_TARGET_ID} Delete a Live Stream Simulcast Target
LiveStreamsApi disableLiveStream PUT /video/v1/live-streams/{LIVE_STREAM_ID}/disable Disable a live stream
LiveStreamsApi enableLiveStream PUT /video/v1/live-streams/{LIVE_STREAM_ID}/enable Enable a live stream
LiveStreamsApi getLiveStream GET /video/v1/live-streams/{LIVE_STREAM_ID} Retrieve a live stream
LiveStreamsApi getLiveStreamSimulcastTarget GET /video/v1/live-streams/{LIVE_STREAM_ID}/simulcast-targets/{SIMULCAST_TARGET_ID} Retrieve a Live Stream Simulcast Target
LiveStreamsApi listLiveStreams GET /video/v1/live-streams List live streams
LiveStreamsApi resetStreamKey POST /video/v1/live-streams/{LIVE_STREAM_ID}/reset-stream-key Reset a live stream’s stream key
LiveStreamsApi signalLiveStreamComplete PUT /video/v1/live-streams/{LIVE_STREAM_ID}/complete Signal a live stream is finished
MetricsApi getMetricTimeseriesData GET /data/v1/metrics/{METRIC_ID}/timeseries Get metric timeseries data
MetricsApi getOverallValues GET /data/v1/metrics/{METRIC_ID}/overall Get Overall values
MetricsApi listAllMetricValues GET /data/v1/metrics/comparison List all metric values
MetricsApi listBreakdownValues GET /data/v1/metrics/{METRIC_ID}/breakdown List breakdown values
MetricsApi listInsights GET /data/v1/metrics/{METRIC_ID}/insights List Insights
PlaybackIDApi getAssetOrLivestreamId GET /video/v1/playback-ids/{PLAYBACK_ID} Retrieve an Asset or Live Stream ID
RealTimeApi getRealtimeBreakdown GET /data/v1/realtime/metrics/{REALTIME_METRIC_ID}/breakdown Get Real-Time Breakdown
RealTimeApi getRealtimeHistogramTimeseries GET /data/v1/realtime/metrics/{REALTIME_HISTOGRAM_METRIC_ID}/histogram-timeseries Get Real-Time Histogram Timeseries
RealTimeApi getRealtimeTimeseries GET /data/v1/realtime/metrics/{REALTIME_METRIC_ID}/timeseries Get Real-Time Timeseries
RealTimeApi listRealtimeDimensions GET /data/v1/realtime/dimensions List Real-Time Dimensions
RealTimeApi listRealtimeMetrics GET /data/v1/realtime/metrics List Real-Time Metrics
URLSigningKeysApi createUrlSigningKey POST /video/v1/signing-keys Create a URL signing key
URLSigningKeysApi deleteUrlSigningKey DELETE /video/v1/signing-keys/{SIGNING_KEY_ID} Delete a URL signing key
URLSigningKeysApi getUrlSigningKey GET /video/v1/signing-keys/{SIGNING_KEY_ID} Retrieve a URL signing key
URLSigningKeysApi listUrlSigningKeys GET /video/v1/signing-keys List URL signing keys
VideoViewsApi getVideoView GET /data/v1/video-views/{VIDEO_VIEW_ID} Get a Video View
VideoViewsApi listVideoViews GET /data/v1/video-views List Video Views

Models

Authorization

accessToken

  • Type: HTTP basic authentication

Tests

To run the tests, use:

composer install
vendor/bin/phpunit

Author

devex@mux.com

About this package

This PHP package is automatically generated by the OpenAPI Generator project:

  • API version: v1
    • Package version: 1.1.1
  • Build package: org.openapitools.codegen.languages.PhpClientCodegen