X264编码
2016-04-20 17:41
162 查看
最近研究了x264 , 果然高效简单,不过还有很多概念有待研究。记录最简单的实现,直接上代码
#include <stdint.h>
#include "x264.h"
#include "x264_config.h"
#include <stdio.h>
int main()
{
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;
int inf,outf;
uint8_t *yuv_buffer;
x264_param_t m_param;
x264_param_default_preset(&m_param,"veryfast","zerolatency");
m_param.i_threads = 1;
m_param.i_width = width;
m_param.i_height = height;
m_param.i_fps_num = fps;
m_param.i_bframe = 10;
m_param.i_fps_den = 1;
m_param.i_keyint_max = 25;
m_param.b_intra_refresh = 1;
m_param.b_annexb = 1;
x264_param_apply_profile(&m_param,"high422");
encoder = x264_encoder_open(&m_param);
x264_encoder_parameters( encoder, &m_param );
x264_picture_alloc(&pic_in, X264_CSP_I420, width, height);
yuv_buffer = 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;
FILE* infile = fopen("ds_480x272.yuv","rb");
FILE* outfile = fopen("out.h264","ab");
if(!infile || !outfile)
{
printf("open file error\n");
return 0;
}
int64_t i_pts = 0;
x264_nal_t *nals;
int nnal;
while (fread(yuv_buffer, 1,yuv_size, infile) > 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,outfile);
}
}
x264_encoder_close(encoder);
close(infile);
close(outfile);
free(yuv_buffer);
return 0;
}
#include <stdint.h>
#include "x264.h"
#include "x264_config.h"
#include <stdio.h>
int main()
{
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;
int inf,outf;
uint8_t *yuv_buffer;
x264_param_t m_param;
x264_param_default_preset(&m_param,"veryfast","zerolatency");
m_param.i_threads = 1;
m_param.i_width = width;
m_param.i_height = height;
m_param.i_fps_num = fps;
m_param.i_bframe = 10;
m_param.i_fps_den = 1;
m_param.i_keyint_max = 25;
m_param.b_intra_refresh = 1;
m_param.b_annexb = 1;
x264_param_apply_profile(&m_param,"high422");
encoder = x264_encoder_open(&m_param);
x264_encoder_parameters( encoder, &m_param );
x264_picture_alloc(&pic_in, X264_CSP_I420, width, height);
yuv_buffer = 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;
FILE* infile = fopen("ds_480x272.yuv","rb");
FILE* outfile = fopen("out.h264","ab");
if(!infile || !outfile)
{
printf("open file error\n");
return 0;
}
int64_t i_pts = 0;
x264_nal_t *nals;
int nnal;
while (fread(yuv_buffer, 1,yuv_size, infile) > 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,outfile);
}
}
x264_encoder_close(encoder);
close(infile);
close(outfile);
free(yuv_buffer);
return 0;
}
相关文章推荐
- 每周总结20130814——Android NDK环境的搭建和使用,YUV420SP格式图像的处理
- YUV转RGB(NV21-ARGB)的Neon优化代码
- YUV转RGB(NV21-ARGB)的Neon优化代码
- SDL显示bmp,SDL播放yuv420P
- RGB与YCbCr颜色空间的转换
- YUV格式详解
- YUV格式基础
- HEVC学习(一) —— HM的使用
- ffmpeg+x264+NeroAac在linux上实现经典的视频压制
- 不同颜色空间的图像转换(RGB到HSV,YUV,Lab)
- ios x264编译问题 No working C compiler found
- iOS FFmpeg实时YUV420P编码H264
- iOS 从摄像头获取YUV420SP数据
- YUV格式详解 .
- yuv和ycrcb的差异
- android ndk 快速渲染yuv数据
- android下MediaCodec硬编码(转)
- 使用ffmpeg生成硬字幕视频
- YUV422转RGB565源码及详解
- sw_scale中实现yuv420转rgb888——neon汇编优化