2017-08-09 34 views
0

我使用在Arch Linux上運行的應用libavformat獲取媒體文件MIME類型的C++應用程序。目前使用以下行:libavformat:獲取格式Mime在C++中輸入

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類型?

回答

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