作者:張醫博
案例:
傳入的截圖時間無效,無論傳多少值,都隻截取視訊的第一幀
排查:
如果選則是關鍵幀截圖,需要看好關鍵幀的間隔設定,。可以參考下官網的 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 轉碼首幀總是黑屏

當送出的截圖是。"frameType":"intra" 時,并且視訊的黑色元素占比較高時截圖出來的可能會是黑屏,可以通過如下參數組合嘗試重新截圖。
time=0 num=1. blacklevel=90。
用戶端請求 MTS 送出轉碼任務并設定截圖,并按照 1s 的 interval 截圖,視訊很長但是隻截取到幾張圖。
遇到問題可以按照以下思路排查:
- 優先看下用戶端送出的截圖參數 format_type 截圖類型,是 intrl 關鍵幀截圖還是 normal 普通截圖。如果是 intrl 截圖設定了 interval 也是沒用的。
- 如果是關鍵幀截圖,看下視訊的關鍵幀有多少,和截圖的數量是不是一緻的,如果一緻就對了。
- 如果是普通截圖的話就會按照 interval 的間隔來截圖。