tencent cloud

Feedback

How to Transcode Videos

Last updated: 2023-05-15 17:39:49

    Instructions

    Overview

    This document describes how to transcode videos stored in VOD and how to get the outputs.

    Costs

    The open-source code provided in this document is free, but the following costs may incur.
    Fees for purchasing a Tencent Cloud CVM instance to execute TencentCloud API requests. For more information, see CVM Billing Mode.
    Fees for storing videos in VOD. For details, see Pay-As-You-Go and Prepaid Packages.
    Fees for transcoding videos stored in VOD. For details, see Pay-As-You-Go and Prepaid Packages.
    Fees for playing videos stored in VOD. For details, see Pay-As-You-Go and Prepaid Packages.

    Parameters

    VOD supports the following formats for transcoding:
    Type
    Parameter
    Description
    Input
    Container format
    WMV, RM, MOV, MPEG, MP4, 3GP, FLV, AVI, RMVB, TS, ASF, MPG, WEBM, MKV, M3U8, WM, ASX, RAM, MPE, VOB, DAT, MP4V, M4V, F4V, MXF, QT, and OGG.
    Video codec
    AV1, AVS2, H.264/AVC, H.263, H.263+, H.265, MPEG-1, MPEG-2, MPEG-4, MJPEG, VP8, VP9, QuickTime, RealVideo, Windows Media Video
    Output
    Container format
    Video: FLV, MP4, HLS (M3U8 + TS)
    Audio: MP3, MP4, Ogg, FLAC, M4A
    Image: GIF, WebP.
    Video codec
    H.264/AVC, H.265/HEVC, AV1
    The target specifications of a transcoding task include codec, resolution, bitrate, and others. VOD uses templates to represent different combinations of these parameters. For details, see Video Processing - Overview.
    Category
    Parameter
    Description
    Video encoding
    Codec
    H.264, H.265, and AV1 codecs are supported.
    Bitrate
    Supported bitrate range: 10 Kbps - 35 Mbps.
    Frame rate
    Supported frame rate range: 1-60 fps; common values: 24, 25, and 30.
    Resolution
    Supported width range: 128 px - 4096 px.
    Supported height range: 128 px - 4096 px.
    GOP length
    Supported GOP length range: 1-10s
    Profile
    When the video codec is H.264, the baseline, main, and high profiles are supported.
    When the video codec is H.265, only the main profile is supported.
    Color space
    YUV420p is supported.
    Note:
    Codec: A method of converting video files from a certain format into another using specific compression technology. Compared with H.264, H.265 uses more advanced encoding techniques and can transcode videos at much lower bitrates (which means lower bandwidth costs) without compromising video quality.
    Bitrate: The size of data encoded by the encoder per second, in kbps. For example, 800 kbps indicates that the encoder generates 800 KB of data per second.
    Frame rate: The number of frames per second.
    Resolution: The number of pixels per inch.
    GOP: The number of frames between two I-frames.
    For general transcoding, we recommend the following resolution and bitrate combinations:
    Definition
    Recommended Bitrate
    Recommended Resolution
    Resolution Range
    SD
    600
    640 x 480
    SD (short side ≤ 480 px)
    HD
    2000
    1280 x 720
    HD (short side ≤ 720 px)
    FHD
    4000
    1920 x 1080
    FHD (short side ≤ 1080 px)
    2K
    6000
    2560 x 1440
    2K (short side ≤ 1440 px)
    4K
    8000
    3840 x 2160
    4K (short side ≤ 2160 px)
    VOD's Top Speed Codec (TSC) solution integrates image quality remaster and enhancement, adaptive parameter selection, and V265 encoder, among other video processing features. It can transcode videos to higher quality at lower bitrates, helping you save network resource costs while delivering a better viewing experience. For TSC transcoding, we recommend the following resolution and bitrate combinations:
    Definition
    Recommended Bitrate
    Recommended Resolution
    Resolution Range
    SD
    350 or leave it empty
    640 x 480
    SD (short side ≤ 480 px)
    HD
    1350 or leave it empty
    1280 x 720
    HD (short side ≤ 720 px)
    FHD
    2700 or leave it empty
    1920 x 1080
    FHD (short side ≤ 1080 px)
    2K
    3500 or leave it empty
    2560 x 1440
    2K (short side ≤ 1440 px)
    4K
    7500 or leave it empty
    3840 x 2160
    4K (short side ≤ 2160 px)
    Note:
    If bitrate is left empty, VOD will set the minimum bitrate automatically based on intelligent analysis of the source video.

    Initiating Transcoding Through the Console

    Step 1. Activate VOD

    Activate VOD. For detailed directions, see Getting Started - Step 1. Activate VOD.

    Step 2. Upload a video

    Upload a test video. For detailed directions, see Getting Started - Step 2. You can download the video used in this document here. The file ID generated is 3270835008936537687.
    
    Note:
    To avoid the transcoding taking too much time, we recommend you use a short video (dozens of seconds) for test .

    Step 3. Initiate transcoding

    1. On the Video/Audio Management page of the VOD console, select the video you uploaded, and click Transcoding.
    
    2. Select Transcoding as the processing type and select a transcoding template.
    
    3. Click Confirm. As an example, the preset templates STD-H264-MP4-360P (ID 100010) and STD-H264-MP4-540P (ID 100020) are selected in this document. For directions on how to use a custom transcoding template, see Template Configuration.
    
    4. Click Confirm.
    
    5. Go to Task Center. If the status of the task is "Completed", the video has been successfully transcoded.
    

    Step 4. Get the transcoding output

    1. In the VOD console, select the target application. On the Media Assets > Video/Audio Management page, if the status of your test video is "Normal", transcoding is finished. Click Manage on the right to enter the details page.
    
    2. Under the Transcoding outputs tab, you will find the transcoding outputs generated by the TD-H264-MP4-360P and STD-H264-MP4-540P templates. You can click Preview on the right to play the video or copy the playback URL and share it to others.
    

    Calling TencentCloud APIs to initiate transcoding

    Step 1. Prepare a CVM instance

    TencentCloud API script needs to be executed on a CVM instance that meets the following requirements:
    Region: No limit.
    Model: The minimum specification (1 CPU core and 1 GB memory) or higher.
    Public network: A public IP address is required, and the bandwidth should be at least 1 Mbps.
    Operating system: Official public image Ubuntu Server 16.04.1 LTS 64-bit or Ubuntu Server 18.04.1 LTS 64-bit.
    For detailed directions on how to purchase a CVM instance and reinstall the system, see Operation Guide - Creating Instances via CVM Purchase Page and Operation Guide - Reinstalling System.
    Note:
    If you do not have a CVM instance that meets the above conditions, you can also run the script on other Linux (such as CentOS or Debian) or macOS servers with public network access, but you need to modify certain commands in the deployment script based on the operating system.

    Step 2. Obtain the TencentCloud API key

    An API key (SecretId and SecretKey) is required for calling TencentCloud APIs. If you have not created an API key yet, create one as instructed in Creating an API key for a root account. If you have already created a key, follow the steps in Viewing an API key of a root account to view the key.

    Step 3. Activate VOD

    Activate VOD. For detailed directions, see Getting Started - Step 1. Activate VOD.

    Step 4. Upload a video

    Upload a test video. For detailed directions, see Getting Started - Step 2. You can download the video used in this document here.
    
    Note:
    To avoid the transcoding taking too much time, we recommend you use a short video (dozens of seconds) for test .

    Step 5. Initiate transcoding

    1. Log in to the CVM instance prepared in Step 1 and run the following command on the remote terminal:
    ubuntu@VM-69-2-ubuntu:~$ export SECRET_ID=AKxxxxxxxxxxxxxxxxxxxxxxx; export SECRET_KEY=xxxxxxxxxxxxxxxxxxxxx;git clone https://github.com/tencentyun/vod-server-demo.git ~/vod-server-demo; bash ~/vod-server-demo/installer/transcode_api.sh
    Note:
    You need to assign values to SECRET_ID and SECRET_KEY according to the key obtained in Step 2.
    2. The above command will download the demo source code from GitHub and automatically run the installation script. The installation process will take several minutes (subject to the CVM network conditions), during which the remote terminal will print the following information:
    [2020-06-15 20:39:56] Start installing pip3.
    [2020-06-15 20:40:06] pip3 is successfully installed.
    [2020-06-15 20:40:06] Start installing TencentCloud API Python SDK.
    [2020-06-15 20:40:07] TencentCloud API Python SDK is installed.
    [2020-06-15 20:40:07] Start configuring API parameters.
    [2020-06-15 20:40:07] API parameters are configured.
    3. Execute the process_media.py script to initiate transcoding.
    ubuntu@VM-69-2-ubuntu:~$ cd ~/vod-server-demo/transcode_api/; python3 process_media.py 243791581340253754
    Note:
    You need to replace 243791581340253754 in the command with the file ID generated in Step 4.
    4. This command will initiate a ProcessMedia request for the video 243791581340253754, transcode the video according to the preset templates 100010 and 100020, and print the response:
    {"TaskId": "1400329073-procedurev2-f6bf6f01612369b6db30f2224792a2aft0", "RequestId": "809918fb-791c-4937-b684-5027ba6bc5f0"}

    Step 6. Get the transcoding output

    1. Go to Task Center. If the status of the task is "Completed", the video has been successfully transcoded.
    
    2. When the status of the test video changes to "Normal", the transcoding is finished. Click Manage on the right to enter the details page.
    
    3. Under the Transcoding outputs tab, you will find the transcoding outputs generated. You can click Preview on the right to play the video or copy the playback URL and share it to others.
    

    Auto Transcoding After Uploading (Task Flow)

    VOD supports multiple upload methods, including upload through the console, upload from the server, upload from a client and upload by pulling from URLs. Whatever method you use, you can specify a task flow to automatically transcode the video after it is uploaded.

    Auto Transcoding After Uploading (Event Notification)

    VOD will send notification requests for both uploading and transcoding events. You can initiate transcoding tasks for newly uploaded videos based on the event notifications as well as get the transcoding results from notifications (or from the console as described above). For details about how to use event notifications, see How to Receive Event Notification.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support