iphone - 从 Iphone Core Surface RGB 帧转换为 ffmpeg AVFrame

标签 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);   

请帮帮我。

谢谢

拉古

最佳答案

这将解决问题:

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

不过,不要浪费时间,您不应该按照 St3fan 的建议使用 Surface。应用程序将被拒绝。

关于iphone - 从 Iphone Core Surface RGB 帧转换为 ffmpeg AVFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2396407/

相关文章:

ios - UITextView exclusionPaths 右下角

ios - 将数据存储在自定义类中的 NSArray 中并在其他类/ Controller 中使用

node.js - Node ffmpeg模块卡住了多个文件

ffmpeg - 如何删除白框?

video - 使用 FFMPEG 将许多帧合并为一个视频?

iOS 7.1 UIModalPresentationCustom 警告消息

iphone - ResignFirstResponder 不会关闭键盘 (iPhone)

iphone - NSString 上的 NSRegularExpression 不起作用

android - 是否有可以存储 GSM-EFR 语音数据的文件容器?

php - 无法在 laravel 项目的文件中加载 FFMpeg