我们有原始流数据,我们使用 Kitkat 上的 MediaCodec 本机代码对其进行解码和渲染。
考虑我们的视频分辨率为 800 X 480,实际视频内容为 800 X 380。顶部和底部高度边距各 50 像素包含黑色区域。在表面上渲染时需要裁剪黑色区域(100 像素)。
尝试了 setRect 方法来裁剪矩形,但没有奏效。
例子:
int32_t left, top, right, bottom;
if (format->findRect("crop", &left, &top, &right, &bottom))
{
left = 0, top = 100, right = 800, bottom = 380;
format->setRect("crop", left, top, right, bottom);
}
Run Code Online (Sandbox Code Playgroud)
另外,尝试在配置格式时设置Mediacodec中指定的crop-left,crop-right,crop-top,crop-bottom,这也未能裁剪。例子:
format.setInteger("crop-left", 0);
format.setInteger("crop-top", 100);
format.setInteger("crop-right", 800);
format.setInteger("crop-bottom", 380);
Run Code Online (Sandbox Code Playgroud)
您能否提出一种裁剪视频的方法,以便裁剪后的视频可以在表面上呈现。