Skip to content

Commit

Permalink
Merge branch 'main' into MotionVectorExtractorFix
Browse files Browse the repository at this point in the history
  • Loading branch information
mraduldubey authored Aug 23, 2023
2 parents c2c8dc3 + 6dd86d5 commit 62afbab
Show file tree
Hide file tree
Showing 9 changed files with 409 additions and 162 deletions.
396 changes: 247 additions & 149 deletions README.md

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions base/include/Mp4ReaderSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Mp4ReaderSourceProps : public ModuleProps
auto canonicalVideoPath = boost::filesystem::canonical(_videoPath);
videoPath = canonicalVideoPath.string();
parseFS = _parseFS;
skipDir = boost::filesystem::path(canonicalVideoPath).parent_path().parent_path().parent_path().string();
bFramesEnabled = _bFramesEnabled;
direction = _direction;
giveLiveTS = _giveLiveTS;
Expand All @@ -51,11 +50,16 @@ class Mp4ReaderSourceProps : public ModuleProps
parseFSTimeoutDuration = _parseFSTimeoutDuration;
readLoop = _readLoop;
reInitInterval = _reInitInterval;
if (parseFS)

//If the input file path is the full video path then its root dir will be skipDir else if the input path is only root dir path then it is directly assigned to skipDir.
if (parseFS && boost::filesystem::path(videoPath).extension() == ".mp4")
{
skipDir = boost::filesystem::path(videoPath).parent_path().parent_path().parent_path().string();
}

else
{
skipDir = boost::filesystem::path(canonicalVideoPath).string();
}
}

void setMaxFrameSizes(size_t _maxImgFrameSize, size_t _maxMetadataFrameSize)
Expand Down
34 changes: 32 additions & 2 deletions base/src/Mp4ReaderSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ class Mp4ReaderDetailAbs
bool Init()
{
sentEOSSignal = false;

auto filePath = boost::filesystem::path(mState.mVideoPath);
if (filePath.extension() != ".mp4")
{
if (!cof->probe(filePath, mState.mVideoPath))
{
LOG_DEBUG << "Mp4 file is not present" << ">";
isVideoFileFound = false;
return true;
}
isVideoFileFound = true;
}
if (mProps.parseFS)
{
auto boostVideoTS = boost::filesystem::path(mState.mVideoPath).stem().string();
Expand Down Expand Up @@ -104,7 +114,15 @@ class Mp4ReaderDetailAbs
return;
}

auto tempSkipDir = boost::filesystem::path(tempVideoPath).parent_path().parent_path().parent_path().string();
std::string tempSkipDir;
if (boost::filesystem::path(tempVideoPath).extension() == ".mp4")
{
tempSkipDir = boost::filesystem::path(tempVideoPath).parent_path().parent_path().parent_path().string();
}
else
{
tempSkipDir = boost::filesystem::path(tempVideoPath).string();
}
if (props.parseFS && mProps.skipDir == tempSkipDir && mState.mVideoPath != "")
{
if (mProps.videoPath == props.videoPath)
Expand All @@ -117,6 +135,18 @@ class Mp4ReaderDetailAbs
{
sentEOSSignal = false;

if (boost::filesystem::path(tempVideoPath).extension() != ".mp4")
{
if (!cof->probe(tempVideoPath, mState.mVideoPath))
{
LOG_DEBUG << "Mp4 file is not present" << ">";
isVideoFileFound = false;
return;
}
isVideoFileFound = true;
tempVideoPath = mState.mVideoPath;
}

auto boostVideoTS = boost::filesystem::path(tempVideoPath).stem().string();
uint64_t start_parsing_ts = 0;
try
Expand Down
131 changes: 123 additions & 8 deletions base/test/mp4readersource_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ BOOST_AUTO_TEST_CASE(read_timeStamp_from_custom_fileName)
{
/* file structure parsing test */
std::string videoPath = "./data/Mp4_videos/h264_video/apraH264.mp4";
std::string outPath = "data/testOutput/outFrames";
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));
bool parseFS = false;
Expand All @@ -217,7 +216,6 @@ BOOST_AUTO_TEST_CASE(read_timeStamp_from_custom_fileName)
BOOST_AUTO_TEST_CASE(getSetProps_change_root_folder)
{
std::string videoPath = "./data/Mp4_videos/h264_video_metadata/20230514/0011/1686723796848.mp4";
std::string outPath = "./data/testOutput/outFrames/";
bool parseFS = true;
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));
Expand Down Expand Up @@ -248,10 +246,9 @@ BOOST_AUTO_TEST_CASE(getSetProps_change_root_folder)
BOOST_TEST(frame->timestamp == 1673420640350);
}

BOOST_AUTO_TEST_CASE(getSetProps_change_root_folder_with_custom_file_name)
BOOST_AUTO_TEST_CASE(getSetProps_change_root_folder_to_custom_file_name)
{
std::string videoPath = "./data/Mp4_videos/h264_video_metadata/20230514/0011/1686723796848.mp4";
std::string outPath = "./data/testOutput/outFrames/";
bool parseFS = true;
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));
Expand Down Expand Up @@ -283,10 +280,9 @@ BOOST_AUTO_TEST_CASE(getSetProps_change_root_folder_with_custom_file_name)
BOOST_TEST(frame->timestamp == 1673420640350);
}

BOOST_AUTO_TEST_CASE(NotParseFs_to_parseFS)
BOOST_AUTO_TEST_CASE(getSetProps_NotParseFs_to_parseFS)
{
std::string videoPath = "./data/Mp4_videos/mp4_seeks_tests_h264/apraH264.mp4";
std::string outPath = "./data/testOutput/outFrames/";
bool parseFS = false;
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));
Expand Down Expand Up @@ -318,10 +314,129 @@ BOOST_AUTO_TEST_CASE(NotParseFs_to_parseFS)
BOOST_TEST(frame->timestamp == 1685604318680);
}

BOOST_AUTO_TEST_CASE(getSetProps_change_root_folder_fail)
BOOST_AUTO_TEST_CASE(getSetProps_custom_file_name_to_root_dir)
{
std::string videoPath = "./data/Mp4_videos/mp4_seeks_tests_h264/apraH264.mp4";
bool parseFS = false;
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));

SetupMp4ReaderTest s(videoPath, h264ImageMetadata, frameType, parseFS, false);
frame_container frames;

s.mp4Reader->step();
frames = s.sink->pop();
auto frame = frames.begin()->second;
BOOST_TEST(frame->timestamp == 1673420640350);

for (int i = 0; i < 50; i++)
{
s.mp4Reader->step();
frames = s.sink->pop();
}

//change the video file path , Now read first frame new video of changed root dir instead of last frame of open video
auto propsChange = s.mp4Reader->getProps();
// To read custom file name parseFS needs to be disabled
propsChange.parseFS = true;
propsChange.videoPath = "./data/Mp4_videos/mp4_seeks_tests_h264/";
s.mp4Reader->setProps(propsChange);
s.mp4Reader->step();
frames = s.sink->pop();
frame = frames.begin()->second;
BOOST_TEST(frame->timestamp == 1673420640350);
}

BOOST_AUTO_TEST_CASE(getSetProps_root_dir_to_custom_file_name)
{
std::string videoPath = "./data/Mp4_videos/mp4_seeks_tests_h264/";
bool parseFS = true;
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));

SetupMp4ReaderTest s(videoPath, h264ImageMetadata, frameType, parseFS, false);
frame_container frames;

s.mp4Reader->step();
frames = s.sink->pop();
auto frame = frames.begin()->second;
BOOST_TEST(frame->timestamp == 1673420640350);

for (int i = 0; i < 50; i++)
{
s.mp4Reader->step();
frames = s.sink->pop();
}

//change the video file path , Now read first frame new video of changed root dir instead of last frame of open video
auto propsChange = s.mp4Reader->getProps();
// To read custom file name parseFS needs to be disabled
propsChange.parseFS = false;
propsChange.videoPath = "./data/Mp4_videos/mp4_seeks_tests_h264/apraH264.mp4";
s.mp4Reader->setProps(propsChange);
s.mp4Reader->step();
frames = s.sink->pop();
frame = frames.begin()->second;
BOOST_TEST(frame->timestamp == 1673420640350);
}

BOOST_AUTO_TEST_CASE(getSetProps_filename_to_root_dir)
{
std::string videoPath = "./data/Mp4_videos/h264_video_metadata/20230514/0011/1686723796848.mp4";
std::string outPath = "./data/testOutput/outFrames/";
bool parseFS = true;
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));

SetupMp4ReaderTest s(videoPath, h264ImageMetadata, frameType, parseFS, false);
frame_container frames;

s.mp4Reader->step();
frames = s.sink->pop();
auto frame = frames.begin()->second;
BOOST_TEST(frame->timestamp == 1686723796848);

//change the video file path , Now read first frame new video of changed root dir instead of last frame of open video
auto propsChange = s.mp4Reader->getProps();
// To read custom file name parseFS needs to be disabled
propsChange.parseFS = true;
propsChange.videoPath = "./data/Mp4_videos/mp4_seeks_tests_h264/";
s.mp4Reader->setProps(propsChange);
s.mp4Reader->step();
frames = s.sink->pop();
frame = frames.begin()->second;
BOOST_TEST(frame->timestamp == 1673420640350);
}

BOOST_AUTO_TEST_CASE(getSetProps_root_dir_to_filename)
{
std::string videoPath = "./data/Mp4_videos/mp4_seeks_tests_h264/";
bool parseFS = true;
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));

SetupMp4ReaderTest s(videoPath, h264ImageMetadata, frameType, parseFS, false);
frame_container frames;

s.mp4Reader->step();
frames = s.sink->pop();
auto frame = frames.begin()->second;
BOOST_TEST(frame->timestamp == 1673420640350);

//change the video file path , Now read first frame new video of changed root dir instead of last frame of open video
auto propsChange = s.mp4Reader->getProps();
// To read custom file name parseFS needs to be disabled
propsChange.parseFS = true;
propsChange.videoPath = "./data/Mp4_videos/h264_video_metadata/20230514/0011/1686723796848.mp4";
s.mp4Reader->setProps(propsChange);
s.mp4Reader->step();
frames = s.sink->pop();
frame = frames.begin()->second;
BOOST_TEST(frame->timestamp == 1686723796848);
}

BOOST_AUTO_TEST_CASE(getSetProps_change_root_folder_fail)
{
std::string videoPath = "./data/Mp4_videos/h264_video_metadata/20230514/0011/1686723796848.mp4";
bool parseFS = true;
auto frameType = FrameMetadata::FrameType::H264_DATA;
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0));
Expand Down
Binary file added data/ReadMe Images/ApraPipes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/ReadMe Images/Docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/ReadMe Images/Linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/ReadMe Images/nvidia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/ReadMe Images/windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 62afbab

Please sign in to comment.