Reputation: 319
I want to decode an encrypted H264 video file on iOS. I already have ported our decryption algorithm and it is working fine. However, we cannot directly use H264 hardware decoder due to lack of API in SDK.
So I am trying to find an alternative to decode H264 video. I am trying to use FFmpeg to decode these video even if there are some possible LGPL license issues. I decode H264 video without any problems and I render H264 frames thanks to OpenGL ES texture. But there are some performance issues. I instrumented my code and the bottleneck is the ffmpeg rescaling and YUV to RGB conversion. I know that I can use OpenGL ES 2.0 shaders to convert YUV to RGB with GPU acceleration (related post Alternative to ffmpeg for iOS). I also know how AVFrame structure is composed: data[0] for Y data, data[1] for U data and data[1] for V data. But I do not understand how can I use line size[x] with data[x] to transmit data to OpenGL texture.
Does anybody have an example of AVFrame YUV to OpenGL texture ?
Thanks, David
Upvotes: 3
Views: 4143
Reputation: 31
1.The first method is that you can use libyuv
.
2.you can also use sws_getCachedContext
and sws_scale
two functions in libswscale.a
module of ffmpeg
, like this convert AV_PIX_FMT_YUV420P
to AV_PIX_FMT_0BGR32
:
enum AVPixelFormat dst_format = AV_PIX_FMT_0BGR32;
if (!is->img_convert_ctx)
is->img_convert_ctx = sws_getCachedContext(is->img_convert_ctx, sourceFrame->width, sourceFrame->height, sourceFrame->format, sourceFrame->width, sourceFrame->height, dst_format, SWS_BILINEAR, NULL, NULL, NULL);
uint8_t *data[AV_NUM_DATA_POINTERS];
int linesize[AV_NUM_DATA_POINTERS];
av_image_alloc(data, linesize, sourceFrame->width, sourceFrame->height, dst_format, 1);
AVFrame *tempFrame = sourceFrame;
sws_scale(is->img_convert_ctx, (const uint8_t**) tempFrame->data, sourceFrame->linesize, 0, sourceFrame->height, data, linesize);
free(data[0]);
after that,AV_PIX_FMT_0BGR32
data is in data[0]
and linesize[0]
Upvotes: 1