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,可以注释掉。
相关推荐
C++ 老炮儿的技术栈2 小时前
我们在设计tcp协议时,要传一个字符串过去,报文:头十长度十内容,是否要把‘\0‘也填入,长度是否包含‘\0‘
开发语言·数据结构·c++·mfc·c
传奇开心果编程2 小时前
【Rust入门练中学】第2课:变量、可变性与常量
开发语言·学习·rust
zr想努力3 小时前
从0开始配置Perforce4环境
开发语言
幸运小圣4 小时前
PointerEvent 常用属性与事件整理【JavaScript】
开发语言·javascript·ecmascript
长谷深风1114 小时前
评测AI Agent:三种裁判各司其职
java·大数据·开发语言·人工智能·ai agent
边境悍匪5 小时前
蜗牛学苑 Java 智能体学习 Day42|项目周开发技术汇总 1 思维导图复盘
java·开发语言·spring boot·学习·spring
君顾15 小时前
本地托管机构管理源码实战:需求拆解、数据建模与多端部署
java·开发语言·托管
传奇开心果编程6 小时前
【Rust入门练中学】 第3课:数据类型
开发语言·学习·rust
刘广睿7 小时前
视频导出为什么发灰?色彩空间与色彩范围(BT.601/709/2020)的 ffmpeg 转换实战
ffmpeg·音视频·视频处理·色彩空间·素材管理
泡泡鱼(敲代码中)7 小时前
MySQL 学习笔记:DCL、函数与约束 —— 安全、效率、完整性的三板斧
开发语言·笔记·sql·学习·mysql·gitee