Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedzakikochargi committed Aug 21, 2023
1 parent 48e2e74 commit 068b47e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 58 deletions.
1 change: 0 additions & 1 deletion base/include/H264EncoderV4L2.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class H264EncoderV4L2 : public Module
std::shared_ptr<H264EncoderV4L2Helper> mHelper;

H264EncoderV4L2Props mProps;
framemetadata_sp mOutputMetadata;
std::string motionVectorFramePinId;
std::string h264FrameOutputPinId;
};
2 changes: 1 addition & 1 deletion base/include/H264EncoderV4L2Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ExtFrame.h"
#include "AV4L2ElementPlane.h"
#include "V4L2CUYUV420Converter.h"
#include "v4l2_nv_extensions.h"
#include <v4l2_nv_extensions.h>

class H264EncoderV4L2Helper
{
Expand Down
4 changes: 1 addition & 3 deletions base/src/H264EncoderV4L2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

H264EncoderV4L2::H264EncoderV4L2(H264EncoderV4L2Props props) : Module(TRANSFORM, "H264EncoderV4L2", props), mProps(props)
{
mOutputMetadata = framemetadata_sp(new H264Metadata(0, 0));
auto mOutputMetadata = framemetadata_sp(new H264Metadata(0, 0));
auto motionVectorOutputMetadata = framemetadata_sp(new FrameMetadata(FrameMetadata::OVERLAY_INFO_IMAGE));
h264FrameOutputPinId = addOutputPin(mOutputMetadata);
motionVectorFramePinId = addOutputPin(motionVectorOutputMetadata);
Expand Down Expand Up @@ -143,8 +143,6 @@ bool H264EncoderV4L2::processSOS(frame_sp &frame)
}

auto h264OutMetadata = framemetadata_sp(new H264Metadata(width, height));
auto h264Metadata = FrameMetadataFactory::downcast<H264Metadata>(h264OutMetadata);
h264Metadata->setData(*h264Metadata);
Module::setMetadata(h264FrameOutputPinId, h264OutMetadata);

mHelper = H264EncoderV4L2Helper::create(v4l2MemType, pixelFormat, width, height, step, 1024 * mProps.targetKbps, mProps.enableMotionVectors, mProps.motionVectorThreshold, 30,h264FrameOutputPinId, motionVectorFramePinId, h264OutMetadata,
Expand Down
11 changes: 4 additions & 7 deletions base/src/H264EncoderV4L2Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,23 @@ void H264EncoderV4L2Helper::serializeMotionVectors(v4l2_ctrl_videoenc_outputbuf_
std::vector<CircleOverlay> circleOverlays;
CompositeOverlay compositeOverlay;

int totalMacroblockInRow = floor(mWidth / 16);
int totalMacroblockInRow = floor(mWidth / 16); // Tells about the total number of macro blocks in each row.
auto motionVectorFrame = makeFrame(1024 * 1024 * 3, motionVectorFramePinId);
uint32_t *frameBuffer = reinterpret_cast<uint32_t *>(motionVectorFrame->data());
size_t mCount = 0;
for (uint32_t i = 0; i < numMVs; i++, pInfo++)
for (uint32_t i = 0; i < numMVs; i++, pInfo++) // numMVs is the total macroblock in the frame.
{

if (abs(pInfo->mv_x) > motionVectorThreshold || abs(pInfo->mv_y) > motionVectorThreshold)
{
auto tempY = floor(i / totalMacroblockInRow);
auto y = tempY * 16 + 8;
auto tempY = floor(i / totalMacroblockInRow); // i represents current macroblock , To get the y offset of macroblock the current macroblock is divided by macroblock across width.
auto y = tempY * 16 + 8; // Here every macroblock is of 16x16 , So multiply it by 16. To get to the centre of the macroblock add it by 8.
auto tempX = floor(i % totalMacroblockInRow);
auto x = tempX * 16 + 8;
CircleOverlay circleOverlay;
circleOverlay.x1 = x;
circleOverlay.y1 = y;
circleOverlay.radius = 1;
frameBuffer[mCount] = static_cast<uint32_t>(x);
frameBuffer[mCount + 1] = static_cast<uint32_t>(y);
frameBuffer[mCount + 2] = 1;
circleOverlays.push_back(circleOverlay);
}
}
Expand Down
46 changes: 0 additions & 46 deletions base/test/h264encoderv4l2_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,50 +282,4 @@ BOOST_AUTO_TEST_CASE(encode_and_extract_motion_vectors)
}
}
}

BOOST_AUTO_TEST_CASE(encode_and_extract_motion_vector_overlay,*boost::unit_test::disabled())
{
// metadata is known
auto width = 640;
auto height = 360;

auto fileReader = boost::shared_ptr<FileReaderModule>(new FileReaderModule(FileReaderModuleProps("./data/Raw_YUV420_640x360/Image???_YUV420.raw")));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(width, height, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
auto rawImagePin = fileReader->addOutputPin(metadata);

H264EncoderV4L2Props encoderProps;
encoderProps.targetKbps = 1024;
encoderProps.enableMotionVectors = true;
auto encoder = boost::shared_ptr<Module>(new H264EncoderV4L2(encoderProps));
fileReader->setNext(encoder);

auto muxer = boost::shared_ptr<Module>(new FramesMuxer());
fileReader->setNext(muxer);
encoder->setNext(muxer);

auto overlay = boost::shared_ptr<OverlayModule>(new OverlayModule(OverlayModuleProps()));
muxer->setNext(overlay);

auto sink = boost::shared_ptr<ExternalSinkModule>(new ExternalSinkModule());
overlay->setNext(sink);

BOOST_TEST(fileReader->init());
BOOST_TEST(encoder->init());
BOOST_TEST(muxer->init());
BOOST_TEST(overlay->init());
BOOST_TEST(sink->init());

fileReader->play(true);

for (auto i = 0; i < 40; i++)
{
fileReader->step();
encoder->step();
muxer->step();
muxer->step();
overlay->step();
auto frames = sink->pop();
}
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 068b47e

Please sign in to comment.