@@ -226,8 +226,31 @@ AVFrame* RandomAccessVideoReader::process_frame(AVFrame* frame) {
226226
227227/* ******************* Reader ********************/
228228
229- Reader::Reader (const std::string& filename)
229+ void SetFFmpegLogLevel (const std::string& log_level) {
230+ static const std::unordered_map<std::string, int > log_level_map = {
231+ {" quiet" , AV_LOG_QUIET},
232+ {" panic" , AV_LOG_PANIC},
233+ {" fatal" , AV_LOG_FATAL},
234+ {" error" , AV_LOG_ERROR},
235+ {" warning" , AV_LOG_WARNING},
236+ {" info" , AV_LOG_INFO},
237+ {" verbose" , AV_LOG_VERBOSE},
238+ {" debug" , AV_LOG_DEBUG},
239+ {" trace" , AV_LOG_TRACE}
240+ };
241+
242+ auto it = log_level_map.find (log_level);
243+ if (it != log_level_map.end ()) {
244+ av_log_set_level (it->second );
245+ } else {
246+ spdlog::warn (" Invalid FFmpeg log level: '{}'. Using 'warning' as default." , log_level);
247+ av_log_set_level (AV_LOG_WARNING);
248+ }
249+ }
250+
251+ Reader::Reader (const std::string& filename, const std::string& log_level)
230252 : filename_(filename),
253+ log_level_ (log_level),
231254 read_mode_(ReadMode::DEPTH_FIRST),
232255 pFormatCtx_(NULL ),
233256 has_rgb_(false ),
@@ -253,7 +276,8 @@ Reader::Reader(const std::string& filename)
253276 keyframe_rgb_idx_(0 ),
254277 allframe_rgb_idx_(0 ),
255278 keyframe_depth_idx_(0 ) {
256- // av_log_set_level(AV_LOG_DEBUG);
279+
280+ SetFFmpegLogLevel (log_level_);
257281
258282 if (filename_.find (' ' ) != std::string::npos) {
259283 throw std::runtime_error (" Find blank in filename, please fix it." );
@@ -821,7 +845,7 @@ bool Reader::SeekToRgbKeyframe(int64_t target_pts) {
821845}
822846
823847bool Reader::IsLastFrame () {
824- std::cout << " GetIndex: " << GetIndex () << " , GetFrameCount: " << GetFrameCount () << std::endl;
848+ // std::cout << "GetIndex: " << GetIndex() << ", GetFrameCount: " << GetFrameCount() << std::endl;
825849 return GetIndex () == GetFrameCount () - 1 ;
826850}
827851
0 commit comments