2017-08-09 2 views
0

私は、メディアファイルのMIMEタイプを取得するためにlibavformatを使用する必要がある、Arch Linux上で動作するC++アプリケーションで動作します。現在、次の行を使用しています:libavformat:形式を取得するC++の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タイプを取得するにはどうすればよいですか?

答えて

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); 
関連する問題