Add flag to estimate last frame's duration to stats.
BUG=https://bugs.chromium.org/p/webm/issues/detail?id=1204 Change-Id: Ie73e2981951f9eb6140bdfb0a6839320e009b7fe
This commit is contained in:
parent
196708a95f
commit
bd3ab3abe6
@ -211,9 +211,18 @@ int64_t Vp9LevelStats::GetMaxLumaPictureSize() const {
|
||||
}
|
||||
|
||||
double Vp9LevelStats::GetAverageBitRate() const {
|
||||
const double duration_seconds =
|
||||
((duration_ns_ == -1) ? end_ns_ - start_ns_ : duration_ns_) /
|
||||
const int64_t frame_duration_ns = end_ns_ - start_ns_;
|
||||
double duration_seconds =
|
||||
((duration_ns_ == -1) ? frame_duration_ns : duration_ns_) /
|
||||
libwebm::kNanosecondsPerSecond;
|
||||
if (estimate_last_frame_duration_ &&
|
||||
(duration_ns_ == -1 || duration_ns_ <= frame_duration_ns)) {
|
||||
const double sec_per_frame = frame_duration_ns /
|
||||
libwebm::kNanosecondsPerSecond /
|
||||
(displayed_frames - 1);
|
||||
duration_seconds += sec_per_frame;
|
||||
}
|
||||
|
||||
return total_compressed_size_ / duration_seconds / 125.0;
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,8 @@ class Vp9LevelStats {
|
||||
total_uncompressed_bits_(0),
|
||||
frames_refreshed_(0),
|
||||
max_frames_refreshed_(0),
|
||||
max_column_tiles_(0) {}
|
||||
max_column_tiles_(0),
|
||||
estimate_last_frame_duration_(true) {}
|
||||
|
||||
~Vp9LevelStats() = default;
|
||||
Vp9LevelStats(Vp9LevelStats&& other) = delete;
|
||||
@ -135,6 +136,16 @@ class Vp9LevelStats {
|
||||
// as the duration.
|
||||
void set_duration(int64_t time_ns) { duration_ns_ = time_ns; }
|
||||
|
||||
bool estimate_last_frame_duration() const {
|
||||
return estimate_last_frame_duration_;
|
||||
}
|
||||
|
||||
// If true try to estimate the last frame's duration if the stream's duration
|
||||
// is not set or the stream's duration equals the last frame's timestamp.
|
||||
void set_estimate_last_frame_duration(bool flag) {
|
||||
estimate_last_frame_duration_ = flag;
|
||||
}
|
||||
|
||||
private:
|
||||
int frames;
|
||||
int displayed_frames;
|
||||
@ -175,6 +186,8 @@ class Vp9LevelStats {
|
||||
int max_frames_refreshed_;
|
||||
|
||||
int max_column_tiles_;
|
||||
|
||||
bool estimate_last_frame_duration_;
|
||||
};
|
||||
|
||||
} // namespace vp9_parser
|
||||
|
@ -129,12 +129,16 @@ TEST_F(Vp9LevelStatsTests, VideoOnlyFile) {
|
||||
EXPECT_EQ(11, stats_.GetLevel());
|
||||
EXPECT_EQ(479232, stats_.GetMaxLumaSampleRate());
|
||||
EXPECT_EQ(36864, stats_.GetMaxLumaPictureSize());
|
||||
EXPECT_DOUBLE_EQ(275.512, stats_.GetAverageBitRate());
|
||||
EXPECT_DOUBLE_EQ(264.03233333333333, stats_.GetAverageBitRate());
|
||||
EXPECT_DOUBLE_EQ(147.136, stats_.GetMaxCpbSize());
|
||||
EXPECT_DOUBLE_EQ(20.873079938441883, stats_.GetCompressionRatio());
|
||||
EXPECT_EQ(1, stats_.GetMaxColumnTiles());
|
||||
EXPECT_EQ(11, stats_.GetMinimumAltrefDistance());
|
||||
EXPECT_EQ(3, stats_.GetMaxReferenceFrames());
|
||||
|
||||
EXPECT_TRUE(stats_.estimate_last_frame_duration());
|
||||
stats_.set_estimate_last_frame_duration(false);
|
||||
EXPECT_DOUBLE_EQ(275.512, stats_.GetAverageBitRate());
|
||||
}
|
||||
|
||||
TEST_F(Vp9LevelStatsTests, Muxed) {
|
||||
@ -148,12 +152,15 @@ TEST_F(Vp9LevelStatsTests, Muxed) {
|
||||
EXPECT_EQ(30, stats_.GetLevel());
|
||||
EXPECT_EQ(9838080, stats_.GetMaxLumaSampleRate());
|
||||
EXPECT_EQ(409920, stats_.GetMaxLumaPictureSize());
|
||||
EXPECT_DOUBLE_EQ(468.38413361169108, stats_.GetAverageBitRate());
|
||||
EXPECT_DOUBLE_EQ(447.09394572025053, stats_.GetAverageBitRate());
|
||||
EXPECT_DOUBLE_EQ(118.464, stats_.GetMaxCpbSize());
|
||||
EXPECT_DOUBLE_EQ(263.10185597889068, stats_.GetCompressionRatio());
|
||||
EXPECT_EQ(2, stats_.GetMaxColumnTiles());
|
||||
EXPECT_EQ(9, stats_.GetMinimumAltrefDistance());
|
||||
EXPECT_EQ(3, stats_.GetMaxReferenceFrames());
|
||||
|
||||
stats_.set_estimate_last_frame_duration(false);
|
||||
EXPECT_DOUBLE_EQ(468.38413361169108, stats_.GetAverageBitRate());
|
||||
}
|
||||
|
||||
TEST_F(Vp9LevelStatsTests, SetDuration) {
|
||||
|
@ -35,7 +35,7 @@ using libwebm::Indent;
|
||||
using libwebm::kNanosecondsPerSecond;
|
||||
using libwebm::kNanosecondsPerSecondi;
|
||||
|
||||
const char VERSION_STRING[] = "1.0.4.2";
|
||||
const char VERSION_STRING[] = "1.0.4.3";
|
||||
|
||||
struct Options {
|
||||
Options();
|
||||
|
Loading…
x
Reference in New Issue
Block a user