FFmpeg API

1. 快速打开媒体文件查看信息

cpp 复制代码
#include "mainwindow.h"
#include <QApplication>
#include <iostream>
#include <QDebug>

#undef main             // 不加这句会直接报错
#include "SDL.h"

extern "C"
{
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libswscale/swscale.h>
    #include <libavdevice/avdevice.h>
    #include <libavformat/version.h>
    #include <libavutil/time.h>
    #include <libavutil/mathematics.h>
    #include <libavutil/imgutils.h>
}


int main(int argc, char *argv[])
{
    const char *input_file = "test.mp4";

    AVFormatContext *pFormatCtx = nullptr;

    int ret = avformat_open_input(&pFormatCtx, input_file, NULL, NULL);
    if(ret != 0)
    {
        // av_log(nullptr, AV_LOG_ERROR, "Open Input File: %s failed: %s \n", input_file, av_err2str(ret));
        return -1;
    }

    av_dump_format(pFormatCtx, 0, input_file, 0);
    avformat_close_input(&pFormatCtx);

    qDebug() << "Finished! ";
    return 0;
}
  • 重要结构体说明

(1)AVFormatContext :容器或者媒体文件的抽象层次。

(2)AVStream:音频、视频或者字幕流。

(3)AVCodecContext与AVCodec:编码格式和编码器的抽象。

(4)AVPackge:数据包的抽象(未解码的数据)。

(5)AVStream:数据帧的抽象。

  • 上边用到了SDL,可以注释掉。
相关推荐
优秀的颜32 分钟前
计算机基础知识(第五篇)
java·开发语言·分布式
CodeWithMe34 分钟前
【C/C++】std::vector成员函数清单
开发语言·c++
uyeonashi34 分钟前
【QT控件】输入类控件详解
开发语言·c++·qt
iCxhust2 小时前
Prj10--8088单板机C语言8259测试(1)
c语言·开发语言
крон5 小时前
【Auto.js例程】华为备忘录导出到其他手机
开发语言·javascript·智能手机
zh_xuan5 小时前
c++ 单例模式
开发语言·c++·单例模式
老胖闲聊6 小时前
Python Copilot【代码辅助工具】 简介
开发语言·python·copilot
Blossom.1186 小时前
使用Python和Scikit-Learn实现机器学习模型调优
开发语言·人工智能·python·深度学习·目标检测·机器学习·scikit-learn
曹勖之6 小时前
基于ROS2,撰写python脚本,根据给定的舵-桨动力学模型实现动力学更新
开发语言·python·机器人·ros2
豆沙沙包?7 小时前
2025年- H77-Lc185--45.跳跃游戏II(贪心)--Java版
java·开发语言·游戏