1

AVFrameの長方形の領域を引き出そうとしていますが、その機能を開始しました。PIX_FMT_RGB24形式のAVFrameの使用にのみ興味があります。私もここで車輪の再発明をしているかもしれませんので、これを行う機能がすでにある場合は、ジャンプしてください。これまでのところ、私の関数は次のようになっています。

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)から開始すると機能するように見えますが(私は思う)、画像内の別の場所に移動すると、本来あるべき色と似た色が出力されますが、正しくありません。私はここにとても近いと思います、誰かがガイダンスを提供できますか?

4

2 に答える 2

1
  • 2つのオプションがあります

    1. ユーザービデオフィルター(vf_crop)。(filtering_video.cは、実際に作物を使用するための例を提供します)
    2. imgconvert.cの関数av_picture_crop()。この機能は完全ではありませんが、使用するために変更することができます。
于 2013-02-05T03:17:49.547 に答える
1

このコードは私のために働きます(RGB24のみ)

#include <libavutil/imgutils.h>

// .....
// left, top
const int crop_left = 500;
const int crop_top = 500;

// output width, height
const int crop_width = 300;
const int crop_height = 200;

AVFrame * rgb24picure;
AVFrame * output;
/// .... initialize ....

const int one_pixel = av_image_get_linesize(PIX_FMT_RGB24, 1, 0);
const int src_line_size = av_image_get_linesize(PIX_FMT_RGB24, source_width, 0);
const int copy_line_size = av_image_get_linesize(PIX_FMT_RGB24, crop_width, 0);

for (int h = crop_top; h < crop_top + crop_height; ++h)
{
    unsigned char * src = rgb24picure->data[0] + src_line_size * h + one_pixel * crop_left;
    unsigned char * dst = output->data[0] + copy_line_size * (h - crop_top);
    memcpy(dst, src, copy_line_size);
}
于 2013-02-05T11:35:49.483 に答える