摄像头输出是mjpeg格式的,需要实现在线预览功能,然后实现拍照功能
1.可以设置采集图像的分辨率,预览分辨率为640*480,可以自定义
2.ctrl+\ 拍照,ctrl+c 退出
void test() { if (signal(SIGQUIT, sigHandle) == SIG_ERR) { perror("set signal err"); } if (signal(SIGINT, sigHandle) == SIG_ERR) { perror("set signal err"); } AVOutputFormat *ofmt = NULL; AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL; AVCodecContext *ifcodec_ctx, *ofcodec_ctx; AVCodec *icodec, *ocodec; AVStream *out_stream; AVFrame *pFrame, *pFrameYUV420, *pFrameBGR; struct SwsContext *in_conCtx, *out_conCtx; unsigned char *in_buffer, *out_buffer; AVPacket inpkg, outpkg; const char *in_filename; int ret, i; int got_picture; IplImage *image; int videoindex = -1; int frame_index = 0; int64_t start_time = 0, end_time = 0; // in_filename = "test.mp4"; in_filename = "/dev/video1"; // in_filename = "rtmp://219.216.87.170/live/test3"; // out_filename = "rtmp://219.216.87.170/live/test2"; av_register_all(); avdevice_register_all(); avformat_network_init(); ifmt_ctx = avformat_alloc_context(); ifmt_ctx->probesize = 20000000; ifmt_ctx->max_analyze_duration = 2000; AVDictionary* options = NULL; av_dict_set(&options, "fflags", "nobuffer", 0); av_dict_set(&options, "max_delay", "100000", 0); av_dict_set(&options, "framerate", "30", 0); av_dict_set(&options, "input_format", "mjpeg", 0); av_dict_set(&options, "video_size", "1920x1080", 0); // av_dict_set(&options, "video_size", "1280x720", 0); if ((ret = avformat_open_input(&