PHP developers can now take advantage of Windows Azure Media Services to enable high-quality media experiences for a global audience
Windows Azure Media Services (WAMS) is a set of flexible and scalable cloud services to enable custom workflows for media ingest and transcoding, format conversion, content protection, on-demand streaming, and live streaming. WAMS support is available for .NET and Java developers via Developer tools for Windows Azure Media Services, and MS Open Tech is pleased to announce that WAMS support is now available to PHP developers as well, through the latest release of the Microsoft Windows Azure PHP SDK.
This releases reinforces MS Open Tech’s commitment to enabling open source developers to use their preferred open source technologies with Windows Azure to build applications in the cloud. You can use the new WAMS PHP SDK functionality to implement custom media workflow to connect to media services, ingest media assets, encode assets, package media for streaming and deliver media in various streaming formats.
Follow these steps to begin using the Windows Azure Media Services PHP SDK:
- Install all Windows Azure SDK prerequisites on you dev machine as covered here.
- Sign up for a Windows Azure Media Services account as instructed here.
- Obtain media service access keys from the “Manage Keys” dialogue.
- In your script create a MediaServicesSettings object and pass “Media Service Account Name” and “Primary Media Service access key” or “Secondary media service access key” to its constructor.
- Use the “createMediaServicesService” method of the ServicesBuilder singleton to create a Media Services Proxy object implementing the IMediaServices interface.
- Use the created Media Services Proxy object to control your Azure Media Services instance.
Here’s an example of the code required to complete the steps outlined above:
$mediaServiceProxy = ServicesBuilder::getInstance()->createMediaServicesService(
[Media Service Account Name],
[Primary Media Service Access Key or Secondary Media Service Access Key]
We have also put together a simple demo application available for download, to help you get started. The application demonstrates how to use the PHP SDK to upload a video, encode it to H264 Broadband SD 4x3" preset (for SAS access) and "H264 Smooth Streaming SD 4x3" preset (for streaming access). You can then create and use a dynamic DASH URL to play the video in a DASH player.
To run the demo application, you’ll need to set up a web server. After that, please follow the instructions here under sections “Install PHP library” and “Configure PHP”. After that, please edit the php.ini file to ensure that your server is configured for handling video files. For example, it will need to have high execution time for scripts and provide reasonable limitations on file uploads. You will also need to set up session support for this demo. Verify the following configuration settings within your php.ini file:
- “session.save_path” should have a valid path (it should be a path to folder where http server has a write permissions)
- “session.use_cookies” is set to “1”
- “session.auto_start” is set to “1”
- “max_execution_time” is set to “0” or a large enough value to handle a big video file upload
- “upload_max_filesize” and “post_max_size” are set to greater values than the video you plan to upload
Restart the server after making changes to the php.ini file.
Once these steps are done, please create a new site on your server and copy demo files into the root folder, then run the index.php file from the demo. Note: The DemoController.php file in the demo has the code that interfaces with the Windows Azure PHP SDK.
After you start the demo, you will see a form with three fields: Account name, Access key and video file. Use your Media Services instance credentials to fill in the account name and access key fields. You can retrieve them within the “Manage keys” dialogue of your Media Services instance. You can use primary or secondary access key from this dialogue (both are suitable). Then, specify a video file through the browser open dialogue. Push the process button to start encoding.
After the file upload is finished, the demo application will start the video encoding process on Windows Azure Media Services. You will see the progress on an info/status page, where you will be able to view the status of two jobs simultaneously - one for SAS access video file encoding and another one for streaming. This page will be updated automatically.
As a final step, the Demo will generate two links for generated media content - one for SAS access media and one for streaming video. The demo page will play the SAS access media in any HTML5 browser that supports the video tag. To get a URL for DASH playback, append (format=mpd-time-csf) to the end of the streaming video URL (after the manifest). To play the DASH URL, follow these steps:
- Verify that you have at least 1 on-demand streaming reserved unit (RU) in the Windows Azure management portal (i.e., under Account, see the Origin TAB, and the RU value should be at least 1). This enables the dynamic packaging feature. For more information about on-demand streaming with Windows Azure Media Services, see Mingfei Yan’s blog post “Demo – how to create HLS and Smooth Streaming assets using dynamic packaging.”
Thanks much to the talented team that has helped make this release possible: Albert Cheng, Abdelrahman Elogeel, Mingfei Yan, Brady Gaster and George Trifonov. Great job, everyone!
This is a work in progress as we will continue to add new scenarios to the SDK going forward such as Bulk ingestion and Ingestion of encrypted content. What else would you like to see supported? Are there specific WAMS scenarios that you’re looking to accomplish from PHP?
Share your thoughts in the comments below, or get involved and contribute to the GitHub project. We look forward to your contributions!
Senior Program Manager
Microsoft Open Technologies, Inc.
Lead Technical Evangelist
Microsoft Open Technologies, Inc.