Overview

You can open a file from a cloud(or other resources) and save packaged files to a cloud(clouds). These options are only valid for VOD (it does not support live streaming).

Amazon S3

Amazon S3 or Amazon Simple Storage Service is a service offered by Amazon Web Services (AWS) that provides object storage through a web service interface. Amazon S3 uses the same scalable storage infrastructure that Amazon.com uses to run its global e-commerce network. Amazon S3 can be employed to store any type of object which allows for uses like storage for Internet applications, backup and recovery, disaster recovery, data archives, data lakes for analytics, and hybrid cloud storage. AWS launched Amazon S3 in the United States on March 14, 2006, then in Europe in November 2007.Learn more

First you need to install AWS SDK via composer:

composer require aws/aws-sdk-php

After installing the package, you can use the following code to open a file from the cloud and save packaged files to it.

// see https://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html to get Security Credentials
$config = [
    'version'     => 'latest',
    'region'      => 'us-west-1', // the region of your cloud server
    'credentials' => [
        'key'    => 'access-key-id', // the key to authorize you on the server
        'secret' => 'secret-access-key', // the secret to access to the cloud
    ]
];
$s3 = new Streaming\Clouds\S3($config);

$from_s3 = [
    'cloud' => $s3,
    'options' => [
        'Bucket' => 'bucket-name', // name of your bucket
        'Key' => 'videos/video.mp4' // your file name on the cloud
    ]
];

$to_s3 = [
    'cloud' => $s3,
    'options' => [
        'dest' => 's3://bucket-name/flder/subfolder', // name of your bucket and path to content folder
        'filename' => 'hls.m3u8' // name of your file on the cloud
    ]
];

$ffmpeg = Streaming\FFMpeg::create();

$video = $ffmpeg->openFromCloud($from_s3);
// you can also use open method to open a file from a local path
// $video = $ffmpeg->open('/var/media/video.mp4');

$video->hls()
    ->x264()
    ->autoGenerateRepresentations()
    ->save(null, $to_s3); // A path can aslo be passed(e.x. save('/var/media/hls.m3u8', $to_s3))

NOTE:

For getting credentials, you need to have an AWS account or you can create one.

NOTE:

Read the "AWS SDK for PHP" Document found here for more information.

Google Cloud Storage

Google Cloud Storage is a RESTful online file storage web service for storing and accessing data on Google Cloud Platform infrastructure. The service combines the performance and scalability of Google's cloud with advanced security and sharing capabilities. It is an Infrastructure as a Service (IaaS), comparable to Amazon S3 online storage service. Contrary to Google Drive and according to different service specifications, Google Cloud Storage appears to be more suitable for enterprises. Learn more

First you need to install Google Cloud Storage via composer:

composer require google/cloud-storage

After installing the package, you can use the following code to open a file from the cloud and save packaged files to it.

// Create a service account key from here: https://console.cloud.google.com/apis/credentials/serviceaccountkey
$gcs = new \Streaming\Clouds\GoogleCloudStorage(['keyFilePath' => '/path/to/credentials.json']);
// Alternatively, you can authenticate by setting the environment variable. See https://cloud.google.com/docs/authentication/production#auth-cloud-implicit-php

$from_gcs = [
    'cloud' => $gcs,
    'options' => [
        'bucket' => 'bucket-name', // name of the bucket
        'object_name' => 'video.mp4' // your file name on the cloud
    ]
];

$to_gcs = [
    'cloud' => $gcs,
    'options' => [
        'bucket' => 'bucket_name', // name of your bucket
        'filename' => 'folder/subfolder/hls.m3u8' // a path to save files on your cloud
    ]
];

$ffmpeg = Streaming\FFMpeg::create();

$video = $ffmpeg->openFromCloud($from_gcs);
// you can also use open method to open a file from a local path
// $video = $ffmpeg->open('/var/media/video.mp4');

$video->hls()
    ->x264()
    ->autoGenerateRepresentations()
    ->save(null, $to_gcs); // A path can aslo be passed(e.x. save('/var/media/hls.m3u8', $to_gcs))

NOTE:

To get credentials, read the Cloud Storage Authentication found here or you can create it directly (Select the "Service account key" option).

Microsoft Azure Storage

Azure Storage is Microsoft's cloud storage solution for modern data storage scenarios. Azure Storage offers a massively scalable object store for data objects, a file system service for the cloud, a messaging store for reliable messaging, and a NoSQL store. Learn more

First you need to install Microsoft Azure Storage via composer:

composer require microsoft/azure-storage-blob

After installing the package, you can use the following code to open a file from the cloud and save packaged files to it.

$mas = new Streaming\Clouds\MicrosoftAzure('DefaultEndpointsProtocol=https;AccountName=>>>yourAccount<<<;AccountKey=>>>yourKey<<<');

$from_mas = [
    'cloud' => $mas,
    'options' =>  [
        'container' => 'container-name', // name of the container
        'blob' => 'video.mp4' // your file name on the cloud
    ]
];

$to_mas = [
    'cloud' => $mas,
    'options' => ['container' => 'container-name'] // name of your container
];

$ffmpeg = Streaming\FFMpeg::create();

$video = $ffmpeg->openFromCloud($from_mas);
// you can also use open method to open a file from a local path
// $video = $ffmpeg->open('/var/media/video.mp4');

$video->hls()
    ->x264()
    ->autoGenerateRepresentations()
    ->save(null, $to_mas);  // A path can aslo be passed(e.x. save('/var/media/hls.m3u8', $to_mas))

NOTE:

To authenticate the service, see here.

Custom Cloud

You can create a custom cloud that implements the "\Streaming\Clouds\CloudInterface":

class CustomCloud implements \Streaming\Clouds\CloudInterface
{

    /**
     * Upload a entire directory to a cloud
     * @param string $dir
     * @param array $options
     */
    public function uploadDirectory(string $dir, array $options): void
    {
        // TODO: Implement uploadDirectory() method.
    }

    /**
     * Download a file from a cloud
     * @param string $save_to
     * @param array $options
     */
    public function download(string $save_to, array $options): void
    {
        // TODO: Implement download() method.
    }
}

After creating your own cloud class, you can use the following code to open a file from your custom cloud and save packaged files to it.

$custom = new CustomCloud();

$from_custom = [
    'cloud' => $custom,
    'options' =>  [...] //this array will be passed to the `download` method in the `CustomCloud` class.
];

$to_custom = [
    'cloud' => $custom,
    'options' => [...] //this array will be passed to the `upload` method in the `CustomCloud` class.
];

$ffmpeg = Streaming\FFMpeg::create();

$video = $ffmpeg->openFromCloud($from_custom);
// you can also use open method to open a file from a local path
// $video = $ffmpeg->open('/var/media/video.mp4');

$video->hls()
    ->x264()
    ->autoGenerateRepresentations()
    ->save(null, $to_custom); // you can also pass a local path to save a copy of files to your server

Save to multiple clouds

You can save your files to multiple clouds:

$dash->save(null, [$to_s3, $to_gcs, $to_mas, $to_custom]);

A path can also be passed to save a copy of files on your local machine.

$hls->save('/var/media/hls.m3u8', [$to_gsc, $to_custom]);

If you like this project, please ⭐️ Star it on Github.