ffmpeg实现mjpeg摄像头的采集-预览-拍照

本文介绍如何利用ffmpeg实现MJPEG格式摄像头的在线预览,并讲解如何通过键盘快捷键进行拍照操作。程序允许自定义采集图像分辨率,如预设的640*480,并支持通过ctrl+拍照,ctrl+c退出程序。内容适合于视频编解码与流媒体处理的学习者。
摘要由CSDN通过智能技术生成

摄像头输出是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(&ifmt_ctx, in_filename, 0, &options)) < 0) {
        printf("open input file err\n");
        goto end;
    }
    av_dict_free(&options);
    if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
        printf("failed to retrieve input stream information\n");
        goto end;
    }
    for (i = 0; i < ifmt_ctx->nb_streams; i++) {
        if (ifmt_ctx->streams[i]->codec->codec_type ==
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值