shop-php/vendor/qiniu/php-sdk/examples/pfop_watermark.php

60 lines
1.8 KiB
PHP
Raw Normal View History

2023-05-10 13:39:12 +08:00
<?php
require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
2023-11-02 14:13:04 +08:00
use Qiniu\Config;
2023-05-10 13:39:12 +08:00
use Qiniu\Processing\PersistentFop;
2023-11-02 14:13:04 +08:00
// 控制台获取密钥https://portal.qiniu.com/user/key
2023-05-10 13:39:12 +08:00
$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$auth = new Auth($accessKey, $secretKey);
2023-11-02 14:13:04 +08:00
// 对已经上传到七牛的视频发起异步转码操作
// 视频水印参考文档https://developer.qiniu.com/dora/api/1314/video-watermarking
// 要转码的文件所在的空间和文件名
$bucket = getenv('QINIU_TEST_BUCKET');
2023-05-10 13:39:12 +08:00
$key = 'qiniu.mp4';
2023-11-02 14:13:04 +08:00
// 用户默认没有私有队列,需要在这里创建然后填写 https://portal.qiniu.com/dora/media-gate/pipeline
2023-05-10 13:39:12 +08:00
$pipeline = 'sdktest';
2023-11-02 14:13:04 +08:00
// 转码完成后通知到你的业务服务器(需要可以公网访问,并能够相应 200 OK
2023-05-10 13:39:12 +08:00
$notifyUrl = 'http://375dec79.ngrok.com/notify.php';
2023-11-02 14:13:04 +08:00
// 当转码后的文件名与源文件名相同时,是否覆盖源文件
2023-05-10 13:39:12 +08:00
$force = false;
2023-11-02 14:13:04 +08:00
$config = new Config();
$config->useHTTPS=true;
2023-05-10 13:39:12 +08:00
$pfop = new PersistentFop($auth, $config);
2023-11-02 14:13:04 +08:00
// 图片水印的源路径,也就是给视频打图片水印的图片
$base64URL = Qiniu\base64_urlSafeEncode('http://test-2.qiniudn.com/logo.png');
// 视频处理完毕后保存到空间中的名称
$saveasKey = 'qiniu_watermark.mp4';
2023-05-10 13:39:12 +08:00
2023-11-02 14:13:04 +08:00
// 进行视频打图片水印操作
$fops = "avthumb/mp4/wmImage/" . $base64URL . "|saveas/"
. \Qiniu\base64_urlSafeEncode("$bucket:$saveasKey");
2023-05-10 13:39:12 +08:00
list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
echo "\n====> pfop avthumb result: \n";
if ($err != null) {
var_dump($err);
} else {
echo "PersistentFop Id: $id\n";
}
2023-11-02 14:13:04 +08:00
// 查询转码的进度和状态
2023-05-10 13:39:12 +08:00
list($ret, $err) = $pfop->status($id);
echo "\n====> pfop avthumb status: \n";
if ($err != null) {
var_dump($err);
} else {
var_dump($ret);
}