pointers - X265 的 FFMpeg

标签 pointers casting ffmpeg

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

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

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:in 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;

}

最佳答案

And I am now not quite sure how to call the same function

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



试过了吗?:
 sws_scale(convertCtx, &image, &srcstride, 0, m_height, pic_in.planes,pic_in.stride);

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

关于pointers - X265 的 FFMpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22083263/

相关文章:

ffmpeg - 有没有人通过 RTMP 获得 FFMPEG 的 Windows 版本以发布到 Akamai 的 CDN?

c++ - 如何在模板中返回 lambda 指针?

常量和指向指针的指针

delphi - 无需手动设置每个字段值即可将数据写入 PVirtualNode

mongodb - 如何将 Mongoose 聚合结果转换为特定的文档模式类型?

batch-file - 在 ffmpeg 中出现错误 'too many inputs specified for the "scale"filter'

c++ - *(int*)(buffer) 是什么意思?

c - 使用 SSE 进行快速双 -> 短转换并进行钳位?

typescript - 为什么可以将 'any' 分配给任何类型而无需先显式转换它?

video - ffmpeg 视频到图像序列批处理文件