当前位置: 代码迷 >> 驱动开发 >> S3C6410的MFC H264编码初始参数的设置解决办法
  详细解决方案

S3C6410的MFC H264编码初始参数的设置解决办法

热度:158   发布时间:2016-04-28 11:19:30.0
S3C6410的MFC H264编码初始参数的设置
有谁用过S3C6410的MFC H264编码吗?编码器初始化的时候会有MFC_ENC_INIT_ARG 结构体的初始化参数设置,里面的参数in_bitrate是根据Y420输入视频码率吗?还有gopnum参数呢?希望用过的能指导下。

------解决方案--------------------
从摄像头实时采集图像到H264编码输出文件的 Demo
前端:包括视频采集模块和视频压缩编码模块。 
实现思路:
视频采集模块使用V4L2 接口收集摄像头数据到缓冲区中,视频压缩模块调用MFC 驱动把YUV420 数据压缩编码,同时可以指定编码参数。
*/
#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <linux/fb.h>
#include "mfc.h"
#include "MfcDrvParams.h"
#include "performance.h"
#define DEV_NAME "/dev/video12"
 
int main(int argc, char *argv[])
{
/*----------------------
//CamIF and OV9650 Config
------------------------*/

//打开camera 设备
 int cam_fp = -1;
 if( (cam_fp = open(DEV_NAME, O_RDWR)) < 0 )
 {
printf("Open Device failed.\n");
return -1;
 }

//V4L2 编程 
struct v4l2_capability cap;
int tmp = -1;
 if((tmp=ioctl(cam_fp, VIDIOC_QUERYCAP, &cap))<0) {
printf("VIDIOC_QUERYCAP error, ret=0x%x\n",tmp);
return -1;
 }
//选择输入/输出 
struct v4l2_input i;
// 枚举所有的输入
//To enumerate all inputs
 memset(&i, 0, sizeof(i));//initialize i.index=0;
/* while(tmp=ioctl(cam_fp, VIDIOC_ENUMINPUT, &i)>=0)//ref V4L2.pdf for VIDIOC_ENUMINPUT
{
printf("input i.name:%s; i.index :%d i.type = %s\n",i.name, i.index, i.type);
i.index++;
}
*/
//究竟应该选哪一个呢?
int index = 0;
i.index = index;//选择index
 if(ioctl(cam_fp, VIDIOC_S_INPUT, &index)<0) //select the specified video input
{
printf("VIDIOC_S_INPUT ERROR\n");
return -1;

/*
To select a video input applications store the number of the desired input in an integer and call the
VIDIOC_S_INPUT ioctl with a pointer to this integer. 
Side effects are possible. For example inputs may support different video standards, 
so the driver may implicitly switch the current standard. 
It is a good practice to select an input before querying or negotiating any other parameters.
Information about video inputs is available using the VIDIOC_ENUMINPUT ioctl.
*/
 if(ioctl(cam_fp, VIDIOC_S_OUTPUT, &index)<0) //select the specified video output
{
printf("VIDIOC_S_OUTPUT ERROR\n");
return -1;
}
//VIDIOC_S_OUTPUT 中的S代表SET, VIDIOC_G_OUTPUT中的G 代表GET 

//设置格式,注意必须设置输出为YUV420 格式 
struct v4l2_framebuffer fb;
 
 ioctl(cam_fp, VIDIOC_G_FBUF, &fb); //VIDIOC_G_FBUF Get frame buffer overlay parameters
printf("fb.capability = %d\n",fb.capability);
printf("fb.fmt.width=%d\n",fb.fmt.width);
printf("fb.fmt.height = %d\n", fb.fmt.height);
printf("initial fb.fmt.pixelformat = %d\n", fb.fmt.pixelformat);
#if 1
static int cap_width,cap_height;
cap_width=640; //LCD 240*320
cap_height=480; //摄像头初始化支持的是VGA640*480
fb.capability = cap.capabilities; 
fb.fmt.width = cap_width; 
fb.fmt.height = cap_height; 
#endif
fb.fmt.pixelformat = V4L2_PIX_FMT_YUV420; 
 ioctl(cam_fp, VIDIOC_S_FBUF, &fb); //VIDIOC_S_FBUF— Set frame buffer overlay parameters
printf("cofig to YUV420:fb.fmt.pixelformat = %d\n", fb.fmt.pixelformat);
  相关解决方案