安装ffmpeg4.X的版本

本文档提供了在Ubuntu系统上安装SDL2和ffmpeg的详细过程,包括依赖包的安装、SDL2的配置与编译、ffmpeg的配置、编译及环境变量设置。确保了ffplay和ffmpeg的正确运行,适用于需要进行多媒体处理的开发者。
摘要由CSDN通过智能技术生成

在这里插入图片描述

1、安装依赖包

sudo apt install -y yasm
sudo apt-get install libsdl1.2-dev

2、安装SDL2(在SDL2压缩包目录…/SDL2-2.0.20下执行命令)

./autogen(如果安装失败,执行sudo apt-get install autoconf automake libtool)
./configure
make
sudo make install

3、编译ffmpeg(在ffmpeg压缩包目录…/ffmpeg4.2.5下执行命令)

./configure --enable-shared --enable-ffplay
make -j$(nproc)
sudo make install
ffplay xxx.mp4(如成功打开视频,ffplay安装成功)
ffmpeg -version(如果成功显示,ffmpeg安装成功,如果没有显示安装的版本号,需要执行步骤4)

4、配置环境变量(该步骤需返回/home目录下)

sudo gedit /etc/ld.so.conf
打开文本后,加入如下路径:/usr/local/lib(默认路径)
sudo ldconfig
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Windows平台上,可以使用dshow(DirectShow)输入设备来读取摄像头。以下是基于FFmpeg4.x的dshow输入设备的代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <libavdevice/avdevice.h> #include <libavformat/avformat.h> int main(int argc, char *argv[]) { AVInputFormat *inputFormat; AVFormatContext *formatCtx = NULL; AVDictionary *options = NULL; AVCodecContext *codecCtx = NULL; AVFrame *frame = NULL; AVPacket pkt; int ret; avdevice_register_all(); inputFormat = av_find_input_format("dshow"); av_dict_set(&options, "video_size", "640x480", 0); av_dict_set(&options, "framerate", "30", 0); av_dict_set(&options, "pixel_format", "yuyv422", 0); av_dict_set(&options, "vcodec", "rawvideo", 0); ret = avformat_open_input(&formatCtx, "video=USB Camera", inputFormat, &options); if (ret < 0) { fprintf(stderr, "Could not open input file\n"); return 1; } ret = avformat_find_stream_info(formatCtx, NULL); if (ret < 0) { fprintf(stderr, "Could not find stream information\n"); return 1; } codecCtx = avcodec_alloc_context3(NULL); if (!codecCtx) { fprintf(stderr, "Could not allocate codec context\n"); return 1; } ret = avcodec_parameters_to_context(codecCtx, formatCtx->streams[0]->codecpar); if (ret < 0) { fprintf(stderr, "Could not copy codec parameters to codec context\n"); return 1; } codecCtx->pix_fmt = AV_PIX_FMT_BGR24; ret = avcodec_open2(codecCtx, avcodec_find_decoder(codecCtx->codec_id), NULL); if (ret < 0) { fprintf(stderr, "Could not open codec\n"); return 1; } frame = av_frame_alloc(); if (!frame) { fprintf(stderr, "Could not allocate frame\n"); return 1; } while (1) { ret = av_read_frame(formatCtx, &pkt); if (ret < 0) break; if (pkt.stream_index == 0) { ret = avcodec_send_packet(codecCtx, &pkt); if (ret < 0) { fprintf(stderr, "Could not send packet to decoder\n"); break; } while (ret >= 0) { ret = avcodec_receive_frame(codecCtx, frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) break; else if (ret < 0) { fprintf(stderr, "Error during decoding\n"); break; } printf("Frame %d (type=%c, size=%d bytes)\n", codecCtx->frame_number, av_get_picture_type_char(frame->pict_type), frame->pkt_size); av_frame_unref(frame); } } av_packet_unref(&pkt); } av_frame_free(&frame); avcodec_free_context(&codecCtx); avformat_close_input(&formatCtx); av_dict_free(&options); return 0; } ``` 这个样例使用了dshow作为输入格式,打开了名为"USB Camera"的设备,读取该设备的视频流,并将视频帧通过AVCodecContext解码。在解码的过程中,将每一帧的信息打印到控制台上。 请注意,使用此样例代码需要安装FFmpeg库,并且需要有Windows系统的摄像头设备。如果要在其他平台上运行,需要根据平台不同进行一定的修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值