Skip to content

Commit 5ffd8d4

Browse files
committed
set loglevel in reader
1 parent c46cbff commit 5ffd8d4

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

bindings/spatialmp4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ PYBIND11_MODULE(spatialmp4, m) {
153153

154154
// Bind Reader class
155155
py::class_<SpatialML::Reader>(m, "Reader")
156-
.def(py::init<const std::string &>())
156+
.def(py::init<const std::string &, const std::string &>(), py::arg("filename"), py::arg("log_level") = "quiet")
157157
.def("has_rgb", &SpatialML::Reader::HasRGB)
158158
.def("has_depth", &SpatialML::Reader::HasDepth)
159159
.def("has_pose", &SpatialML::Reader::HasPose)

src/spatialmp4/reader.cc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

823847
bool 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

src/spatialmp4/reader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class SPATIALMP4_EXPORT Reader {
102102
}
103103
}
104104

105-
Reader(const std::string& filename);
105+
Reader(const std::string& filename, const std::string& log_level);
106106
~Reader();
107107

108108
bool HasRGB() const { return has_rgb_; }
@@ -157,6 +157,7 @@ class SPATIALMP4_EXPORT Reader {
157157

158158
private:
159159
std::string filename_;
160+
std::string log_level_;
160161
ReadMode read_mode_;
161162
AVFormatContext* pFormatCtx_;
162163
AVPacket current_packet_;

0 commit comments

Comments
 (0)