diff --git a/base/include/H264EncoderV4L2.h b/base/include/H264EncoderV4L2.h index 19c0319a7..694dcad1c 100644 --- a/base/include/H264EncoderV4L2.h +++ b/base/include/H264EncoderV4L2.h @@ -39,7 +39,6 @@ class H264EncoderV4L2 : public Module std::shared_ptr mHelper; H264EncoderV4L2Props mProps; - framemetadata_sp mOutputMetadata; std::string motionVectorFramePinId; std::string h264FrameOutputPinId; }; diff --git a/base/include/H264EncoderV4L2Helper.h b/base/include/H264EncoderV4L2Helper.h index d1d1ef776..71aa96868 100644 --- a/base/include/H264EncoderV4L2Helper.h +++ b/base/include/H264EncoderV4L2Helper.h @@ -4,7 +4,7 @@ #include "ExtFrame.h" #include "AV4L2ElementPlane.h" #include "V4L2CUYUV420Converter.h" -#include "v4l2_nv_extensions.h" +#include class H264EncoderV4L2Helper { diff --git a/base/src/H264EncoderV4L2.cpp b/base/src/H264EncoderV4L2.cpp index d2b941cd1..e22a248ca 100644 --- a/base/src/H264EncoderV4L2.cpp +++ b/base/src/H264EncoderV4L2.cpp @@ -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); @@ -143,8 +143,6 @@ bool H264EncoderV4L2::processSOS(frame_sp &frame) } auto h264OutMetadata = framemetadata_sp(new H264Metadata(width, height)); - auto h264Metadata = FrameMetadataFactory::downcast(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, diff --git a/base/src/H264EncoderV4L2Helper.cpp b/base/src/H264EncoderV4L2Helper.cpp index cf682a929..8be1256ab 100644 --- a/base/src/H264EncoderV4L2Helper.cpp +++ b/base/src/H264EncoderV4L2Helper.cpp @@ -275,26 +275,23 @@ void H264EncoderV4L2Helper::serializeMotionVectors(v4l2_ctrl_videoenc_outputbuf_ std::vector 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(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(x); - frameBuffer[mCount + 1] = static_cast(y); - frameBuffer[mCount + 2] = 1; circleOverlays.push_back(circleOverlay); } } diff --git a/base/test/h264encoderv4l2_tests.cpp b/base/test/h264encoderv4l2_tests.cpp index 1698d5292..c0c609825 100755 --- a/base/test/h264encoderv4l2_tests.cpp +++ b/base/test/h264encoderv4l2_tests.cpp @@ -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(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(new H264EncoderV4L2(encoderProps)); - fileReader->setNext(encoder); - - auto muxer = boost::shared_ptr(new FramesMuxer()); - fileReader->setNext(muxer); - encoder->setNext(muxer); - - auto overlay = boost::shared_ptr(new OverlayModule(OverlayModuleProps())); - muxer->setNext(overlay); - - auto sink = boost::shared_ptr(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()