资源简介
Linux下用V4L2采集视频,并用x264编码成h264视频

代码片段和文件信息
#include
#include
#include
#include “h264encoder.h“
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;
int i = 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];
int is_y = 1 is_u = 1;
int y_index = 0 u_index = 0 v_index = 0;
int yuv422_length = 2 * en->param->i_width * en->param->i_height;
//序列为YU YV YU YV,一个yuv422帧的长度 width * height * 2 个字节
for (i = 0; i < yuv422_length; ++i) {
if (is_y) {
*(y + y_index) = *(in + i);
++y_index;
is_y = 0;
} else {
if (is_u) {
*(u + u_index) = *(in + i);
++u_index;
is_u = 0;
} else {
*(v + v_index) = *(in + i);
++v_index;
is_u = 1;
}
is_y = 1;
}
}
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;
}
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->picture) {
x264_picture_clean(en->picture);
free(en->picture);
en->picture = 0;
}
if (en->param) {
free(en->param);
en->param = 0;
}
if (en->handle) {
x264_encoder_close(en->handle);
}
free(en);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 972945 2012-05-01 13:19 camera\bin\camera_h264encode
文件 245 2012-04-17 05:42 camera\include\x264_config.h
文件 40894 2012-03-30 20:45 camera\include\x264.h
文件 1026684 2012-04-29 07:42 camera\lib\libx264.a
目录 0 2012-05-01 13:19 camera\bin\
文件 3020 2012-05-01 13:12 camera\h264encoder.c
文件 3552 2012-05-01 07:54 camera\h264encoder.c~
文件 553 2012-05-01 13:13 camera\h264encoder.h
文件 564 2012-04-30 16:58 camera\h264encoder.h~
文件 15336 2012-05-01 13:19 camera\h264encoder.o
目录 0 2012-05-01 13:19 camera\include\
目录 0 2012-04-30 16:28 camera\lib\
文件 1444 2012-05-01 13:14 camera\main.c
文件 1711 2012-05-01 06:32 camera\main.c~
文件 11108 2012-05-01 13:19 camera\main.o
文件 300 2012-04-30 16:59 camera\Makefile
文件 331 2012-04-30 16:58 camera\Makefile~
文件 7754 2012-05-01 13:15 camera\video_capture.c
文件 7754 2012-05-01 13:15 camera\video_capture.c~
文件 895 2012-05-01 13:14 camera\video_capture.h
文件 936 2012-04-29 13:11 camera\video_capture.h~
文件 31944 2012-05-01 13:19 camera\video_capture.o
- 上一篇:HDCP 2.2 Spec.
- 下一篇:OpenGL入门教程高清完整
相关资源
- LSI 3ware 6Gb提高视频采集和编辑的吞吐
- 基于V4L2的视频采集,能够采集YUVJPE
- 在QT中使用RTP进行视频的采集和传输
- 基于STM32F407的视频采集与传输系统设
- 从零开始学习音视频编程技术十二 录
- 使用RTMPdump(libRTMP)直播来自v4l2的摄
- 云视通视频采集卡
- 关于视频采集卡二次开发全攻略
- 基于arm的视频采集系统设计与实现
- qt5_V4L2_Camera 实现摄像头实时画面显示
- v4l2中文手册(规范)全五章(包含驱
- 基于嵌入式Linux的视频采集系统设计
- 京东评价图片和视频采集软件
- 山寨四路视频采集卡/EasyCap usb 2 DVR
- USB视频采集卡驱动
- directshow实现的视频采集程序AVCap
- USB摄像头通过v4l2技术采集、储存视频
- V4L2采集YUYV数据x264编码成H264视频
- qt+opencv的视频采集 与保存
- linux系统下基于QT的usb摄像头视频采集
- linux下关于Qt界面的摄像头v4l2操作源码
- OpenCV图像视频采集 DirectShow 64位32位库
- 基于嵌入式Linux与S3C2410平台的视频采
- 基于ARM和Linux的嵌入式视频采集存储系
- linux+QT下基于RTP协议的实时视频传输客
- v4l2采集+yuyv转yuv420p+h264编码+tcp传输
- 基于FPGA的视频采集系统
- 虚拟摄像头Filter代码--VirtualCamFilter_
- 抖音、火山小视频采集软件,附带使
- linux+qt+v4l2 摄像头视频捕捉--源代码
评论
共有 条评论