资源简介
通过V4L2采集YUYV(YUV422)数据,然后使用x264编码库将数据编码成H264视频。详细内容请见博客 http://blog.csdn.net/li_wen01/article/details/56282443
代码片段和文件信息
/*=============================================================================
# FileName: h264encoder.c
# Desc: this program aim to get image from USB camera
# used the V4L2 interface.
# Author: licaibiao
# Version:
# LastChange: 2017-02-21
=============================================================================*/
#include
#include
#include
#include “./include/h264encoder.h“
int WIDTH = 640;
int HEIGHT = 480;
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
WIDTH = width;
HEIGHT = height;
//en->param->i_frame_total = 0;
//en->param->i_keyint_max = 10;
en->param->rc.i_lookahead = 0;
//en->param->i_bframe = 5;
//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 = 30;
en->param->i_fps_den = 1;
en->param->i_csp = X264_CSP_I422;
x264_param_apply_profile(en->param x264_profile_names[4]);
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);
}
int compress_frame(Encoder *en int type uint8_t *in uint8_t *out) {
x264_picture_t pic_out;
int index_y index_u index_v;
int num;
int nNal = -1;
int result = 0;
int i = 0;
static long int pts = 0;
uint8_t *p_out = out;
char *y = en->picture->img.plane[0];
char *u = en->picture->img.plane[1];
char *v = en->picture->img.plane[2];
char * ptr;
index_y = 0;
index_u = 0;
index_v = 0;
num = WIDTH * HEIGHT * 2 - 4 ;
for(i=0; i {
*(y + (index_y++)) = *(in + i);
*(u + (index_u++)) = *(in + i + 1);
*(y + (index_y++)) = *(in + i + 2);
*(v + (index_v++)) = *(in + i + 3);
}
switch (type) {
case 0:
en->picture->i_type = X264_TYPE_P;
break;
case 1:
en->picture->i_type = X264_TYPE_IDR;
break;
case 2:
en->picture->i_type = X264_TYPE_I;
break;
default:
en->picture->i_type = X264_TYPE_AUTO;
break;
}
en->picture->i_pts = pts++;
if (x264_encoder_encode(en->handle &(en->nal) &nNal en->picture
&pic_out) < 0) {
return -1;
}
for (i = 0; i < nNal; i++) {
memcpy(p_out en->nal[i].p_payload en->nal[i].i_payload);
p_out += en->nal[i].i_payload;
result += en->nal[i].i_payload;
}
return result;
}
void compress_end(Encoder *en) {
if (en->han
相关资源
- X264编码H264视频
- linux下关于Qt界面的摄像头v4l2操作源码
- Linux PC下UVC摄像头采集并用x264进行编
- SONY IMX264 Data Sheet
- x264库(64位and32位)
- linux+QT下基于RTP协议的实时视频传输客
- v4l2采集+yuyv转yuv420p+h264编码+tcp传输
- 视频编解码---x264用于编码,ffmpeg用于
- webcam(含有编译好的ffmpegx264z库)
- linux+qt+v4l2 摄像头视频捕捉--源代码
- Linux下使用Qt+V4L2测试UVC相机
- x264-snapshot-20170415-2245.tar.bz2
- 基于v4l2的qt视频实时显示
- libx264.zip
- v4l2 USB摄像头图像采集程序C
- linux下基于V4L2/Qt的usb摄像头采集显示
- v4l2采集MJPG保存到本地
- linux qt4.7 v4l2 YUV(YUYV) mmap 显示视频
- V4L2 通过JRTPLIB 实现RTP实时视频传输并
- singleCamD
- MAX9286的V4L2测试代码
- webcam_v4l2_x264
- 嵌入式平台ARm9使用V4L2格式摄像头抓帧
- linux下基于QT和v4l2驱动的USB摄像头视频
- 智能家居的项目用的 V4L2
- v4l2采集视频并保存和lcd显示
- v4l2 QT MJPEG格式 视频采集+屏幕显示+图
- 使用Linux的V4L2读取摄像头数据+Opencv图
- v4l2 qt实时显示摄像头数据未使用ope
- 2014 libx264 最新 64bit
评论
共有 条评论