ios libx264 h264 encode
来源:互联网 发布:淘宝卖家批量怎么发货 编辑:程序博客网 时间:2024/05/22 06:13
#import "X264Encode.h"#include "x264.h"#define KEY_FRAME_INTERVAL 30typedef struct{ x264_param_t * param; x264_t *handle; x264_picture_t * picture; x264_nal_t *nal;} X264EncodeParam;@interface X264Encode(){ X264EncodeParam* _x264Param; char* _h264Buf; long _frameCnt;}@end@implementation X264Encode- (int)initEncoder:(int)width height:(int)height bitrate:(int)bitrate{ _frameCnt = 0; _h264Buf = (char*)malloc(width*height); _x264Param = (X264EncodeParam *) malloc(sizeof(X264EncodeParam)); _x264Param->param = (x264_param_t *) malloc(sizeof(x264_param_t)); _x264Param->picture = (x264_picture_t *) malloc(sizeof(x264_picture_t)); x264_param_default(_x264Param->param); //set default param //_x264Param->param->rc.i_rc_method = X264_RC_CQP; _x264Param->param->rc.i_rc_method = X264_RC_ABR ; _x264Param->param->rc.i_bitrate = bitrate; _x264Param->param->i_log_level = X264_LOG_NONE; _x264Param->param->i_width = width; //set frame width _x264Param->param->i_height = height; //set frame height _x264Param->param->rc.i_lookahead =0; _x264Param->param->i_bframe=0; _x264Param->param->i_fps_num =5; _x264Param->param->i_fps_den = 1; if ((_x264Param->handle = x264_encoder_open(_x264Param->param)) == 0) { return -1; } x264_nal_t* p_nal; int i_nal; x264_encoder_headers(_x264Param->handle, &p_nal, &i_nal); int i; for(i=0;i<i_nal;i++) { if(p_nal[i].i_type == NAL_SPS) { //TOTO:返回sps,p_nal[i].p_payload,p_nal[i].i_payload } if(p_nal[i].i_type == NAL_PPS) { //TOTO:返回pps,p_nal[i].p_payload,p_nal[i].i_payload } } /* Create a new pic */ x264_picture_alloc(_x264Param->picture, X264_CSP_I420, _x264Param->param->i_width, _x264Param->param->i_height); return 0;}- (void)encodeSampleBufToH264:(CMSampleBufferRef)sampleBuffer{ }- (void)encodeBufToH264:(char*)yuv420p{ x264_picture_t pic_out; int i_data=0; int nNal=-1; int len=0; int i=0; int nPicSize = _x264Param->param->i_width*_x264Param->param->i_height; memcpy(_x264Param->picture->img.plane[0],yuv420p,nPicSize); memcpy(_x264Param->picture->img.plane[1],yuv420p+nPicSize,nPicSize/4); memcpy(_x264Param->picture->img.plane[2],yuv420p+(nPicSize*5/4),nPicSize/4); if (_frameCnt % KEY_FRAME_INTERVAL == 0) { _x264Param->picture->i_type = X264_TYPE_IDR; }else{ _x264Param->picture->i_type = X264_TYPE_AUTO; } _frameCnt++; if( x264_encoder_encode( _x264Param->handle, &(_x264Param->nal), &nNal, _x264Param->picture ,&pic_out) < 0 ) { return; } char* pTmpOut = _h264Buf; for (i = 0; i < nNal; i++){ memcpy(pTmpOut, _x264Param->nal[i].p_payload, _x264Param->nal[i].i_payload); pTmpOut += _x264Param->nal[i].i_payload; len += _x264Param->nal[i].i_payload; //TODO:回调编码数据 } printf("Succeed to encode frame: %5ld\tsize:%5d\n", _frameCnt, len);}- (void)free{ if(_x264Param->picture) { x264_picture_clean(_x264Param->picture); free(_x264Param->picture); _x264Param->picture = NULL; } if(_x264Param->param) { free(_x264Param->param); _x264Param->param = NULL; } if(_x264Param->handle) { x264_encoder_close(_x264Param->handle); } if (_x264Param) { free(_x264Param); _x264Param = NULL; } if (_h264Buf) { free(_h264Buf); _h264Buf = NULL; }}@end
阅读全文
0 0
- ios libx264 h264 encode
- ios ffmpeg h264 encode
- Ffmpeg Install With Libx264 (H264)
- H264 encode and decode
- H264--4 encode
- yuv encode h264 test
- ios 编译libx264,libfaac
- ios ffmpeg+libx264
- H264 encode and decode overview
- H264 encode and decode overview
- H264 encode and decode overview
- h264 encode and decode success
- iOS 使用libx264编码视频
- iOS 使用libx264编码视频
- capture(yuv422) -> h264 encode(yuv420) -> h264 -> h264 decode(yuv420)
- 【iOS开发】编译libx264和带libx264的FFMpeg包
- 【媒体流】libx264 将rgb24格式转换为h264
- H264 CAVLC encode procedure example 1
- 和为S的连续正数序列
- 三种经典iPhone上网络抓包方法详解
- 为什么我们要这么拼?
- 日常问题总结(7)
- html响应式--媒体播放
- ios libx264 h264 encode
- 高德地图的一下方法
- Android 数据存储(二)文件存储
- 细说ASP.NET控制HTTP缓存
- Myeclipse SVN 修改用户名和密码详解
- Android AppcompatActivity隐藏标题栏
- 策略模式
- 第23讲项目3-两段函数求值
- mybatis和Springmvc系统将数据从数据库传送到前台的总流程