This topic describes how to use the application template for FFmpeg-based audio and video processing or code packages to deploy audio and video processing applications in Function Compute.

Prerequisites

  • Scenario 1: Automatically deploy an application in the Function Compute console:
  • Scenario 2: Manually deploy an application by using Funcraft:

Background information

OSS provides general image processing services. However, it cannot adequately meet your requirements for general audio or video processing, and custom image, audio, or video processing.

FFmpeg is an open source software project that consists of a large suite of programs used to record audio and videos, convert audio and video formats, and stream audio and video files. FFmpeg is licensed under the GNU Lesser General Public License (LGPL) or GNU General Public License (GPL). It provides a comprehensive solution to record, convert, and stream audio and videos. FFmpeg uses the advanced audio and video codec library libavcodec to ensure high portability and encoding and decoding quality.

Function Compute provides an application template for FFmpeg-based audio and video processing in Application Center of the Function Compute console. You can use the template in the console to automatically deploy applications related to audio and video processing. You can also manually deploy such applications by using Funcraft.

The application template contains the following functions or features:

  • get_media_meta: obtains the metadata of an audio or video file.
  • get_duration: queries the duration of an audio or video file.
  • transcode: performs parallel audio or video transcoding.
  • get_sprites: creates an image sprite.
  • video_watermark: adds a watermark to an video file.
  • video_gif: converts a video file to a GIF file.
  • audio_convert: converts the format of an audio file.

Automatically deploy an application in the Function Compute console

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Application Center. On the Audio and Video Processing tab of the Application Templates section, move the pointer over Video Audio Processing Service and click Configure and Deploy.
  4. On the Create Template Application page, set the Application Name parameter.
  5. Optional:On the Create Template Application page, click Preview to view the resources contained in the template.
  6. Click Deploy.
    After the application is deployed, you can click My Applications on the Application Center page to view the deployed application on the My Applications page.

Manually deploy an application by using Funcraft

  1. Run the following command to clone the application and decompress the code package:
    git clone https://github.com/awesome-fc/fc-oss-ffmpeg.git           
    Note If you have not installed Git, click Code package to download the code package.
  2. Run the following command to go to the application directory:
    cd fc-oss-ffmpeg
  3. Run the following command to deploy the application to Function Compute:
    fun deploy
    After you deploy the application, you can view the deployed service and functions on the Services and Functions page.FFmpeg

Modify the function code

The preceding code used to deploy applications is provided only for your reference. You can edit the code based on your business requirements.

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Services and Functions.
  4. Find the function whose code you want to modify in a service and click the name of the function.
    FFmpeg
  5. Click the Code tab. Then, enter your code in the code editor.

    The following example shows the event format of the get_duration function:

    {
        "bucket_name" : "test-bucket",
        "object_key" : "a.mp4"
    }                       

    For more information about the event objects of functions, see the comments in the function code.