In use cases such as video and social networking, users upload high numbers of images and audio/video files frequently, which has high requirements for the real-timeness and concurrency capabilities of the processing system. Multiple functions can be used to process uploaded videos with different definitions in order to meet the needs of users in diversified scenarios and adapt to small-bandwidth and unstable mobile networks.
SCF, FFmpeg, and COS can be used in combination as shown below to transcode audio and video files:
In SCF, you can write custom business logic in different programming languages (Python, Node, PHP, Java, and Go). Taking transcoding as an example, the steps are as follows:
Compared with TKE, the combination of SCF and FFmpeg has the following advantages and disadvantages in audio/video transcoding:
Item | TKE-based Implementation | SCF-based Implementation | Analysis |
---|---|---|---|
Implementation method |
|
|
The implementation methods do not differ greatly. |
Development/Testing/Deployment experience |
|
|
SCF makes the development process easier and more efficient. |
Logging/Monitoring/Alarming | It is necessary to launch the agent in the TKE cluster and connect it to the logging platform, monitoring center, and alarming platform. | SCF offers logging/monitoring/alarming capabilities and APIs for connection to third-party logging/monitoring platforms. It supports launching the agent process in the runtime and reporting data synchronously. | SCF offers a wider range of capabilities, but for connection to self-created platforms, it is more complex to launch the agent in SCF than in TKE. |
OPS | TKE clusters need to be maintained on your own and have low auto-scaling efficiency. | Maintenance is not required, as SCF guarantees cluster availability, load balancing, and auto scaling. | SCF is easier to use. |
Fees | It is necessary to reserve container resources based on the peak values, which may cause a waste of resources. | Resources are auto-scalable and pay-as-you-go, saving more than 30% of costs. | SCF has obvious advantages. |
Through comparison with TKE in multiple dimensions above, the following conclusions can be drawn:
Advantages:
Disadvantages:
This document uses the Guangzhou region as an example:
Log in to the SCF Console and click Functions on the left sidebar.
Select the region where to create a function at the top of the "Functions" page and click Create to enter the function creation process.
Create a function as follows in "Basic Info" on the "Create Function" page and click Next.
Transcode
as an example.On the "Function configuration" page, keep the default configuration and click Complete.
Enter the "Function configuration" page of the created function, click Edit in the top-right corner, and complete the function configuration as follows:
key | value |
---|---|
region | COS bucket region. |
target_bucket | The created COS bucket to which the output video will be uploaded after being transcoded. |
target_path | The specified directory of the bucket to which the output video will be uploaded after being transcoded. |
Note:
If you have activated the CFS service, please enable both the VPC and file system mounting capabilities in the function by following the steps below.
On the "Function configuration" page of the function, click Edit in the top-right corner and configure the function.
Click the Function code tab to enter the function code editing page and modify the file upload path.
Comment on line 76 of the code and add the following code to line 77.
upload_path = '/mnt/new-'+ key.split('/')[-1]
Log in to the COS Console, enter the corresponding bucket directory, upload a video file, and check whether a compressed video file is generated in the corresponding transcoding directory.
Note:
The time it takes to compress a video varies by video size. If a video is large, it will take longer to compress the video and display the output video.
You can add automated CDN purge/prefetch capabilities to the demo in this document. For example, when the output video is returned to the COS bucket, a new function can be triggered to execute the CDN purge/prefetch features.
You can also leverage the high concurrence of SCF to implement fast transcoding or sharding. For example, function A can schedule tasks while function B can perform actual transcoding/sharding tasks. With the aid of the CFS mounting capabilities, you can also implement cross-function file sharing with ease.
Was this page helpful?