FFMpeg with X265



我目前正在尝试通过x265对原始RGB24图像进行编码。我已经用x264库成功地做到了这一点,但与x265库相比,有些地方发生了变化。

简而言之,这里的问题是:我想通过FFMPEG的sws_scale函数将我的图像从RGB24转换为YUV 4:2:0。该功能的原型是:

int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) 

假设image包含我的原始图像,srcstride和"m_height"是我图像的相应RGB步幅和高度,我用x264 进行了以下调用

sws_scale(convertCtx, &image, &srcstride, 0, m_height, pic_in.img.plane, pic_in.img.i_stride);

pic_in是x264_picture_t类型,看起来(简短)如下

typedef struct
{
...
x264_image_t img;
} x264_picture_t;

x264_image_t

typedef struct
{
...
int     i_stride[4];
uint8_t *plane[4]; 
} x264_image_t;

现在,在x265中,结构已略微更改为

typedef struct x265_picture
{
...
void*   planes[3];
int     stride[3];
} x265_picture;

我现在不太确定如何调用相同的函数

sws_scale(convertCtx, &image, &srcstride, 0, m_height, ????, pic_in.stride);

我试着创建一个临时数组,然后向后复制并重新创建数组项,但似乎不起作用

pic.planes[i] = reinterpret_cast<void*>(tmp[i]) ;

有人能帮我吗?

非常感谢:)

编辑

我现在明白了

outputSlice = sws_scale(convertCtx, &image, &srcstride, 0, m_height, reinterpret_cast<uint8_t**>(pic_in.planes), pic_in.stride);

这似乎奏效了:)

顺便说一句,对于其他正在试验x265的人来说:在x264中,有一个x264_picture_alloc函数,我在x265中没有找到。这是我在应用程序中使用的一个函数,它起到了关键作用。

void x265_picture_alloc_custom( x265_picture *pic, int csp, int width, int height, uint32_t depth) {
x265_picture_init(&mParam, pic);
pic->colorSpace = csp;
pic->bitDepth = depth;
pic->sliceType = X265_TYPE_AUTO;
uint32_t pixelbytes = depth > 8 ? 2 : 1;
uint32_t framesize = 0;
for (int i = 0; i < x265_cli_csps[csp].planes; i++)
{
uint32_t w = width >> x265_cli_csps[csp].width[i];
uint32_t h = height >> x265_cli_csps[csp].height[i];
framesize += w * h * pixelbytes;
}
pic->planes[0] = new char[framesize];
pic->planes[1] = (char*)(pic->planes[0]) + width * height * pixelbytes;
pic->planes[2] = (char*)(pic->planes[1]) + ((width * height * pixelbytes) >> 2);
pic->stride[0] = width;
pic->stride[1] = pic->stride[2] = pic->stride[0] >> 1;
}

我现在不太确定如何调用相同的函数

sws_scale(convertCtx,&image,&srcstride,0,m_height????,pic_in.spaced);

尝试使用?:

sws_scale(convertCtx, &image, &srcstride, 0, m_height, pic_in.planes,pic_in.stride);

你有什么错误?你初始化x265_picture的内存了吗?

最新更新