【问题标题】:libavformat: get formats Mime Type in C++libavformat:在 C++ 中获取格式 Mime 类型
【发布时间】:2018-01-17 06:28:57
【问题描述】:

我在 Arch Linux 上运行的 C++ 应用程序工作,它应该使用 libavformat 来获取媒体文件 mime 类型。目前使用以下几行:

std::string path = "/path/to/file.extension";

av_register_all();
AVFormatContext* pFormatCtx = avformat_alloc_context();
avformat_open_input(&pFormatCtx, path.c_str(), NULL, NULL);
avformat_find_stream_info(pFormatCtx, NULL);

std::string mimeType(pFormatCtx->iformat->mime_type);

现在,这将按预期使用 *.mkv (Matroska) 文件。返回预期的逗号分隔的 mimeType 字符串“video/x-matroska,...”。但对于任何其他文件格式,如 *.mp4 或 *.avi,iformat->mime_type 将始终返回 NULL。

如何获得其他容器格式的 Mime 类型?

【问题讨论】:

    标签: c++ ffmpeg mime-types libav libavformat


    【解决方案1】:

    似乎avformat_find_stream_info 只设置了iformat 而大多数 AVInputFormat 变量不初始化 mime_type 字段。

    你也可以使用

    AVOutputFormat* format = av_guess_format(NULL,path.c_str(),NULL);
    if(format)
      printf("%s\n",format->mime_type);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 2010-09-30
      • 2011-04-11
      • 2014-04-16
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多