linux下usb摄像头采集的YUYV格式转换成JPEG格式的图片

由于现在部分摄像头采集的格式是YUYV,不能自己转换成jpeg的图片格式,让我们观看相当麻烦。。所以参考了mjpeg-streamer的源码。

从中取得转换函数,通过自己的组合可以实现从YUYV的格式转换成jpeg,以便于我们通过网络实施远程监控。现给出自己组合的源代码如下:

 //代码计较繁杂,没去整理,不喜勿喷。。

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <assert.h>

#include <getopt.h>           

#include <fcntl.h>            

#include <unistd.h>

#include <errno.h>

#include <malloc.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <sys/time.h>

#include <sys/mman.h>

#include <sys/ioctl.h>

#include <asm/types.h>        

#include <linux/videodev2.h>

#include <jpeglib.h>

 

#define OUTPUT_BUF_SIZE  4096

#define CLEAR(x) memset (&(x), 0, sizeof (x))

#define WIDTH 320

#define HEIGHT 240

 

struct buffer {

         void   *start;

         size_t length;

};

 

typedef struct {

  struct jpeg_destination_mgr pub;

 

  JOCTET * buffer; 

 

  unsigned char *outbuffer;

  int outbuffer_size;

  unsigned char *outbuffer_cursor;

  int *written;

 

}mjpg_destination_mgr;

 

typedef mjpg_destination_mgr *mjpg_dest_ptr;

 

static char *           dev_name        = "/dev/video0";

static int              fd              = -1;

struct buffer *         buffers         = NULL;

static unsigned int     n_buffers       = 0;

FILE *file_fd;

static unsigned long file_length;

static unsigned char *file_name;

 

METHODDEF(void) init_destination(j_compress_ptr cinfo) {

  mjpg_dest_ptr dest = (mjpg_dest_ptr) cinfo->dest;

  dest->buffer = (JOCTET *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, OUTPUT_BUF_SIZE * sizeof(JOCTET));

  *(dest->written) = 0;

  dest->pub.next_output_byte = dest->buffer;

  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;

}

 

METHODDEF(boolean) empty_output_buffer(j_compress_ptr cinfo) {

  mjpg_dest_ptr dest = (mjpg_dest_ptr) cinfo->dest;

  memc

  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值