pfop_watermark.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Processing\PersistentFop;
  5. //对已经上传到七牛的视频发起异步转码操作
  6. $accessKey = getenv('QINIU_ACCESS_KEY');
  7. $secretKey = getenv('QINIU_SECRET_KEY');
  8. $bucket = getenv('QINIU_TEST_BUCKET');
  9. $auth = new Auth($accessKey, $secretKey);
  10. //要转码的文件所在的空间和文件名。
  11. $key = 'qiniu.mp4';
  12. //转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
  13. $pipeline = 'sdktest';
  14. //转码完成后通知到你的业务服务器。
  15. $notifyUrl = 'http://375dec79.ngrok.com/notify.php';
  16. $force = false;
  17. $config = new \Qiniu\Config();
  18. //$config->useHTTPS=true;
  19. $pfop = new PersistentFop($auth, $config);
  20. //需要添加水印的图片UrlSafeBase64
  21. //可以参考http://developer.qiniu.com/code/v6/api/dora-api/av/video-watermark.html
  22. $base64URL = Qiniu\base64_urlSafeEncode('http://devtools.qiniu.com/qiniu.png');
  23. //水印参数
  24. $fops = "avthumb/mp4/s/640x360/vb/1.4m/image/" . $base64URL . "|saveas/"
  25. . \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_wm.mp4");
  26. list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
  27. echo "\n====> pfop avthumb result: \n";
  28. if ($err != null) {
  29. var_dump($err);
  30. } else {
  31. echo "PersistentFop Id: $id\n";
  32. }
  33. //查询转码的进度和状态
  34. list($ret, $err) = $pfop->status($id);
  35. echo "\n====> pfop avthumb status: \n";
  36. if ($err != null) {
  37. var_dump($err);
  38. } else {
  39. var_dump($ret);
  40. }