Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c++ ffmpeg

作者:刺眼的男ren   发布日期:2025-10-27   浏览:63

#include <iostream>
extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
}

int main() {
    // 初始化FFmpeg库
    av_register_all();
    avcodec_register_all();

    // 打开视频文件
    AVFormatContext *pFormatCtx = avformat_alloc_context();
    if (avformat_open_input(&pFormatCtx, "test.mp4", NULL, NULL) != 0) {
        std::cerr << "无法打开视频文件" << std::endl;
        return -1;
    }

    // 获取流信息
    if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
        std::cerr << "无法获取流信息" << std::endl;
        return -1;
    }

    // 打印元数据
    av_dump_format(pFormatCtx, 0, "test.mp4", 0);

    // 关闭资源
    avformat_close_input(&pFormatCtx);

    std::cout << "程序结束" << std::endl;
    return 0;
}

解释说明:

  1. 初始化FFmpeg库

    • av_register_all()avcodec_register_all() 用于注册所有可用的编解码器和格式。
  2. 打开视频文件

    • 使用 avformat_open_input 函数打开指定的视频文件(例如 "test.mp4")。如果打开失败,程序会输出错误信息并退出。
  3. 获取流信息

    • avformat_find_stream_info 函数用于检索输入文件的流信息。如果失败,程序会输出错误信息并退出。
  4. 打印元数据

    • av_dump_format 函数用于打印文件的元数据信息到标准输出。
  5. 关闭资源

    • 使用 avformat_close_input 函数关闭并释放与输入文件相关的资源。

这个示例代码展示了如何使用FFmpeg库来打开一个视频文件、获取其流信息并打印元数据。

上一篇:c++ std::cout

下一篇:c++swap函数

大家都在看

c++闭包

c++单引号和双引号的区别

c++ 注释

c++如何判断素数

c++格式化字符串

c++ orm框架

队列c++

c++freopen怎么用

进制转换c++代码

c++ 获取系统时间

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站