好运快3

文檔庫

最新最全的文檔下載
當前位置:文檔庫 > linux下ffmpeg3.0采集攝像頭畫面用libjpeg-turbo轉成jpeg

linux下ffmpeg3.0采集攝像頭畫面用libjpeg-turbo轉成jpeg

#include
#include
#include
#include
extern "C"{
#include "libavcodec/avcodec.h"
#include "libavutil/mem.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
}
#include "sys/time.h"
#include "turbojpeg.h"

using namespace std;

int tyuv2jpeg(unsigned char* yuv_buffer, int yuv_size, int width, int height, int subsample, unsigned char** jpeg_buffer, unsigned long* jpeg_size, int quality)
{
tjhandle handle = NULL;
int flags = 0;
int padding = 4; // 1或4均可,但不能是0
int need_size = 0;
int ret = 0;

handle = tjInitCompress();

flags |= 0;

need_size = tjBufSizeYUV2(width, padding, height, subsample);
if (need_size != yuv_size)
{
printf("we detect yuv size: %d, but you give: %d, check again.\n", need_size, yuv_size);
return 0;
}

ret = tjCompressFromYUV(handle,yuv_buffer, width, padding, height, subsample, jpeg_buffer, jpeg_size, quality, flags);
if (ret < 0)
{
printf("compress to jpeg failed: %s\n", tjGetErrorStr());
}

tjDestroy(handle);

return ret;
}

int main(int argc, char **argv) {
int ret;
int videoindex = -1;
AVFormatContext *fmtCtx = NULL;
AVCodecContext *c =NULL;
AVPacket pcaket;
AVDictionary *options = NULL;

/*1、注冊*/
avcodec_register_all();
av_register_all();
avdevice_register_all();
/*2、連接視頻源*/
av_init_packet(&pcaket);

AVInputFormat *inputFmt = av_find_input_format("video4linux2");
if (NULL != inputFmt) {
std::cout << "input device name:" << inputFmt->name << std::endl;
} else {
std::cout << "Null point!" << std::endl;
return -1;
}
/*設置分辨率*/
av_dict_set(&options, "video_size", "640x480", 0);
//av_dict_set(&options, "pixel_format","yuv422p", 0);

ret = avformat_open_input(&fmtCtx, "/dev/video0", inputFmt,&options);
if (0 == ret) {
std::cout << "Open input device seccess!" << std::endl;
}
//發現碼流
if(avformat_find_stream_info(fmtCtx, NULL) < 0)
{
fprintf(stderr,"avformat_find_stream_info fail\n");
avformat_close_input(&fmtCtx);
avformat_free_context(fmtCtx);
exit(1);
}
//發現視頻流
videoindex=-1;
int i = 0;
for(i=0; inb_streams; i++)
{
if(fmtCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
videoindex=i;
break;
}
}
if(videoindex==-1)
{
printf("Didn't find a video stream.\n");
return -1;
}
//取視頻流句柄
c = fmtCtx->streams[videoindex]->codec;
printf("%d---%d-----%d\n",c->width,c->height,c->pix_fmt);
av_dump_format(fmtCtx,0,"/dev/video0",0);
struct SwsContext *img_convert_ctx = sws_getContext(c->

好运快3 时时彩下载 pk10前五百分百准 分分彩混买方法稳赚 三公大吃小玩法 重庆时时彩助赢软件 时时彩刷九码算违规吗 网上通比牛牛有假吗 重庆市重庆时时开奖结果记录 北京pk10一期计划 龙虎和口诀 重庆时时彩正不正规 双色球球开奖结果 如何处理大数据 重庆时时在线预测 2019世界男篮排名 棋牌游戏二人斗地主