【问题标题】:FFMpeg with X265X265 的 FFMpeg
【发布时间】:2014-02-27 23:49:51
【问题描述】:

我目前正在尝试通过 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: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;

}

【问题讨论】:

    标签: pointers casting ffmpeg


    【解决方案1】:

    我现在不太确定如何调用同一个函数

    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的内存了吗?

    【讨论】:

    • 我现在添加了我的解决方案,但问题是 sws_scale 函数不接受 void 指针作为参数!
    • 尝试铸造? sws_scale(convertCtx, &image, &srcstride, 0, m_height, (uint8_t*)pic_in.planes,pic_in.stride);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    • 2019-01-25
    相关资源
    最近更新 更多