開發與維運

媒體處理 MTS-截圖問題

作者:張醫博

案例:

傳入的截圖時間無效,無論傳多少值,都只截取視頻的第一幀

排查:

如果選則是關鍵幀截圖,需要看好關鍵幀的間隔設置,。可以參考下官網的 java 代碼,測試是過是可以生成多張的。

package com.aliyun.mts;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.mts.model.v20140618.*;
public class Snapshot {
    private static String accessKeyId = "xxx";
    private static String accessKeySecret = "xxx";
    private static String mpsRegionId = "cn-hangzhou";
    private static String pipelineId = "xxx";
    private static String ossLocation = "oss-cn-hangzhou";
    private static String ossBucket = "xxx";
    private static String ossInputObject = "input.mp4";
    private static String ossOutputObject = "output_{Count}.jpg";
    public static void main(String[] args) {
        // DefaultAcsClient
        DefaultProfile profile = DefaultProfile.getProfile(
                mpsRegionId,      // Region ID
                accessKeyId,      // AccessKey ID
                accessKeySecret); // Access Key Secret
        IAcsClient client = new DefaultAcsClient(profile);
        // request
        SubmitSnapshotJobRequest request = new SubmitSnapshotJobRequest();
        // Input
        JSONObject input = new JSONObject();
        input.put("Location", ossLocation);
        input.put("Bucket", ossBucket);
        try {
            input.put("Object", URLEncoder.encode(ossInputObject, "utf-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("input URL encode failed");
        }
        request.setInput(input.toJSONString());
        // SnapshotConfig
        JSONObject snapshotConfig = new JSONObject();
        // SnapshotConfig->OutputFile
        JSONObject output = new JSONObject();
        output.put("Location", ossLocation);
        output.put("Bucket", ossBucket);
        try {
            output.put("Object", URLEncoder.encode(ossOutputObject, "utf-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("output URL encode failed");
        }
        snapshotConfig.put("OutputFile", output.toJSONString());
        // SnapshotConfig->Time
        snapshotConfig.put("Time", "2");
        // SnapshotConfig->Interval/Num
        snapshotConfig.put("Interval", "2");
        snapshotConfig.put("Num", "3");
        // SnapshotConfig->Width/Height
        snapshotConfig.put("Height", "360");
        // SnapshotConfig
        request.setSnapshotConfig(snapshotConfig.toJSONString());
        // PipelineId
        request.setPipelineId(pipelineId);
        // call api
        SubmitSnapshotJobResponse response;
        try {
            response = client.getAcsResponse(request);
            System.out.println("RequestId is:"+response.getRequestId());
            System.out.println("JobId is:" + response.getSnapshotJob().getId());
            System.out.println(String.format(
                                        "http://%s.%s.aliyuncs.com/output_00001.jpg",
                                        ossBucket,
                                        ossLocation));
            System.out.println(String.format(
                                        "http://%s.%s.aliyuncs.com/output_00002.jpg",
                                        ossBucket,
                                        ossLocation));
            System.out.println(String.format(
                                        "http://%s.%s.aliyuncs.com/output_00003.jpg",
                                        ossBucket,
                                        ossLocation));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

案例:

媒體處理設置 CBR 轉碼後均失敗

排查:

媒體處理提供了轉碼轉碼模式的轉碼

  • CBR 模式下,如果設置了固定碼率需要結合 maxrate minrate vbv 三個參數才能用,CBR 要求保持的碼率是恆定的,不能有波動,比如運動比較大的畫面。
  • ONEPASS 模式下,用戶可以設置客戶端設置的固定碼率,允許碼率有波動。
  • TWO PASS 模式下,在第一次其實是檢測收集運動啊亮度等相關數據,這樣在第二次編碼的時候就會針對不同的場景來進行動態的壓縮編碼。二次編碼比一次編碼質量要好一些的。但是編碼時間也會增加不少。使用二次編碼可以把變化不大的畫面轉換時碼率低一些(如靜態畫面),而變化大的碼率高一些(如打鬥動作部分),這樣碼率是變化的,可以使整部影片的清晰度比較均勻,只有在轉換高清影片時二次編碼才能發揮最大做用。
結論:

更改 ONEPASS 模式後問題解決。

案例:

MTS 轉碼首幀總是黑屏

排查:

image.png

當提交的截圖是。"frameType":"intra" 時,並且視頻的黑色元素佔比較高時截圖出來的可能會是黑屏,可以通過如下參數組合嘗試重新截圖。

time=0 num=1. blacklevel=90。

案例:

客戶端請求 MTS 提交轉碼任務並設置截圖,並按照 1s 的 interval 截圖,視頻很長但是隻截取到幾張圖。

排查:

遇到問題可以按照以下思路排查:

  • 優先看下客戶端提交的截圖參數 format_type 截圖類型,是 intrl 關鍵幀截圖還是 normal 普通截圖。如果是 intrl 截圖設置了 interval 也是沒用的。
  • 如果是關鍵幀截圖,看下視頻的關鍵幀有多少,和截圖的數量是不是一致的,如果一致就對了。
  • 如果是普通截圖的話就會按照 interval 的間隔來截圖。

Leave a Reply

Your email address will not be published. Required fields are marked *