从Iphone Core Surface RGB Frame转换为ffmpeg AVFrame

时间:2010-03-07 13:33:08

标签: iphone ffmpeg

我正在尝试将Core Surface RGB帧缓冲区(Iphone)转换为ffmpeg Avfarme以编码为电影文件。但我没有得到正确的视频输出(视频显示的颜色令人眼花缭乱而不是正确的图片)

我认为从核心表面帧缓冲区转换为AVFrame有问题。

这是我的代码:

Surface *surface = [[Surface alloc]initWithCoreSurfaceBuffer:coreSurfaceBuffer];
[surface lock];
unsigned int height = surface.height;
unsigned int width = surface.width;
unsigned int alignmentedBytesPerRow = (width * 4);
if (!readblePixels) {
    readblePixels = CGBitmapAllocateData(alignmentedBytesPerRow * height);
    NSLog(@"alloced readablepixels");
}
unsigned int bytesPerRow = surface.bytesPerRow;
void *pixels = surface.baseAddress;
for (unsigned int j = 0; j < height; j++) {
    memcpy(readblePixels + alignmentedBytesPerRow * j, pixels + bytesPerRow * j, bytesPerRow);
}

pFrameRGB->data[0] = readblePixels; // I guess here is what I am doing wrong.
pFrameRGB->data[1] = NULL;
pFrameRGB->data[2] = NULL;
pFrameRGB->data[3] = NULL;

pFrameRGB->linesize[0] = pCodecCtx->width;
pFrameRGB->linesize[1] = 0;
pFrameRGB->linesize[2] = 0;
pFrameRGB->linesize[3] = 0;


sws_scale (img_convert_ctx, pFrameRGB->data, pFrameRGB->linesize,
       0, pCodecCtx->height,
       pFrameYUV->data, pFrameYUV->linesize);   

请帮帮我。

谢谢,

Raghu

1 个答案:

答案 0 :(得分:3)

这将解决问题:

pFrameRGB->linesize[0] = pCodecCtx->width * 4; // linesize includes total bytes for the line (ARGB)

不要浪费时间,但你不应该像St3fan建议的那样使用Surface。应用程序将被拒绝。