Working with video streams from PHP SDK
PHP SDK offers you a way to handle videos and their streams from the backend of your system.
Every video has multiple streams. From original, to default and any other streams that have been created based on your setup.
Here you will see the way to work with video streams through your PHP API calls.
PHP SDK Video Streams Methods
- index Return all streams associated with a video
$ziggeo->streams()->index($video_token_or_key, $arguments = array())
- states Filter streams by state
This method returns JSON[ { "volatile":false, "token":"d751140b4e1cf0a243f32092f6110296", "key":null, "creation_type":5, "state":5, "streamable":2, "video_type":"mp4", "video_sub_type":"other", "image_size":0, "video_size":36078, "video_width":640, "video_height":360, "duration":1, "has_video":true, "has_image":true, "submission_date":1390257799, "type":"ApiVideoStream", "created":1390257799, "owned":true, "creation_type_string":"SERVER_UPLOAD", "streamable_string":"DEGRADED", "state_string":"READY" }]
- get Get a single stream
$ziggeo->streams()->get($video_token_or_key, $token_or_key)
This method returns JSON{ "volatile":false, "token":"d751140b4e1cf0a243f32092f6110296", "key":null, "creation_type":5, "state":5, "streamable":2, "video_type":"mp4", "video_sub_type":"other", "image_size":0, "video_size":36078, "video_width":640, "video_height":360, "duration":1, "has_video":true, "has_image":true, "submission_date":1390257799, "type":"ApiVideoStream", "created":1390257799, "owned":true, "creation_type_string":"SERVER_UPLOAD", "streamable_string":"DEGRADED", "state_string":"READY" }
Example:<?php /* This script will show you how to get details of a stream of specific video Parameters you need to pass: 1. app_token 2. private_key 3. video_token 4. stream_token */ require_once(dirname(__FILE__) . "/../Ziggeo.php"); $opts = getopt("", array("app_token:", "private_key:", "video_token:", "stream_token:")); //We initialize our SDK $ziggeo = new Ziggeo($opts["app_token"], $opts["private_key"]); $result = $ziggeo->streams()->get($opts["video_token"], $opts["stream_token"]); var_dump($result); ?>
- download_video Download the video data associated with the stream
$ziggeo->streams()->download_video($video_token_or_key, $token_or_key)
This method returns DATAExample:<?php /* This script will show you how to download a specific stream of a video Parameters you need to pass: 1. app_token 2. private_key 3. video_token 4. stream_token */ require_once(dirname(__FILE__) . "/../Ziggeo.php"); $opts = getopt("", array("app_token:", "private_key:", "video_token:", "stream_token:")); //We initialize our SDK $ziggeo = new Ziggeo($opts["app_token"], $opts["private_key"]); //see streams_get.php for more info $video = $ziggeo->streams()->get($opts["video_token"], $opts["stream_token"]); $file_name = $opts["video_token"]."_".$opts["stream_token"].".".$video["video_type"]; $file_content = $ziggeo->streams()->download_video($opts["video_token"], $opts["stream_token"]); file_put_contents($file_name, $file_content); ?>
- download_image Download the image data associated with the stream
$ziggeo->streams()->download_image($video_token_or_key, $token_or_key)
This method returns DATAExample:<?php /* This script will show you how to download a specific stream of a video Parameters you need to pass: 1. app_token 2. private_key 3. video_token 4. stream_token */ require_once(dirname(__FILE__) . "/../Ziggeo.php"); $opts = getopt("", array("app_token:", "private_key:", "video_token:", "stream_token:")); //We initialize our SDK $ziggeo = new Ziggeo($opts["app_token"], $opts["private_key"]); //see streams_get.php for more info $video = $ziggeo->streams()->get($opts["video_token"], $opts["stream_token"]); $file_name = $opts["video_token"]."_".$opts["stream_token"].".png"; $file_content = $ziggeo->streams()->download_image($opts["video_token"], $opts["stream_token"]); file_put_contents($file_name, $file_content); ?>
- push_to_service Push a stream to a provided push service.
$ziggeo->streams()->push_to_service($video_token_or_key, $token_or_key, $arguments = array())
- pushservicetoken Push Services's token (from the Push Services configured for the app)
This method returns JSON - delete Delete the stream
$ziggeo->streams()->delete($video_token_or_key, $token_or_key)
- delete_file Delete video file only of specific stream (keeps the data) by providing video token or key.
$ziggeo->streams()->delete_file($video_token_or_key, $token_or_key)
- create Create a new stream
$ziggeo->streams()->create($video_token_or_key, $arguments = array())
- file Video file to be uploaded
This method returns JSON{ "volatile":false, "token":"d751140b4e1cf0a243f32092f6110296", "key":null, "creation_type":5, "state":5, "streamable":2, "video_type":"mp4", "video_sub_type":"other", "image_size":0, "video_size":36078, "video_width":640, "video_height":360, "duration":1, "has_video":true, "has_image":true, "submission_date":1390257799, "type":"ApiVideoStream", "created":1390257799, "owned":true, "creation_type_string":"SERVER_UPLOAD", "streamable_string":"DEGRADED", "state_string":"READY" }
Example:<?php /* This script will show you how to get details of a stream of specific video Parameters you need to pass: 1. app_token 2. private_key 3. video_token 4. filename */ require_once(dirname(__FILE__) . "/../Ziggeo.php"); $opts = getopt("", array("app_token:", "private_key:", "video_token:", "filename:")); //We initialize our SDK $ziggeo = new Ziggeo($opts["app_token"], $opts["private_key"]); $ziggeo->streams()->create($opts["video_token"], array( "file" => $opts["filename"] )); ?>
- attach_image Attaches an image to a new stream. Must be attached before video, since video upload triggers the transcoding job and binds the stream
$ziggeo->streams()->attach_image($video_token_or_key, $token_or_key, $arguments = array())
- file Image file to be attached
This method returns JSONExample:<?php /* This script will show you how to download a specific stream of a video Parameters you need to pass: 1. app_token 2. private_key 3. video_token 4. stream_token 5. filename */ require_once(dirname(__FILE__) . "/../Ziggeo.php"); $opts = getopt("", array("app_token:", "private_key:", "video_token:", "stream_token:", "filename:")); //We initialize our SDK $ziggeo = new Ziggeo($opts["app_token"], $opts["private_key"]); $arguments = array( 'file' => $opts["filename"] ); $result = $ziggeo->streams()->attach_image($opts["video_token"], $opts["stream_token"], $arguments); var_dump($result); ?>
- attach_video Attaches a video to a new stream
$ziggeo->streams()->attach_video($video_token_or_key, $token_or_key, $arguments = array())
- file Video file to be attached
This method returns JSON - attach_subtitle Attaches a subtitle to the stream.
$ziggeo->streams()->attach_subtitle($video_token_or_key, $token_or_key, $arguments = array())
- lang Subtitle language
- label Subtitle reference
- data Actual subtitle
This method returns JSON