ios ffmpeg h264 decode
来源:互联网 发布:单片机实验报告总结 编辑:程序博客网 时间:2024/06/02 02:16
ios使用ffmpeg解码h264数据封装。
#import "FFMpegAVCDecoder.h"#ifdef __cplusplusextern "C" {#endif #include <libavutil/opt.h>#include <libavcodec/avcodec.h>#include <libavformat/avformat.h>#include <libswscale/swscale.h> #ifdef __cplusplus};#endif@interface FFMpegAVCDecoder(){ AVCodec *_videoCodec; AVCodecContext *_pCodecCtx; AVFrame *_pFrame; char* _yuvBuf;}@end@implementation FFMpegAVCDecoder-(int)initDecoder{ av_register_all(); /* find the video encoder */ _videoCodec = avcodec_find_decoder(AV_CODEC_ID_H264); _pCodecCtx = avcodec_alloc_context3(_videoCodec); if (!_videoCodec) return -1; _pCodecCtx->time_base.num = 1; _pCodecCtx->frame_number = 1; //每包一个视频帧 if(avcodec_open2(_pCodecCtx, _videoCodec,NULL) >= 0) _pFrame = av_frame_alloc();// Allocate video frame else return -1; return 0;}-(int)decode:(char *)buf len:(int)len{ int frameFinished = len; AVPacket packet = { .data = (uint8_t*)buf, .size = len, }; avcodec_decode_video2(_pCodecCtx, _pFrame, &frameFinished, &packet); if(frameFinished)//成功解码 { int picSize = _pCodecCtx->height * _pCodecCtx->width; int newSize = picSize * 3/2; if (!_yuvBuf) { _yuvBuf = (char*)malloc(newSize); } int height = _pCodecCtx->height; int width = _pCodecCtx->width; //写入数据 int pos=0,i; for (i=0; i<height; i++) { memcpy(_yuvBuf+pos,_pFrame->data[0] + i * _pFrame->linesize[0], width); pos+=width; } for (i=0; i<height/2; i++) { memcpy(_yuvBuf+pos,_pFrame->data[1] + i * _pFrame->linesize[1], width/2); pos+=width/2; } for (i=0; i<height/2; i++) { memcpy(_yuvBuf+pos,_pFrame->data[2] + i * _pFrame->linesize[2], width/2); pos+=width/2; } //TODO:解码数据回调 } return 0;}-(void)freeDecoder{ if(_pCodecCtx){ avcodec_close(_pCodecCtx); _videoCodec = NULL; } if (_pFrame) { av_frame_free(&_pFrame); _pFrame = NULL; } if (_yuvBuf) { free(_yuvBuf); _yuvBuf = NULL; }}@end
阅读全文
0 0
- ios ffmpeg h264 decode
- ffmpeg decode raw h264
- 来源于 原创 分类 ios 5.0 ffmpeg decode h264 stream
- ios ffmpeg audio decode
- ffmpeg H264 decode for Android Native Surface
- ios ffmpeg h264 encode
- FFMPEG Intro - decode h264 raw video by ffmpeg
- 【FFMPEG】从内存中获取H264数据并进行decode
- ios ffmpeg 实时视频压缩(主要是H264)
- iOS FFmpeg实时YUV420P编码H264
- ffmpeg h264
- Exploit FFmpeg Libraries to Decode Raw H264 File in Windows, Which Supports Multithread-Decoding
- H264 encode and decode
- H264---5 decode
- ios 6.1下ffmpeg真机库带h264编码解码
- ios一步一步编译ffmpeg,x264实现h264编码
- ios一步一步编译ffmpeg,x264实现h264编码
- iOS ffmpeg将音视频写入文件aac+h264
- Swift 类
- 朴素贝叶斯算法
- ubuntu terminator字体挤在一起问题 大小设置
- 用户时间数据的检查
- MyEclipse2015修改项目Web-root
- ios ffmpeg h264 decode
- MYSQL慢查询(一):开启慢查询
- 机器视觉的情感判断实践(From Pixels to Sentiment: Fine-tuning CNNs for Visual Sentiment Prediction)
- kubernetes简介
- java freemaker 导出word文档 高逼格教程
- 序列模式挖掘算法之PrefixSpan
- JAVA值传递
- 安卓activity中onResume()的用处
- 【机器学习实战】第3章 决策树