h.264库在linux编译,H264 X264 linux下的装配?库?lx264

H264 X264 linux下的安装?库?lx264?

这几天在弄视频编码这个东东,在网上搜了好多高人的资料,可惜我是在太笨了,不知道怎么用啊,然后根据一个牛人的程序改改,编译,结果出现个各种奇怪的症状···

105610157.gif命苦啊····

求大神来救救我啊!!!!

是这样的,我的程序是这样的,就是想把已经保存好的YUV420格式的图片,压缩下,看看行不行,网上说X264就是H264的一种,所以想用X264应该就行了啊,我的源码如下:

#include           /* for videodev2.h */

#include               /* low-level i/o */

#include 

#include 

#include 

#include 

#include 

//#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include "h264encoder.h"

#define CLEAR(x) memset (&(x), 0, sizeof (x))

typedef unsigned char uint8_t;

uint8_t *h264_buf;

unsigned int n_buffers = 0;

//int len = 640* 480* 3/2;

Encoder en;

void init_encoder() {

compress_begin(&en, 640, 480);

h264_buf = (uint8_t *) malloc(

sizeof(uint8_t)*640* 480* 3/2); // 设置缓冲区

}

void close_encoder() {

compress_end(&en);

free(h264_buf);

}

void encode_frame(char * yuv_frame, char * output_filename) {

int h264_length = 0;

h264_length = compress_frame(&en, -1, yuv_frame, h264_buf);

if (h264_length > 0) {

//写h264文件

fwrite(h264_buf, h264_length, 1, output_filename);

}

}

int read_and_encode_frame(char * input_filename,char * output_filename) {

FILE *input_file;

FILE *output_file;

if ((/*infile*/input_file = fopen(input_filename, "rb")) == NULL) {

fprintf(stderr, "can't open %s\n", input_filename);

return 0;

}

if ((/*infile*/output_file = fopen(output_filename, "wb")) == NULL) {

fprintf(stderr, "can't open %s\n", output_filename);

return 0;

}

encode_frame(input_file, output_file);

fclose(input_file);

fclose(output_file);

return 1;

}

int main()

{

init_encoder();

read_and_encode_frame("jpgimage1.yuv","jpgimage1.h264");

close_encoder

下面是encoder.h

#ifndef _H264ENCODER_H

#define _H264ENCODER_H

#include 

#include 

#include "x264.h"

typedef unsigned char uint8_t;

typedef struct {

x264_param_t *param;

x264_t *handle;

x264_picture_t *picture; //说明一个视频序列中每帧特点

x264_nal_t *nal;

} Encoder;

void compress_begin(Encoder *en, int width, int height) {

en->param = (x264_param_t *) malloc(sizeof(x264_param_t));

en->picture = (x264_picture_t *) malloc(sizeof(x264_picture_t));

x264_param_default(en->param); //set default param

//en->param->rc.i_rc_method = X264_RC_CQP;//设置为恒定码率

// en->param->i_log_level = X264_LOG_NONE;

// en->param->i_threads  = X264_SYNC_LOOKAHEAD_AUTO;//取空缓存区使用不死锁保证

en->param->i_width = width; //set frame width

en->param->i_height = height; //set frame height

//en->param->i_frame_total = 0;

//  en->param->i_keyint_max = 10;

en->param->rc.i_lookahead = 0; //表示i帧向前缓冲区

//   en->param->i_bframe = 5; //两个参考帧之间b帧的数目

//  en->param->b_open_gop = 0;

//  en->param->i_bframe_pyramid = 0;

//   en->param->i_bframe_adaptive = X264_B_ADAPT_TRELLIS;

//en->param->rc.i_bitrate = 1024 * 10;//rate 为10 kbps

en->param->i_fps_num = 5; //帧率分子

en->param->i_fps_den = 1; //帧率分母

x264_param_apply_profile(en->param, x264_profile_names[0]); //使用baseline

if ((en->handle = x264_encoder_open(en->param)) == 0) {

return;

}

/* Create a new pic */

x264_picture_alloc(en->picture, X264_CSP_I422, en->param->i_width,

en->param->i_height);

en->picture->img.i_csp = X264_CSP_I422;

en->picture->img.i_plane = 3;

}

int compress_frame(Encoder *en, int type, uint8_t *in, uint8_t *out) {

x264_picture_t pic_out;

int nNal = -1;

int result = 0;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值