简体   繁体   English

libavformat:获取C ++中的Mime Type格式

[英]libavformat: get formats Mime Type in C++

I work on an C++ Application running on Arch Linux that should use libavformat to obtain a media files mime type. 我在Arch Linux上运行的C ++应用程序上工作,该应用程序应使用libavformat获取媒体文件的mime类型。 Currently using the following lines: 当前使用以下行:

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);

Now, that will work as expected with *.mkv (Matroska) files. 现在,该文件将与* .mkv(Matroska)文件一起正常工作。 Returning the expected Comma seperated mimeType String "video/x-matroska,...". 返回预期的逗号分隔的mimeType字符串“ video / x-matroska,...”。 But with any other File Format like *.mp4 or *.avi the iformat->mime_type will always return NULL. 但是,对于任何其他文件格式(例如* .mp4或* .avi),iformat-> mime_type将始终返回NULL。

How do i get the Mime Types of the other Container Formats? 如何获得其他容器格式的Mime类型?

It seems that avformat_find_stream_info sets only the iformat and that most AVInputFormat variables don't initialize the mime_type field. 似乎avformat_find_stream_info仅设置iformat ,大多数AVInputFormat变量未初始化mime_type字段。

You can also use 您也可以使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM