简体   繁体   English

带X265的FFMpeg

[英]FFMpeg with X265

I am currently trying to encode raw RGB24 images via x265. 我目前正在尝试通过x265编码原始RGB24图像。 I already successfully did this with the x264 library, but a few things have changed as compared to the x265 library. 我已经使用x264库成功完成了此操作,但是与x265库相比,有些事情发生了变化。

Here the problem in short: I want to convert the image I have from RGB24 to YUV 4:2:0 via the sws_scale function of FFMPEG. 简而言之,这里的问题是:我想通过FFMPEG的sws_scale函数将RGB24的图像转换为YUV 4:2:0。 The prototype of the function is: 该函数的原型是:

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

Assuming image contains my raw image, srcstride and `m_height' the corresponding RGB stride and height of my image, I made the following call with x264 假设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 is of type x264_picture_t which looks (brief) as follows pic_in的类型为x264_picture_t ,其外观如下:

typedef struct
{
    ...
    x264_image_t img;

} x264_picture_t;

with x264_image_t x264_image_t

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

} x264_image_t;

Now, in x265 the structures have slightly changed to 现在,在x265中,结构已稍微更改为

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

} x265_picture;

And I am now not quite sure how to call the same function 我现在不太确定如何调用相同的函数

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

I tried creating a temporary array, and then copying back and recasting the array items, but it doesnt seem to work 我尝试创建一个临时数组,然后复制并重铸该数组项,但是它似乎不起作用

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

Can someone help me out? 有人可以帮我吗?

Thanks a lot :) 非常感谢 :)

Edit 编辑

I figured it out now 我现在想通了

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

This seems to do the trick :) 这似乎可以解决问题:)

And btw, for other people who are experiment with x265:in x264 there was a x264_picture_alloc function which I didn't manage to find in x265. 顺便说一句,对于其他尝试使用x265的人:在x264中,有一个x264_picture_alloc函数,但我在x265中找不到。 So here is a function which I used in my application and which does the trick. 因此,这是我在应用程序中使用的函数,可以完成此操作。

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.stride);

tried with?: 尝试过吗?:

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

what error do you have? 你有什么错误? have you initialized memory of x265_picture? 您是否已初始化x265_picture的内存?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM