没有合适的资源?快使用搜索试试~ 我知道了~
首页基于linux_V4L视频采集摄像程序
资源详情
资源评论
资源推荐

/
*******************************************************************************
**********************
linux_m4v.c
gcc -o linux_m4v linux_m4v.c -lc -lm -lxvidcore
*******************************************************************************
************************/
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/videodev.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include "xvid_encode.h"
void *enc_handle = NULL;
int done = 0;
int
enc_main(unsigned char *image,
unsigned char *bitstream,
int *key,
int *stats_type,
int *stats_quant,
int *stats_length,
int sse[3]);
int
enc_stop();
int
enc_init(int use_assembler);
double
msecond();

#define VIDEO_PALETTE_JPEG 21
struct vdIn {
int fd;
char *videodevice ;
struct video_capability videocap;
struct video_picture videopict;
struct video_window videowin;
int framesizeIn ;
int bppIn;
int hdrwidth;
int hdrheight;
int formatIn;
};
struct vdIn videoIn;
int init_videoIn (struct vdIn *vd, char *device, int width, int height,int format);
static int GetDepth (int format);
static int GetVideoPict (struct vdIn *vd);
static int SetVideoPict (struct vdIn *vd);
int main(int argc,char *argv[])
{
char *device;
int format = VIDEO_PALETTE_YUV420P;
int width = 352;
int height = 288;
int i;
unsigned char r_buffer[304128];
unsigned char* mp4_buffer;
double enctime;
double totalenctime = 0.;
float totalPSNR[3] = {0., 0., 0.};
device = "/dev/video0";
ARG_OUTPUTFILE = "test.m4v";
int use_assembler = 1;
int result;
int totalsize;
int m4v_size;
int key;

int stats_type;
int stats_quant;
int stats_length;
int input_num;
int output_num;
char filename[256];
FILE *out_file = NULL;
memset (&videoIn, 0, sizeof (struct vdIn));
if (init_videoIn(&videoIn, device, width, height,format) != 0)
printf (" damned encore rate !!\n");
/* xvid init */
ARG_SAVEMPEGSTREAM = 1;
ARG_SAVEINDIVIDUAL = 0;
XDIM = width;
YDIM = height;
mp4_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM, YDIM) * 2);
totalsize = 0;
result = 0;
result = enc_init(0);
if (result != 0) {
fprintf(stderr, "Encore INIT problem, return value %d\n",result);
goto release_all;
}
/* i=read(videoIn.fd,r_buffer,304128);
printf("i read : %d\n",i);
if(i<0){
printf("error read!\n");
close(videoIn.fd);
return -1;
}
*/
input_num = 0; /* input frame counter */
output_num = 0;
if (ARG_SAVEMPEGSTREAM && ARG_OUTPUTFILE) {

if ((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) {
fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE);
goto release_all;
}
} else {
out_file = NULL;
}
/* Xvid encode */
do {
char *type;
int sse[3];
i=read(videoIn.fd,r_buffer,304128);
printf("i read : %d\n",i);
if(i<0){
printf("error read!\n");
close(videoIn.fd);
return -1;
}
if (input_num >= ARG_MAXFRAMENR) {
//result = 1;
done = 1;
}
enctime = msecond();
m4v_size =enc_main(!result ? (unsigned char*)r_buffer:0,mp4_buffer, &key,
&stats_type,&stats_quant, &stats_length, sse);
enctime = msecond() - enctime;
printf("m4v_size is %d \n",m4v_size);
if (m4v_size < 0) {
printf("erro in encode....\n");
}
/* Update encoding time stats */
totalenctime += enctime;
totalsize += m4v_size;
if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {
/* Save single files */
if (ARG_SAVEINDIVIDUAL) {
剩余18页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论5