MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ can_read()

bool MayaFlux::IO::SoundFileReader::can_read ( const std::string &  filepath) const
overridevirtual

Check if this reader can open the given file.

Parameters
filepathPath to the file.
Returns
True if the file can be read, false otherwise.

Implements MayaFlux::IO::FileReader.

Definition at line 111 of file SoundFileReader.cpp.

112{
113 AVFormatContext* format_ctx = nullptr;
114 int ret = avformat_open_input(&format_ctx, filepath.c_str(), nullptr, nullptr);
115
116 if (ret < 0) {
117 return false;
118 }
119
120 bool has_audio = false;
121 if (avformat_find_stream_info(format_ctx, nullptr) >= 0) {
122 int audio_stream = av_find_best_stream(format_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, nullptr, 0);
123 has_audio = (audio_stream >= 0);
124 }
125
126 avformat_close_input(&format_ctx);
127 return has_audio;
128}