• 大小: 9.82MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-05
  • 语言: 其他
  • 标签: libx264  

资源简介

本资源是通过opencv 采集摄像头图像(bgr24图像格式),使用libx264将(bgr24)图像编码为h264视频编码格式。开发环境位vs2013. 详情请参考博客:http://blog.csdn.net/qq_21193563/article/details/78692908

资源截图

代码片段和文件信息

// bolgLibx264.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include 
#include 
#include 

#if defined ( __cplusplus)
extern “C“
{
#include 
#include “x264.h“
};
#else
#include “x264.h“
#endif

using namespace std;
using namespace cv;

#define WIDTH 640
#define HEIGHT 480
#define VENC_FPS 30

typedef struct __X264_ENCODER__
{

x264_t* m_pX264Handle;
x264_param_t* m_pX264Param;

x264_picture_t* m_pX264Pic_out;
x264_picture_t* m_pX264Pic_in;
x264_nal_t* m_pX264Nals;
int m_x264iNal;
FILE *m_x264Fp;
}X264Encoder;

void initX264Encoder(X264Encoder &x264Encoderchar *filePath)
{
x264Encoder.m_x264Fp = fopen(filePath “wb“);
x264Encoder.m_pX264Param = (x264_param_t *)malloc(sizeof(x264_param_t));
assert(x264Encoder.m_pX264Param);
x264_param_default(x264Encoder.m_pX264Param);
x264_param_default_preset(x264Encoder.m_pX264Param “veryfast“ “zerolatency“);
x264_param_apply_profile(x264Encoder.m_pX264Param “baseline“);
x264Encoder.m_pX264Param->i_threads = X264_THREADS_AUTO;//X264_SYNC_LOOKAHEAD_AUTO; // 取空缓冲区继续使用不死锁的保证

// 视频选项
x264Encoder.m_pX264Param->i_width = WIDTH; // 要编码的图像宽度.
x264Encoder.m_pX264Param->i_height = HEIGHT; // 要编码的图像高度

// 帧率
x264Encoder.m_pX264Param->b_vfr_input = 0;//0时只使用fps控制帧率
int m_frameRate = VENC_FPS;
x264Encoder.m_pX264Param->i_fps_num = m_frameRate; // 帧率分子
x264Encoder.m_pX264Param->i_fps_den = 1; // 帧率分母
x264Encoder.m_pX264Param->i_timebase_den = x264Encoder.m_pX264Param->i_fps_num;
x264Encoder.m_pX264Param->i_timebase_num = x264Encoder.m_pX264Param->i_fps_den;
x264Encoder.m_pX264Param->b_intra_refresh = 0;
x264Encoder.m_pX264Param->b_annexb = 1;
//m_pX264Param->b_repeat_headers = 0;
x264Encoder.m_pX264Param->i_keyint_max = m_frameRate;

x264Encoder.m_pX264Param->i_csp = X264_CSP_BGR;//X264_CSP_I420;// 
x264Encoder.m_pX264Param->i_log_level = X264_LOG_INFO;//X264_LOG_DEBUG;

x264Encoder.m_x264iNal = 0;
x264Encoder.m_pX264Nals = NULL;
x264Encoder.m_pX264Pic_in = (x264_picture_t *)malloc(sizeof(x264_picture_t));
if (x264Encoder.m_pX264Pic_in == NULL)
exit(1);
else
memset(x264Encoder.m_pX264Pic_in 0 sizeof(x264_picture_t));
//x264_picture_alloc(m_pX264Pic_in X264_CSP_I420 m_pX264Param->i_width m_pX264Param->i_height);
x264_picture_alloc(x264Encoder.m_pX264Pic_in X264_CSP_BGR x264Encoder.m_pX264Param->i_width x264Encoder.m_pX264Param->i_height);
x264Encoder.m_pX264Pic_in->i_type = X264_TYPE_AUTO;

x264Encoder.m_pX264Pic_out = (x264_picture_t *)malloc(sizeof(x264_picture_t));
if (x264Encoder.m_pX264Pic_out == NULL)
exit(1);
else
memset(x264Encoder.m_pX264Pic_out 0 sizeof(x264_picture_t));
x264_picture_init(x264Encoder.m_pX264Pic_out);
x264Encoder.m_pX264Handle = x264_encoder_open(x264Encoder.m_pX264Param);
assert(x264Encoder.m_pX264Handle);
}

void convertframeToX264Img(x264_image_t *x264InImgMat &frame)
{
//RGB方式
int srcSize

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-12-02 10:43  bolgLibx264\
     目录           0  2017-12-02 10:34  bolgLibx264\bolgLibx264\
     文件    17104896  2017-12-02 10:43  bolgLibx264\bolgLibx264.sdf
     文件         979  2017-12-02 09:35  bolgLibx264\bolgLibx264.sln
     文件       20480  2017-12-02 10:43  bolgLibx264\bolgLibx264.v12.suo
     文件        4688  2017-12-02 10:34  bolgLibx264\bolgLibx264\bolgLibx264.cpp
     文件        4653  2017-12-02 10:27  bolgLibx264\bolgLibx264\bolgLibx264.vcxproj
     文件        1318  2017-12-02 09:35  bolgLibx264\bolgLibx264\bolgLibx264.vcxproj.filters
     目录           0  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\
     文件        3042  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.log
     文件      281763  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.obj
     文件     1638400  2017-12-02 09:41  bolgLibx264\bolgLibx264\Debug\bolgLibx264.pch
     目录           0  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.tlog\
     文件         160  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.tlog\bolgLibx264.lastbuildstate
     文件        1434  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.tlog\cl.command.1.tlog
     文件       23016  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.tlog\CL.read.1.tlog
     文件        1030  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.tlog\CL.write.1.tlog
     文件        2940  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.tlog\link.command.1.tlog
     文件        7352  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.tlog\link.read.1.tlog
     文件         540  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\bolgLibx264.tlog\link.write.1.tlog
     文件       11573  2017-12-02 09:41  bolgLibx264\bolgLibx264\Debug\stdafx.obj
     文件      691200  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\vc120.idb
     文件     1347584  2017-12-02 10:34  bolgLibx264\bolgLibx264\Debug\vc120.pdb
     文件     1560186  2015-01-09 20:02  bolgLibx264\bolgLibx264\libx264.dll
     文件      244022  2015-01-09 20:02  bolgLibx264\bolgLibx264\libx264.lib
     文件     1716224  2017-12-02 10:34  bolgLibx264\bolgLibx264\myCamera.h264
     文件        1588  2017-08-21 15:29  bolgLibx264\bolgLibx264\opencv249.props
     文件       60073  2008-11-06 11:37  bolgLibx264\bolgLibx264\pthreadGC2.dll
     文件        1538  2017-12-02 09:35  bolgLibx264\bolgLibx264\ReadMe.txt
     文件         217  2017-12-02 09:35  bolgLibx264\bolgLibx264\stdafx.cpp
     文件         234  2017-12-02 09:35  bolgLibx264\bolgLibx264\stdafx.h
............此处省略12个文件信息

评论

共有 条评论