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,可以注释掉。
相关推荐
Yue丶越几秒前
【Python】基础语法入门(二)
android·开发语言·python
Demon--hx2 分钟前
[c++]string的三种遍历方式
开发语言·c++·算法
共享家952715 分钟前
QT-系统(多线程)
开发语言·数据库·qt
郝学胜-神的一滴43 分钟前
Effective Python 第52条:用subprocess模块优雅管理子进程
linux·服务器·开发语言·python
valan liya1 小时前
C++list
开发语言·数据结构·c++·list
小毅&Nora1 小时前
【后端】【C++】智能指针详解:从裸指针到 RAII 的优雅演进(附 5 个可运行示例)
c++·指针
Le1Yu1 小时前
订单取消功能(退款功能、策略模式、定时任务)
开发语言
章鱼哥7301 小时前
Java 策略模式 + 聚合对象:实现多模块的统计与聚合,快速扩展的实战
java·开发语言·策略模式
是店小二呀1 小时前
openGauss进阶:使用DBeaver可视化管理与实战
开发语言·人工智能·yolo
万粉变现经纪人1 小时前
如何解决 pip install 编译报错 ‘cl.exe’ not found(缺少 VS C++ 工具集)问题
开发语言·c++·人工智能·python·pycharm·bug·pip