ios使用ffmpeg解码h264数据封装。

#import "FFMpegAVCDecoder.h"
#ifdef __cplusplus
extern "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 frameelse  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

ios ffmpeg h264 decode相关推荐

  1. ios ffmpeg audio decode

    ffmepg解码音频. #import "FFMpegAudioDecoder.h"#ifdef __cplusplus extern "C" { #endif ...

  2. ios ffmpeg h264 encode

    简单封装了下,ffmepg需要包含libx264. #import "FFMpegAVCEncode.h"#ifdef __cplusplus extern "C&quo ...

  3. ffmpeg H264 编解码配置

    ffmpeg H264编解码前面有文章介绍下,本文主要介绍一些参数配置. 编码: int InitEncoderCodec( int iWidth, int iHeight) {AVCodec * p ...

  4. iOS FFmpeg 优秀博客(资源)集锦

    iOS FFmpeg 优秀博客(资源)集锦 这篇博客没有我自己写的内容: 主要是对FFmpeg一些优秀博客的记录 随时更新 1>iOS编译FFmpeg,kxmovie实现视频播放 2>视音 ...

  5. ffmpeg h264解码器分析sps(二)

    ffmpeg h264解码器解析sps下半部分 sps->mb_width = get_ue_golomb(gb) + 1; /*以宏块为单位的宽度*/ sps->mb_height = ...

  6. FFMPEG h264 ACC 合成 mkv ts;h264 mp3 合成 MP4 avi flv

    FFMPEG h264 ACC 合成 mkv ts:h264 mp3 合成 MP4 avi flv #include <stdio.h>#include <cstdio>#in ...

  7. ffmpeg h264解码, 屏蔽因为网络丢包等各种原因导致的花屏帧

     ffmpeg h264解码, 屏蔽因为网络丢包等各种原因导致的花屏帧  ---->看来问题只能这样解决了,现在还要多测测,防止产生新的问题.目前来看,对现有代码没有影响,花屏的帧直接屏蔽掉了. ...

  8. ffmpeg h264+ts +udp传输

    http://bbs.csdn.net/topics/370246456 http://1229363.blog.163.com/blog/static/19743427201001244711137 ...

  9. ffmpeg h264 解码 转

    原作者博客 http://blog.csdn.net/taixinlfx/article/details/7531631 项目需要,要做PC端的解码器,解H264. 一直郁闷,终于今天搞定了.记录如下 ...

最新文章

  1. php 清除之前echo_PHP入门读书笔记(三): 常量和变量
  2. angular.element()的用法
  3. Ajax请求中的async:false/true的作用
  4. 利用windows的rar工具创建自解压安装文件的方法
  5. 使用ASP.NET 2.0进行记录错误
  6. TCP/IP协议族-----10、搬家IP
  7. 冒泡排序 和 归并排序
  8. NOX的使用之学习篇【一】
  9. flume建立ElasticSearch索引时间的问题
  10. tr php,?php } ? 啥意思?
  11. 代码比较工具DiffMerge的下载和使用
  12. var that =this的用法详解
  13. 1元课,学会小学数学应用题,你的孩子也能秒解“鸡兔同笼”
  14. HDU 6143 (容斥)
  15. 微信公众号调取扫一扫功能
  16. 关于单精度浮点型精确位数7~8以及双精度浮点型精确位数15~16的解释
  17. LWN: 名为 Sequoia 的 seq_file 漏洞!
  18. kali linux 打不开终端的问题
  19. 怎么退出自适应巡航_你的自适应巡航“全速”了吗?
  20. dbd mysql db_关于DBD连接mysql数据库

热门文章

  1. 使用bat运行jar文件
  2. 超实用Mac软件分享(二)
  3. 后台处理客户端控件上传的文件(input type=file)
  4. 大学英语四六级写作模板
  5. C# word 转 pdf
  6. python程序启动其他python程序_python中使用fork创建新的进程
  7. css鼠标拖拉卡顿_JavaScript实现元素拖动性能优化
  8. 梅森旋转产生随机数c语言实现,梅森旋转法产生随机数
  9. How to check number of Active connections in SQL server?
  10. 学习python的一些脚本