-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that verifies video encoder timing, which uses VideoEncoder to encode several frames to a video file and verifies the duration using the Video class with a new Duration() function. Signed-off-by: Jenn Nguyen <jenn@openrobotics.org> Co-authored-by: Ian Chen <ichen@osrfoundation.org>
- Loading branch information
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (C) 2020 Open Source Robotics Foundation | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
#include <gtest/gtest.h> | ||
#include <array> | ||
#include "ignition/common/VideoEncoder.hh" | ||
#include "ignition/common/Video.hh" | ||
#include "test_config.h" | ||
#include "test/util.hh" | ||
|
||
using namespace ignition; | ||
using namespace common; | ||
|
||
const unsigned int kSize = 10; | ||
const std::array<unsigned char, kSize*kSize> kFrame = {}; | ||
|
||
// set to 720ms because video duration missing additional 18 frames | ||
// which may be due to how video encoding works | ||
const std::chrono::milliseconds kTol(720); | ||
|
||
void durationTest(VideoEncoder &_vidEncoder, Video &_video, | ||
const int &_fps, const int &_seconds) | ||
{ | ||
_vidEncoder.Start("mp4", "", kSize, kSize, _fps, 0); | ||
|
||
int frameCount = 0; | ||
while (frameCount != _fps*_seconds) | ||
{ | ||
if (_vidEncoder.AddFrame(kFrame.data(), kSize, kSize)) | ||
++frameCount; | ||
} | ||
|
||
_vidEncoder.Stop(); | ||
_video.Load(common::joinPaths(common::cwd(), "/TMP_RECORDING.mp4")); | ||
|
||
EXPECT_NEAR(std::chrono::duration_cast<std::chrono::milliseconds>( | ||
_video.Duration()).count(), | ||
_seconds*1000, | ||
kTol.count()); | ||
} | ||
|
||
TEST(EncoderTimingTest, Duration) | ||
{ | ||
VideoEncoder vidEncoder; | ||
Video video; | ||
|
||
durationTest(vidEncoder, video, 50, 1); | ||
durationTest(vidEncoder, video, 30, 2); | ||
durationTest(vidEncoder, video, 25, 5); | ||
} |