#include "stdint.h"
#include <stdio.h>
#include <stdlib.h>
extern "C"
{
#include "x264.h"
}
#define width 640
#define height 360
int main(int argc, char **argv)
{
int i;
int j;
int frame_num = 100;
int csp = X264_CSP_I420;
int n_nal = 0;
int ret;
FILE* read_filename = fopen("test_yuv420p.yuv", "rb");
FILE* write_filename = fopen("test.h264", "wb");
if (read_filename == NULL || write_filename == NULL)
{
printf("Error open files.\n");
return -1;
}
x264_param_t* param = (x264_param_t*)malloc(sizeof(x264_param_t));
x264_param_default(param);
x264_picture_t* pic_in = (x264_picture_t*)malloc(sizeof(x264_picture_t));
x264_picture_t* pic_out = (x264_picture_t*)malloc(sizeof(x264_picture_t));
param->i_width = width;
param->i_height = height;
//param->i_fps_num = 25;
//param->i_fps_den = 1;
//param->i_frame_total = 0;
//param->i_threads = X264_SYNC_LOOKAHEAD_AUTO;
//param->i_log_level = X264_LOG_DEBUG;
//param->i_bframe = 5;
//param->b_open_gop = 0;
//param->i_bframe_adaptive = X264_B_ADAPT_TRELLIS;
//param->i_bframe_pyramid = 0;
//param->i_timebase_den = param->i_fps_num;
//param->i_timebase_num = param->i_fps_den;
//param->i_keyint_max = 25;
//param->rc.i_bitrate = 96;
//param->rc.i_qp_max = 0;
//param->rc.i_qp_min = 0;
//param->b_annexb = true;
//param->b_intra_refresh = 1;
x264_param_apply_profile(param, "baseline");
param->i_csp = csp;
x264_t *m_h = NULL;
x264_t *encoder=NULL;
x264_picture_init(pic_out);
x264_picture_alloc(pic_in, csp, param->i_width, param->i_height);
x264_nal_t *my_nal;
x264_nal_t *nal = NULL;
nal = (x264_nal_t *)malloc(sizeof(x264_nal_t));
encoder = x264_encoder_open(param);
if (frame_num == 0)
{
fseek(read_filename, 0, SEEK_END);
frame_num = ftell(read_filename) / (width * height * 3 / 2);
fseek(read_filename, 0, SEEK_SET);
}
for (i = 0; i < frame_num; i++)
{
int y_size = width*height;
fread(pic_in->img.plane[0], y_size, 1, read_filename);
fread(pic_in->img.plane[1], y_size / 4, 1, read_filename);
fread(pic_in->img.plane[2], y_size / 4, 1, read_filename);
pic_in->i_pts = i;
ret = x264_encoder_encode(encoder, &nal, &n_nal, pic_in, pic_out);
if (ret < 0)
{
printf("Error.\n");
return -1;
}
printf("Succeed encode frame: %5d\n", i);
for (j = 0; j < n_nal; ++j)
{
fwrite(nal[j].p_payload, 1, nal[j].i_payload, write_filename);
}
}
i = 0;
while (1)
{
ret = x264_encoder_encode(encoder, &nal, &n_nal, NULL, pic_out);
if (ret == 0)
{
break;
}
printf("Flush 1 frame.\n");
for (j = 0; j < n_nal; ++j)
{
fwrite(nal[j].p_payload, 1, nal[j].i_payload, write_filename);
}
i++;
}
x264_picture_clean(pic_in);
x264_encoder_close(encoder);
encoder = NULL;
free(pic_in);
free(pic_out);
free(param);
fclose(read_filename);
fclose(write_filename);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
最简单的X264编码(win7+vs2013)
共29个文件
tlog:6个
h:3个
pdb:2个
5星 · 超过95%的资源 需积分: 11 34 下载量 197 浏览量
2017-12-12
21:54:52
上传
评论 2
收藏 13.69MB RAR 举报
温馨提示
最简单的X264编码(win7+vs2013),只能对本地文件编码,内部包括了X264的需要的lib、dll和头文件。
资源推荐
资源详情
资源评论
收起资源包目录
X264-encode.rar (29个子文件)
X264-encode
X264-encode.sln 979B
X264-encode.v12.suo 19KB
Debug
X264-encode.pdb 500KB
X264-encode.ilk 250KB
libx264.dll 1.49MB
X264-encode.exe 33KB
pthreadGC2.dll 100KB
X264-encode.sdf 2.88MB
X264-encode
X264-encode.vcxproj 4KB
Debug
X264-encode.log 1KB
vc120.pdb 68KB
X264-encode.Build.CppClean.log 1KB
main.obj 12KB
vc120.idb 51KB
X264-encode.tlog
cl.command.1.tlog 766B
CL.read.1.tlog 1KB
link.read.1.tlog 2KB
link.write.1.tlog 582B
CL.write.1.tlog 604B
link.command.1.tlog 1KB
X264-encode.lastbuildstate 181B
x264.h 45KB
x264_config.h 172B
test.h264 2.67MB
X264-encode.vcxproj.filters 1KB
libx264.lib 238KB
stdint.h 6KB
main.cpp 3KB
test_yuv420p.yuv 32.96MB
共 29 条
- 1
资源评论
- zhxl01252019-01-30正在调试用
- yy10694421422019-08-29为什么我下载下来后生成的h264文件是0字节呢?
为取经而来
- 粉丝: 101
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功