The development of the Internet has made videos an indispensable part of people's daily lives, and more and more websites are beginning to use videos to display their content. For video processing, such as video compression, transcoding, etc., professional technical support is required. Qiniu Cloud Storage is a popular cloud storage service that provides powerful video transcoding functions that can convert uploaded video files into video files in a specified format. For video transcoding, Qiniu Cloud Storage also provides callback reception. Let’s introduce the implementation method of PHP Qiniu video transcoding reception callback.
1. What is callback reception
Callback reception, that is, after Qiniu Cloud Storage completes the transcoding, the transcoding result will be sent to the specified URL through post method and the specified data will be returned. Format. The advantage of implementing this method is that there is no need to perform callback processing on the customer's server, because the callback will be sent directly to the URL specified by the customer, thus enabling fast processing of the transcoding results.
2. Implementation method
2.1 Register and upload credentials
Before using Qiniu Cloud Storage for video transcoding, you first need to register and upload the credentials. The upload certificate is a token that is used to legally prove the legality of the user's uploaded file on the server side. In Qiniu Cloud Storage, we can use PHP SDK to obtain tokens. The following is the code to obtain the upload certificate:
use Qiniu\Auth; use Qiniu\Storage\UploadManager; $accessKey = 'ACCESS_KEY'; $secretKey = 'SECRET_KEY'; $auth = new Auth($accessKey, $secretKey); $bucket = 'BUCKET_NAME'; $token = $auth->uploadToken($bucket);
2.2 Upload the video
After obtaining the upload certificate, you can upload the video. Similar to uploading images, uploading videos also requires the use of the upload manager. The following is the code for video upload:
use Qiniu\Storage\UploadManager; use Qiniu\Storage\BucketManager; use Qiniu\Auth; $accessKey = 'ACCESS_KEY'; $secretKey = 'SECRET_KEY'; $auth = new Auth($accessKey, $secretKey); $bucket = 'BUCKET_NAME'; $callbackUrl = 'http://your.domain.com/callback.php'; $callbackBody = 'filename=$(fname)&filesize=$(fsize)&etag=$(etag)'; $policy = array( 'callbackUrl' => $callbackUrl, 'callbackBody' => $callbackBody ); $upToken = $auth->uploadToken($bucket, null, 3600, $policy); $filePath = '/path/to/video.mp4'; $key = 'video.mp4'; $uploadMgr = new UploadManager(); list($ret, $err) = $uploadMgr->putFile($upToken, $key, $filePath);
Here we can see that unlike processing pictures, processing videos requires setting the url and callbackBody content received by the callback. The content of this part determines the data format received by the callback.
2.3 Receive callback
After the upload is completed, we need to receive a callback. On the URL received by the callback, use the following code to process the callback information:
$hostname = "http://api.qiniu.com"; $port = 80; $path = "/callback"; $url = $hostname . ":" . $port . $path; $data = json_decode(file_get_contents('php://input'));
Through the above code, you can receive the callback data passed from Qiniu Cloud Storage. For different callbacks, we can perform different processing based on the data in "data".
3. Summary
This article introduces the callback reception of PHP Qiniu video transcoding. Through this method, video transcoding can be efficiently realized. At the same time, I hope the content in this article will be helpful to everyone.
The above is the detailed content of Let's talk about the implementation method of php Qiniu video transcoding receiving callback. For more information, please follow other related articles on the PHP Chinese website!