Live-to-VOD clip extraction PHP query examples (nDVR) for the Wowza Streaming Engine REST API

Wowza Streaming Engine media server software includes a REST Application Programming Interface (API) that you can use to configure, manage, and monitor the media server through HTTP requests. This article describes how to get information about Wowza nDVR stores and extract clips from live streams to on-demand (VOD) streams in nDVR stores by using PHP to query the Wowza Streaming Engine REST service.

Notes:

Contents


Get a list of nDVR stores
Get an nDVR item
Convert an nDVR store
Convert a group of nDVR stores
Optional parameters
Clear the conversion cache
More resources
For developers

Get a list of nDVR stores


The following example shows how to request a list of all nDVR stores in your Wowza Streaming Engine media server:
// ndvr is the application name
$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->getAll();
An example result:
object(stdClass)#3 (3) {
  ["serverName"]=>
  string(15) "_defaultServer_"
  ["groupConversionStatusList"]=>
  array(0) {
  }
  ["dvrconverterstoresummary"]=>
  array(1) {
    [0]=>
    object(stdClass)#4 (2) {
      ["location"]=>
      string(106) "/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/ndvr/instances/_definst_/dvrstores/tmp123.0"
      ["name"]=>
      string(8) "tmp123.0"
    }
  }
}

Get an nDVR item


The following example shows how to request information about a single nDVR store:
$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->getItem("tmp123");
An example result:
object(stdClass)#3 (3) {
  ["serverName"]=>
  string(15) "_defaultServer_"
  ["dvrStoreName"]=>
  string(8) "tmp123.0"
  ["DvrConverterStore"]=>
  object(stdClass)#4 (11) {
    ["dvrStoreName"]=>
    string(8) "tmp123.0"
    ["audioAvailable"]=>
    bool(true)
    ["videoAvailable"]=>
    bool(false)
    ["isLive"]=>
    bool(false)
    ["dvrStartTime"]=>
    int(0)
    ["dvrEndTime"]=>
    int(232280)
    ["duration"]=>
    int(232280)
    ["utcStart"]=>
    int(1474624864368)
    ["utcEnd"]=>
    int(1474625095218)
    ["outputFilename"]=>
    NULL
    ["conversionStatus"]=>
    object(stdClass)#5 (12) {
      ["storeName"]=>
      string(8) "tmp123.0"
      ["fileName"]=>
      NULL
      ["state"]=>
      string(12) "INITIALIZING"
      ["statusCode"]=>
      string(4) "NONE"
      ["errorStrings"]=>
      array(0) {
      }
      ["startTime"]=>
      int(1474624867412)
      ["endTime"]=>
      int(-1)
      ["duration"]=>
      int(228877)
      ["currentChunk"]=>
      int(2)
      ["chunkCount"]=>
      int(2)
      ["fileSize"]=>
      int(0)
      ["fileDuration"]=>
      int(0)
    }
  }
}

Convert an nDVR Store


The following example shows how to initiate the conversion of single-bitrate DVR stream to a VOD asset:
$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->convert("tmp123");
An example XML result:
 
object(stdClass)#3 (3) {
  ["success"]=>
  bool(true)
  ["message"]=>
  string(18) "Conversion started"
  ["data"]=>
  NULL
}
Note: A conversion request is cached so it can be viewed and used for conversions of the same store in the future. If you need to adjust any conversion parameters for future conversions, you must clear the cache. For more information, see Clear the conversion cache.

Convert a group of nDVR stores


The following example shows how to initiate the conversion of DVR streams in an adaptive bitrate (ABR) streaming group to a VOD asset:
$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->convertGroup(array("tmp123","tmp124"));
Note: A conversion request is cached so it can be viewed and used for conversions of the same store in the future. If you need to adjust any conversion parameters for future conversions, you must clear the cache. For more information, see Clear the conversion cache.

Optional parameters


To control when DVR store conversion starts and stops and to specify the file name of the extracted clip, include the following parameters in your HTTP requests:
 
  • dvrConverterStartTime - The Unix timestamp to start DVR store conversion.
     
  • dvrConverterEndTime - The Unix timestamp to stop DVR store conversion.
     
  • dvrConverterDuration - The amount of time (in milliseconds) after dvrConverterStartTime or before dvrConverterEndTime to stop DVR store conversion. This parameter can be used instead of specifying either a stand or end time.
     
  • dvrConverterOutputFilename - The file name of the extracted VOD clip.
     
  • dvrConverterDebugConversions - Enables debugging in the Wowza Streaming Engine access log file.
Note: A conversion request is cached so it can be viewed and used for conversions of the same store in the future. If you need to adjust any conversion parameters for future conversions, you must clear the cache. For more information, see Clear the conversion cache.

Start and end time example

$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->convert("tmp127", strtotime('-1 hour'),time());
Note: The actual start and end times may vary from dvrConverterStartTime and dvrConverterEndTime depending on the framerate and keyframe frequency of your encoded live stream. To help avoid this issue, we recommend that your encoder inserts a keyframe into the stream at least once every 30 frames if you're encoding a live stream at 30 frames-per-second (fps). If you're encoding a live stream at 30 fps and you choose to insert a keyframe for every 60 frames, the start or end times may vary from the specified parameter values by one or more seconds. Be sure to test your workflow to find the best settings.

Start time and duration example

$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->convertByDurationWithStartTime("tmp123", strtotime("-1 hour"), 5000);

End time and duration example

$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->convertByDurationWithEndTimeTime("tmp123", time(), 5000);

End time, duration, and output file name example

$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->convertByDurationWithEndTimeTime("tmp123", time(), 5000,"[OutputFileName]");

Enable debug output example 

$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->debugConversions("tmp127");

Clear the conversion cache


When a conversion is requested, the request is cached so it can be viewed and used for conversions of the same store in the future. If you need to adjust any conversion parameters for future conversions, you must clear the cache. To clear the conversion cache for the nDVR converter, use the following request:
$sf = new Com\Wowza\DvrClipExtraction("ndvr");
$response = $sf->clearCache();

More resources


How to extract MP4-formatted files from DVR streams using Wowza Streaming Engine Java API

For developers


Source code is available on GitHub.

Wowza Media Systems™ provides developers with a platform to create streaming applications and solutions. See Wowza Developer Tools to learn more about our APIs and SDK.