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,可以注释掉。
相关推荐
从0至12 分钟前
C++编程入门:从基础到复合类型
开发语言·c++
guozhetao32 分钟前
【ST表、倍增】P7167 [eJOI 2020] Fountain (Day1)
java·c++·python·算法·leetcode·深度优先·图论
枫叶丹41 小时前
【Qt开发】信号与槽(二)-> 信号和槽的使用
开发语言·qt
Vertira2 小时前
python 阿里云 安装 dashscope的简介、安装
开发语言·python
hqxstudying4 小时前
Java异常处理
java·开发语言·安全·异常
小坏坏的大世界5 小时前
C++ STL常用容器总结(vector, deque, list, map, set)
c++·算法
wjs20246 小时前
状态模式(State Pattern)
开发语言
我命由我123456 小时前
Kotlin 数据容器 - List(List 概述、创建 List、List 核心特性、List 元素访问、List 遍历)
java·开发语言·jvm·windows·java-ee·kotlin·list
liulilittle6 小时前
C++ TAP(基于任务的异步编程模式)
服务器·开发语言·网络·c++·分布式·任务·tap
励志要当大牛的小白菜8 小时前
ART配对软件使用
开发语言·c++·qt·算法