tencent cloud

Feedback

Horizontal-to-Vertical Video Transformation Tutorial

Last updated: 2024-11-29 15:41:53

    Overview

    About Horizontal-to-Vertical Video Transformation

    Horizontal-to-vertical video transformation is not merely a rotation but involves identifying the region of interest (ROI) and cropping a video to a certain proportion suitable for playback on mobile devices. Horizontal-to-vertical video transformation enables batch generation of short videos and allows existing horizontal video resources to be converted into vertical video resources.
    Intelligent cropping is performed by following the ROI (typically the location of the ball in sports videos) when the video is converted into a vertical one.
    Intelligent cropping is performed by following the ROI (typically the location of the ball in sports videos) when the video is converted into a vertical one.
    

    Input and Output Formats

    The input video files support the following formats:
    Encoding standards: MPEG, H.264, and H.265.
    Container formats: .mp4, .avi, .mkv, .mov, and .mpg.
    The output video files are uniformly encoded in H.264 and formatted in .mp4. You can preview videos using the Google Chrome browser. If you require transcoding and remuxing of formats, you can process it locally or use the audio/video transcoding feature provided by Media Processing Service (MPS).

    Integration Method 1: Initiating a Task via API

    1. Calling an API

    You can directly initiate a POST request to Tencent Cloud. The API request domain name is mps.tencentcloudapi.com. Call the MPS API, select AiAnalysisTask, and set Definition to 28 (preset horizontal-to-vertical video transformation template). ExtendedParameter is an extended parameter, and its value is an escaped JSON string. For specific parameter meanings, see Extended Parameter Description below.
    
    
    

    Request Example

    Note:
    Currently, the horizontal-to-vertical video transformation feature supports two input sources: Tencent Cloud Object Storage (COS) and URL download addresses. AWS S3 is currently not supported.
    {
    "Action": "ProcessMedia",
    "Version": "2019-06-12",
    "InputInfo": {
    "Type": "URL",
    "UrlInputInfo": {
    "Url": "https://..." // Replace it with the URL of the video that needs horizontal-to-vertical transformation, or refer to the "ProcessMedia" API document.
    }
    },
    "OutputStorage": {
    "CosOutputStorage": {
    "Bucket": "BucketName",
    "Region": "BucketRegion"
    },
    "Type": "COS"
    },
    "OutputDir": "/mycos/htv_test/result/",
    "AiAnalysisTask": {
    "Definition": 28, // Preset horizontal-to-vertical video transformation template ID.
    "ExtendedParameter": "{\\"htv\\": {\\"AlgorithmType\\": 1}}"
    }
    "TaskNotifyConfig": {
    "NotifyType": "URL",
    "NotifyUrl": "http://callback_url"
    }
    }

    2. API Explorer Quick Verification

    You can perform quick verification through API Explorer. After filling in relevant parameter information on the page, you can initiate an online API call.
    
    
    
    Note:
    API Explorer will automatically convert the format. You only need to enter the corresponding ExtendedParameter in JSON format without converting it to a string. If calling the API directly, you need to escape the JSON string.

    3. Extended Parameter Description

    Extended parameters can enable specific capabilities. Since the MPS API cannot parse extended parameters, the value of ExtendedParameter is a serialized JSON string. The ExtendedParameter for horizontal-to-vertical video transformation should be placed under htv. Below is an example of a JSON before serialization. Input the escaped parameters when using the API:
    {
    "htv": {
    "AlgorithmType": 3,
    "FaceDetectConfig": {
    "FaceScoreThd": 80
    }
    }
    }
    // Before escaping (usable in API Explorer): {"htv": {"AlgorithmType": 3, "FaceDetectConfig": {"FaceScoreThd": 80}}}
    // After escaping (required when the API is called directly): {\\"htv\\": {\\"AlgorithmType\\": 3, \\"FaceDetectConfig\\": {\\"FaceScoreThd\\": 80}}}
    Name
    Type
    Description
    AlgorithmType
    Integer
    Designated Algorithm Categories:
    1: a general model with a relatively rapid processing speed.
    2: supports a variety of models and is tailored for optimization.
    3: Utilizes a precise face detection algorithm; when two faces are detected, they are displayed in a split-screen format, with efforts made to center the faces as much as possible.
    Ratio
    String
    Video aspect ratio, which is a string and parsed internally. If parsing fails, the default value of 9:16 is used for cropping (for example, "9:16" indicates converting to a video with an aspect ratio of 9:16, taking the original video's height).
    FaceDetectConfig
    FaceDetectConfig
    Face detection configurations.
    FaceDetectConfig
    Name
    Type
    Description
    FaceScoreThd
    Integer
    The recognition threshold for the face detection algorithm. A face is considered valid only when the recognition score exceeds this threshold.

    4. Querying Task Results

    Task callbacks: When initiating an MPS task using ProcessMedia, you can set callback information through the TaskNotifyConfig parameter. After the task is completed, the task results will be called back through the configured callback information. You can parse the event notification results through ParseNotification. The related data structures listed below are provided for reference.
    Query via the DescribeTaskDetail API:
    For tasks started with the API and a template as described in Integration Method 1 above, use the TaskId from ProcessMedia (for example: 24000022-WorkflowTask-b20a8exxxxxxx1tt110253) to parse AiAnalysisResultSet in WorkflowTask. The related data structures listed below are provided for reference.
    For tasks started via ProcessMedia without a template but with a ScheduleId(the subsequent section on automatic task triggering explains how to create a schedule), the returned TaskId will include "ScheduleTask" (e.g. 24000022-ScheduleTask-774f101xxxxxxx1tt110253). In this scenario, use the TaskId to parse ActivityResultSet in ScheduleTask.
    For tasks initiated from the console, as described in Integration Method 2 below, go to Tasks -> VOD for the task ID and results. You can also parse theActivityResultSet in ScheduleTask in the DescribeTaskDetail API to obtain the task results.
    Query via console: Log in to the console and go to VOD Processing Tasks, where the newly initiated tasks are displayed in the task list.
    
    
    
    When the subtask status is "Successful", you can go to COS Bucket > Output Bucket, find your output directory, and locate the files starting with htv- in the directory, which are the output videos after horizontal-to-vertical video transformation.
    
    
    

    Related Data Structures

    AiAnalysisTaskHorizontalToVerticalResult
    Horizontal-to-vertical video transformation result type.
    Referenced by the following APIs: DescribeTaskDetail and ParseNotification.
    Name
    Type
    Description
    Status
    String
    Task status, including PROCESSING, SUCCESS, and FAIL.
    ErrCode
    Integer
    Error code. 0: Successful; other values: Failed.
    Message
    String
    Error message.
    Input
    AiAnalysisTaskHorizontalToVerticalInput
    Horizontal-to-vertical video transformation task input.
    Output
    AiAnalysisTaskHorizontalToVerticalOutput
    Horizontal-to-vertical video transformation task output. Note: This field may return null, indicating that no valid value is obtained.
    AiAnalysisTaskHorizontalToVerticalInput
    Horizontal-to-vertical video transformation task input type.
    Referenced by the following APIs: DescribeTaskDetail and ParseNotification.
    Name
    Type
    Description
    Definition
    Integer
    Horizontal-to-vertical video transformation template ID.
    AiAnalysisTaskHorizontalToVerticalOutput
    Horizontal-to-vertical video transformation result information.
    Referenced by the following APIs: DescribeTaskDetail and ParseNotification.
    Name
    Type
    Description
    Path
    String
    Horizontal-to-vertical video transformation list.
    OutputStorage
    TaskOutputStorage
    Storage location of videos after horizontal-to-vertical transformation. Note: This field may return null, indicating that no valid value is obtained.

    Integration Method 2: Initiating a Task from Console (Zero Code)

    1. Creating a Task

    1.1 Log in to the MPS console and click Create Task > Create VOD Processing Task.
    
    
    
    1.2 Specify an input video file. Currently, the horizontal-to-vertical video transformation feature supports two input sources: Tencent Cloud COS and URL download addresses. AWS S3 is currently not supported.
    1.3 In the "Process Input File" step, add the Intelligent Analysis node.
    
    
    
    In the intelligent analysis settings drawer that pops up, select the **preset horizontal-to-vertical video transformation template (template ID: 28)**.
    Note:
    If you need to enable the horizontal-to-vertical video transformation feature for a custom intelligent analysis template, you can contact us and provide the template ID, and Tencent Cloud MPS developers will configure and enable the horizontal-to-vertical video transformation feature for you.
    
    
    
    1.4 After specifying the save path for the output video, click Create to initiate the task.
    
    
    

    2. Querying Task Results

    Refer to the above Querying Task Results.

    3. Automatically Triggering a Task (Optional Capability)

    If you require automatically performing horizontal-to-vertical video transformation according to the preset parameters after a video file is uploaded in the COS bucket, you can:
    3.1 When creating a task, click Save The Orchestration, and configure parameters such as Trigger Bucket and Trigger Directory in the pop-up window.
    
    
    
    3.2 Go to the VOD Orchestration list, find the new orchestration, and turn on the switch at Enable. Subsequently, any new video files added to the trigger directory will automatically initiate tasks according to the preset process and parameters of the orchestration, and the processed video files will be saved to the output path configured in the orchestration.
    Note:
    It takes 3-5 minutes for the orchestration to take effect after being enabled.
    
    
    
    
    
    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