1+ <?php
2+ require_once __DIR__ . '/../autoload.php ' ;
3+
4+ use Qencode \Exceptions \QencodeApiException ;
5+ use Qencode \Exceptions \QencodeClientException ;
6+ use Qencode \Exceptions \QencodeException ;
7+ use Qencode \Classes \CustomTranscodingParams ;
8+ use Qencode \Classes \Format ;
9+ use Qencode \Classes \Stream ;
10+ use Qencode \Classes \Destination ;
11+ use Qencode \Classes \Libx264_VideoCodecParameters ;
12+ use Qencode \QencodeApiClient ;
13+
14+ // Replace this with your API key
15+ $ apiKey = '12345678 ' ;
16+ $ params = '
17+ {"query": {
18+ "source": "https://qa.qencode.com/static/timer.mp4",
19+ "format": [
20+ {
21+ "output": "mp4",
22+ "size": "320x240",
23+ "video_codec": "libx264"
24+ }
25+ ]
26+ }
27+ } ' ;
28+
29+ $ q = new QencodeApiClient ($ apiKey );
30+
31+ try {
32+
33+ $ task = $ q ->createTask ();
34+ log_message ("Created task: " .$ task ->getTaskToken ());
35+
36+ $ task ->startCustom ($ params );
37+
38+ do {
39+ sleep (5 );
40+ $ response = $ task ->getStatus ();
41+ if (is_array ($ response ) and array_key_exists ('percent ' , $ response )) {
42+ log_message ("Completed: {$ response ['percent ' ]}% " );
43+ }
44+ } while ($ response ['status ' ] != 'completed ' );
45+
46+ foreach ($ response ['videos ' ] as $ video ) {
47+ log_message ($ video ['user_tag ' ] . ': ' . $ video ['url ' ]);
48+ }
49+ echo "DONE! " ;
50+
51+ } catch (QencodeClientException $ e ) {
52+ // We got some inconsistent state in client application (e.g. task_token not found when requesting status)
53+ log_message ('Qencode Client Exception: ' . $ e ->getCode () . ' ' . $ e ->getMessage ());
54+ } catch (QencodeApiException $ e ) {
55+ // API response status code was not successful
56+ log_message ('Qencode API Exception: ' . $ e ->getCode () . ' ' . $ e ->getMessage ());
57+ } catch (QencodeException $ e ) {
58+ // API call failed
59+ log_message ('Qencode Exception: ' . $ e ->getMessage ());
60+ var_export ($ q ->getLastResponseRaw ());
61+ }
62+
63+ function log_message ($ msg ) {
64+ echo $ msg ."\n" ;
65+ }
0 commit comments