22require_once __DIR__ . '/../autoload.php ' ;
33
44use Qencode \Exceptions \QencodeApiException ;
5+ use Qencode \Exceptions \QencodeClientException ;
56use Qencode \Exceptions \QencodeException ;
67use Qencode \Classes \CustomTranscodingParams ;
78use Qencode \Classes \Format ;
1112use Qencode \QencodeApiClient ;
1213
1314// Replace this with your API key
14- $ apiKey = '5a5db6fa5b4c5 ' ;
15+ $ apiKey = 'abcdefgh ' ;
16+ $ video_url = 'https://qa.qencode.com/static/1.mp4 ' ;
1517
16- $ transcodingProfileId = '5a5db6fa5b8ac ' ;
17-
18- $ video_url = 'https://qa.stagevids.com/static/1.mp4 ' ;
19-
20- $ q = new QencodeApiClient ($ apiKey , 'https://api-qa.qencode.com ' );
18+ $ q = new QencodeApiClient ($ apiKey );
2119
2220try {
2321
2422 $ task = $ q ->createTask ();
23+ log_message ("Created task: " .$ task ->getTaskToken ());
24+
2525 $ params = new CustomTranscodingParams ();
2626 $ params ->source = $ video_url ;
2727
2828 $ format = new Format ();
2929 $ format ->destination = new Destination ();
30- $ format ->destination ->url = "s3://s3-eu-west-2.amazonaws.com/qencode-test " ;
31- $ format ->destination ->key = "AKIAIKZIPSJ7SDAIWK4A " ;
32- $ format ->destination ->secret = "h2TGNXeT49OT+DtZ3RGr+94HEhptS6oYsmXCwWuL " ;
30+ $ format ->destination ->url = "s3://s3-your-region.amazonaws.com/your-bucket/folder " ;
31+ $ format ->destination ->key = "your-access-key " ;
32+ $ format ->destination ->secret = "your-secret-key " ;
33+ $ format ->destination ->permissions = "public-read " ;
34+ $ format ->destination ->storage_class = "REDUCED_REDUNDANCY " ;
35+ $ format ->segment_duration = 4 ;
3336 $ format ->output = "advanced_hls " ;
3437
3538 $ stream = new Stream ();
5356 do {
5457 sleep (5 );
5558 $ response = $ task ->getStatus ();
56- print_r ($ response );
57- echo "<BR><BR> " ;
59+ if (is_array ($ response ) and array_key_exists ('percent ' , $ response )) {
60+ log_message ("Completed: {$ response ['percent ' ]}% " );
61+ }
5862 } while ($ response ['status ' ] != 'completed ' );
5963
6064 foreach ($ response ['videos ' ] as $ video ) {
61- echo $ video ['user_tag ' ] . ': ' . $ video ['url ' ]. ' <BR> ' ;
65+ log_message ( $ video ['user_tag ' ] . ': ' . $ video ['url ' ]) ;
6266 }
6367 echo "DONE! " ;
6468
65-
69+ } catch (QencodeClientException $ e ) {
70+ // We got some inconsistent state in client application (e.g. task_token not found when requesting status)
71+ log_message ('Qencode Client Exception: ' . $ e ->getCode () . ' ' . $ e ->getMessage ());
6672} catch (QencodeApiException $ e ) {
6773 // API response status code was not successful
68- echo 'Qencode API Exception: ' . $ e ->getCode () . ' ' . $ e ->getMessage ();
74+ log_message ( 'Qencode API Exception: ' . $ e ->getCode () . ' ' . $ e ->getMessage () );
6975} catch (QencodeException $ e ) {
7076 // API call failed
71- echo 'Qencode Exception: ' . $ e ->getMessage ();
77+ log_message ( 'Qencode Exception: ' . $ e ->getMessage () );
7278 var_export ($ q ->getLastResponseRaw ());
7379}
80+
81+ function log_message ($ msg ) {
82+ echo $ msg ."\n" ;
83+ }
0 commit comments