Clion 使用ffmpeg 学习1 开发环境配置

Clion 使用ffmpeg 学习1 开发环境配置

  • 一、准备工作
    • [1. 准备环境](#1. 准备环境)
    • [2. 下载FFmpeg](#2. 下载FFmpeg)
  • 二、操作步骤
    • [1. Clion 新建一个C项目](#1. Clion 新建一个C项目)
    • [2. 修改 CMakeLists.txt](#2. 修改 CMakeLists.txt)
    • [3. 修改配置](#3. 修改配置)
    • [4. 运行测试](#4. 运行测试)
    • [5. 打印rtsp 流信息的 demo](#5. 打印rtsp 流信息的 demo)

一、准备工作

在视频处理和多媒体应用程序开发中,FFmpeg 是一个强大的开源工具,它提供了处理音频和视频的丰富功能。CLion 是一款受欢迎的跨平台集成开发环境(IDE),它提供了强大的代码编辑和调试工具。

本文章介绍在CLion下配置FFmpeg开发环境的方法。

1. 准备环境

  • windows10
  • 已安装Clion

2. 下载FFmpeg

官网入口

找 Windows builds by BtbN,跳转到:

https://github.com/BtbN/FFmpeg-Builds/releases

选择合适的版本下载 。 我这里下载的是 ffmpeg-n4.4.4-6-gd5fa6e3a91-win64-gpl-shared-4.4 。

二、操作步骤

1. Clion 新建一个C项目

2. 修改 CMakeLists.txt

c 复制代码
cmake_minimum_required(VERSION 3.24)
project(ffmpeg_learn1 C)

set(CMAKE_C_STANDARD 11)

include_directories(E:/Downloads/ffmpeg-master-latest-win64-gpl-shared/include)
link_directories(E:/Downloads/ffmpeg-master-latest-win64-gpl-shared/lib)

add_executable(ffmpeg_learn1 main.c)

target_link_libraries(
        ffmpeg_learn1
        avcodec
        avdevice
        avfilter
        avformat
        avutil
        postproc
        swresample
        swscale
)

3. 修改配置

点击 Edit Configurations:

设置环境变量:

bash 复制代码
path=E:/Downloads/ffmpeg-master-latest-win64-gpl-shared/bin

4. 运行测试

main.c输入内容 :

c 复制代码
#include "libavformat/avformat.h"

int main() {
    av_log_set_level(AV_LOG_INFO);
    av_log(NULL, AV_LOG_INFO, "avformat_configurations: \n %s", avformat_configuration());
    return 0;
}

点击运行:

5. 打印rtsp 流信息的 demo

c 复制代码
#include <stdio.h>
#include <libavformat/avformat.h>

int main(int argc, char *argv[]) {
    // 初始化 FFmpeg
    av_register_all();

    // 打开 RTSP 流
    AVFormatContext *formatContext = NULL;
    if (avformat_open_input(&formatContext, "rtsp://地址信息", NULL, NULL) != 0) {
        fprintf(stderr, "无法打开 RTSP 流\n");
        return 1;
    }

    // 获取流信息
    if (avformat_find_stream_info(formatContext, NULL) < 0) {
        fprintf(stderr, "无法获取流信息\n");
        return 1;
    }

    // 打印流信息
    av_dump_format(formatContext, 0, "rtsp://地址信息", 0);

    // 关闭 RTSP 流
    avformat_close_input(&formatContext);

    return 0;
}

通过官方文档 : https://www.ffmpeg.org/documentation.html 可以查看更多FFmpeg的操作方法。

相关推荐
龙湾开发11 分钟前
计算机图形学编程(使用OpenGL和C++)(第2版)学习笔记 10.增强表面细节(二)法线贴图
c++·笔记·学习·图形渲染·贴图
liang_202635 分钟前
【HT周赛】T3.二维平面 题解(分块:矩形chkmax,求矩形和)
数据结构·笔记·学习·算法·平面·总结
虾球xz38 分钟前
游戏引擎学习第290天:完成分离渲染
c++·人工智能·学习·游戏引擎
虾球xz40 分钟前
游戏引擎学习第285天:“Traversables 的事务性占用”
c++·学习·游戏引擎
虾球xz1 小时前
游戏引擎学习第280天:精简化的流式实体sim
数据库·c++·学习·游戏引擎
深度学习入门1 小时前
学习深度学习是否要先学习机器学习?
人工智能·深度学习·神经网络·学习·机器学习·ai·深度学习入门
FAREWELL000752 小时前
Unity基础学习(十五)核心系统——音效系统
学习·unity·c#·游戏引擎
岁岁岁平安2 小时前
Vue3学习(组合式API——Watch侦听器、watchEffect()详解)
前端·javascript·vue.js·学习·watch侦听器·组合式api
虾球xz2 小时前
游戏引擎学习第281天:在房间之间为摄像机添加动画效果
c++·人工智能·学习·游戏引擎
Y3174293 小时前
Python Day25 学习
python·学习