我在一个运行在Arch上的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字符串“视频/x-matroska,.”。但是对于任何其他文件格式,如*.mp4或*.avi,iformat->mime_type将始终返回NULL。
如何获得其他容器格式的Mime类型?
发布于 2017-08-09 15:52:30
似乎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);https://stackoverflow.com/questions/45589437
复制相似问题