从AVFrame - ffmpeg复制一个矩形区域 [英] Copy a rectangular area from AVFrame - ffmpeg
问题描述
我正在尝试拉出AVFrame的矩形区域,并开始执行这样一个功能。我只想使用格式为PIX_FMT_RGB24的AVFrames。我也可能在这里重新发明一下,所以如果已经有了这个功能,请跳进去。到目前为止,我的功能如下所示:
I am trying to pull out a rectangular area of an AVFrame and have started on a function that will do so. I'm only interested in using AVFrames that are format PIX_FMT_RGB24. I may be reinventing the wheel a bit here too, so please jump in if there is already a function to do this. So far my function looks like this:
AVFrame * getRGBsection(AVFrame *pFrameRGB, const int start_x, const int start_y, const int w, const int h) {
AVFrame *pFrameSect;
int numBytes;
uint8_t *mb_buffer;
pFrameSect = avcodec_alloc_frame();
numBytes = avpicture_get_size(PIX_FMT_RGB24, w, h);
mb_buffer = (uint8_t *) av_malloc(numBytes * sizeof(uint8_t));
avpicture_fill((AVPicture *) pFrameSect, mb_buffer, PIX_FMT_RGB24, w, h);
int curY, curX, i = 0;
for (curY = start_y ; curY < (start_y + h); curY++) {
for (curX = start_x; curX < (start_x + w); curX++) {
int curIndex = curX * 3 + curY * pFrameRGB->linesize[0];
pFrameSect->data[0][i] = pFrameRGB->data[0][curIndex];
pFrameSect->data[0][i + 1] = pFrameRGB->data[0][curIndex + 1];
pFrameSect->data[0][i + 2] = pFrameRGB->data[0][curIndex + 2];
i += 3;
}
}
return pFrameSect;
}
该功能似乎工作,当我从(0, 0)(我想),但是当我移动到图像的其他地方时,会输出与应该在那里的颜色相似但不对的颜色。我觉得我在这里很近,有人可以提供指导吗?
The function seems to work when I start at (0,0) (I think) but when I move elsewhere in the image it outputs colors similar to what should be there but isn't right. I think I am very close here, can anyone offer guidance?
推荐答案
-
2个选项
there are 2 options
- 用户视频过滤器(vf_crop)。 (filter_video.c提供实际使用作品的示例)imgconvert.c中的
- 函数av_picture_crop()。此功能不完整,但您可以修改它以供使用。
这篇关于从AVFrame - ffmpeg复制一个矩形区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!