Serverless Devs allows you to deploy applications together with services such as Function Compute, Object Storage Service (OSS), and FFmpeg to process audio and video files. For example, you can use Serverless Devs to query audio and video information, add watermarks to audio and video files, and convert file formats.
Background
FFmpeg is an open source software project that consists of a set of programs that allow you to record, convert, and stream audio and video files. FFmpeg is licensed under the GNU Lesser General Public License (LGPL) or GNU General Public License (GPL). FFmpeg provides a comprehensive solution to record, convert, and stream audio and videos. FFmpeg uses libavcodec, an advanced audio and video codec library, to ensure high portability and quality in encoding and decoding scenarios. For more information, see FFmpeg.
This topic provides examples that cover the features when you process audio and video files. In this topic, Python language is used. The following table describes sample functions to implement specific features. You can modify the function code for each sample function to implement secondary development based on your business requirements.
Sample function | Description |
GetMediaMeta | Queries the metadata of an audio or video file. |
GetDuration | Queries the duration of an audio or video file. |
GetSprites | Creates an image sprite for a video. |
VideoWatermark | Adds text watermarks, image watermarks, or animated Graphics Interchange Format (GIF) watermarks to a video. |
AudioConvert | Converts the format of an audio or video file. |
VideoGif | Converts a video file to a GIF file. |
Before you begin
Make sure that the following operations are complete:
Deploy an application by using Serverless Devs
Run the following command to initialize the project that you want to manage:
sudo s init ffmpeg-app -d ffmpeg-app
In the preceding command,
-d specifies the name of the generated directory.
Run the following command to go to the directory of the project:
cd ffmpeg-app
(Optional) You can modify the sample code in the directory based on your business requirements to implement your business logic.
Run the following command to deploy the project:
sudo s deploy -y
NoteIf you want to deploy a specific feature of the project, run the corresponding command. For example, if you want to deploy the GetMediaMeta feature to query the metadata information of audio or video files, run the following command:
sudo s GetMediaMeta deploy
If you want to deploy another feature, replace
GetMediaMeta
with another feature name.Call a function.
References
To accelerate the transcoding of large videos or perform complex operations, you can use the Serverless Workflow orchestration function to build a video processing system. For more information, see Build an elastic and highly available audio and video processing system based on the serverless architecture.
If you want to process audio and video data in real time or near real time, you can deploy applications on GPU-accelerated instances. For more information, see Best practices for audio and video processing.