/***********************************************************************
*作者:HJL
*编写日期:2015.7.16
*效果:x264软件编码,将输入的yuv视频文件编码为h264视频文件
*程序中要设置2处:
*1.设置视频的宽高
*2.设置待转码yuv视频的路径
************************************************************************/
#include <iostream>
#include <string>
#include "stdint.h"
//#include <time.h>
extern "C"
{
#include "x264.h"
#include "x264_config.h"
};
int main(int argc, char** argv)
{
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//设置视频的宽度、高度
int width = 480;
int height = 272;
///////////////////////////////////////////////////////////
int fps = 25;//设置帧率
size_t yuv_size = width * height * 3 / 2;
x264_t *encoder;
x264_picture_t pic_in, pic_out;
uint8_t *yuv_buffer;
x264_param_t param;
x264_param_default_preset(¶m, "veryfast", "zerolatency");
param.i_threads = 1;
param.i_width = width;
param.i_height = height;
param.i_fps_num = fps;//视频数据帧率
param.i_fps_den = 1;
param.i_keyint_max = 25;
param.b_intra_refresh = 1;
param.b_annexb = 1;
x264_param_apply_profile(¶m, "baseline");
encoder = x264_encoder_open(¶m);
x264_picture_alloc(&pic_in, X264_CSP_I420, width, height);
yuv_buffer =(uint8_t*) malloc(yuv_size);
pic_in.img.plane[0] = yuv_buffer;
pic_in.img.plane[1] = pic_in.img.plane[0] + width * height;
pic_in.img.plane[2] = pic_in.img.plane[1] + width * height / 4;
int64_t i_pts = 0;
x264_nal_t *nals;
int nnal;
/////////////////////////////////////////////////////////////////////////////
//读取yuv视频文件,即待转码yuv文件
FILE *inf=fopen("ds_480x272.yuv","rb");
//* 创建文件,用于存储编码数据
FILE *outf=fopen("test.h264","ab");
if(NULL==inf)
{
return -1;
}
//clock_t start,end;
//float cpuTime;
//start=time(NULL);
while (fread(yuv_buffer, 1, yuv_size,inf) > 0)
{
pic_in.i_pts = i_pts++;
x264_encoder_encode(encoder, &nals, &nnal, &pic_in, &pic_out);
x264_nal_t *nal;
for (nal = nals; nal < nals + nnal; nal++)
{
fwrite( nal->p_payload, 1, nal->i_payload,outf);//写h264
}
}
//end=time(NULL);
//cpuTime=(float)(end-start);
//printf("cuptime= %f mseconds\n",cpuTime);
x264_encoder_close(encoder);
fclose(inf);
fclose(outf);
free(yuv_buffer);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
x264Test.rar (44个子文件)
x264Test
x264Test
x264lib
libx264-132.lib 286KB
x264.h 44KB
x264_config.h 172B
Debug
cl.command.1.tlog 614B
link.10172-rc.read.1.tlog 2B
CL.read.1.tlog 13KB
link-cvtres.read.1.tlog 2B
link.read.1.tlog 3KB
link.10172-cvtres.read.1.tlog 2B
link.write.1.tlog 414B
CL.write.1.tlog 334B
link.10172-rc.write.1.tlog 2B
link.12864.read.1.tlog 2B
link.12864-rc.write.1.tlog 2B
x264Test.log 2KB
vc110.idb 347KB
link.10172.read.1.tlog 2B
link.12864-cvtres.read.1.tlog 2B
link.10172-cvtres.write.1.tlog 2B
link.command.1.tlog 1KB
vc110.pdb 356KB
x264Test.obj 140KB
link.12864-cvtres.write.1.tlog 2B
link.10172.write.1.tlog 2B
link-rc.write.1.tlog 2B
link.12864.write.1.tlog 2B
x264Test.lastbuildstate 62B
link-cvtres.write.1.tlog 2B
link-rc.read.1.tlog 2B
link.12864-rc.read.1.tlog 2B
unistd.h 113B
x264Test.cpp 2KB
test.h264 231KB
x264Test.vcxproj 4KB
ds_480x272.yuv 18.68MB
x264Test.vcxproj.filters 946B
libx264-132.dll 1.36MB
pthreadGC2.dll 59KB
Debug
x264Test.exe 62KB
x264Test.pdb 811KB
x264Test.ilk 462KB
x264Test.sln 891B
x264Test.v11.suo 24KB
x264Test.sdf 7.69MB
共 44 条
- 1
hjl240
- 粉丝: 142
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页