diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 217ff4d9..4c9063ce 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -365,6 +365,7 @@ Value makeMediaSourceJson(MediaSource &media){ } obj["loss"] = loss; } + obj["frames"] = track->getFrames(); switch(codec_type){ case TrackAudio : { auto audio_track = dynamic_pointer_cast(track); @@ -378,6 +379,7 @@ Value makeMediaSourceJson(MediaSource &media){ obj["width"] = video_track->getVideoWidth(); obj["height"] = video_track->getVideoHeight(); obj["fps"] = round(video_track->getVideoFps()); + obj["key_frames"] = video_track->getVideoKeyFrames(); break; } default: diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index 0f95a780..6060c355 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -311,6 +311,10 @@ public: */ bool inputFrame(const Frame::Ptr &frame) override { std::lock_guard lck(_mtx); + ++_frames; + if (frame->keyFrame() && frame->getTrackType() == TrackVideo) { + ++_video_key_frames; + } bool ret = false; for (auto &pr : _delegates) { if (pr.second->inputFrame(frame)) { @@ -333,7 +337,25 @@ public: _delegates.clear(); } + /** + * 获取累计关键帧数 + */ + uint64_t getVideoKeyFrames() const { + std::lock_guard lck(_mtx); + return _video_key_frames; + } + + /** + * 获取帧数 + */ + uint64_t getFrames() const { + std::lock_guard lck(_mtx); + return _frames; + } + private: + uint64_t _frames = 0; + uint64_t _video_key_frames = 0; mutable std::mutex _mtx; std::map _delegates; };