最近做了个视频项目,分享下源码。
掌握一个主线:视频原始数据-->FFMPeg -->YUV-->RGB-->UIImage
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .h文件
#import <AVFoundation/AVFoundation.h>
#include "libavformat/avformat.h"
#include <libavutil/opt.h>
#include <libavutil/audioconvert.h>
#include <libavutil/common.h>
#include <libavutil/imgutils.h>
#include <libavutil/mathematics.h>
#include <libavutil/samplefmt.h>
#include <libswscale/swscale.h>
@interface VideioDecoder : NSObject {
AVCodecContext *codetext;
struct SwsContext * scxt420;
AVFrame *frame420;
AVFrame *frameRgba;
NSRecursiveLock* _fLock;
int _nOldWidth;
int _nOldHeight;
}
+ (VideioFrameDecoder *)shareInstance;
- (void)initFFMPEG;
- (void)didFinish:(NSData *)data Len:(int)nLen;
@end
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// .m文件
// 以单例形式处理
static VideioDecoder *instance = nil;
+ (VideioDecoder *)shareInstance {
@synchronized(self) {
if (nil == instance) {
instance = [[self alloc] init];
}
}
retur

本文介绍了如何在iOS项目中利用FFmpeg库解码H264格式的视频数据,从原始数据转换为UIImage对象。通过创建AVCodecContext,设置解码参数,解码视频帧,并使用SwsContext进行色彩空间转换,最终得到可以在iOS应用中显示的RGB图像。
最低0.47元/天 解锁文章
6541

被折叠的 条评论
为什么被折叠?



