I work on an C++ Application running on Arch Linux that should use libavformat to obtain a media files mime type. 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. Returning the expected Comma seperated mimeType String "video/x-matroska,...". But with any other File Format like *.mp4 or *.avi the iformat->mime_type will always return NULL.
How do i get the Mime Types of the other Container Formats?
It seems that avformat_find_stream_info
sets only the iformat
and that most
AVInputFormat
variables don't initialize the mime_type
field.
You can also use
AVOutputFormat* format = av_guess_format(NULL,path.c_str(),NULL);
if(format)
printf("%s\n",format->mime_type);