Frame Transfer Upsetting The Server
AnsweredHi
Windows 10, VMS and Metadata 5.0.0.35745
Attempting to transfer a video frame at set intervals, but the current setup is causing the server to stop and restart, and that's before the plugin is green lit. Just wondering if the initial setup is the problem as I have run the Curl ftp upload successfully with just a named image, although timings were slightly erratic.
Key DeviceAgent info
/**
* Called when the Server sends a new uncompressed frame from a camera.
*/
bool DeviceAgent::pushUncompressedVideoFrame(const IUncompressedVideoFrame* videoFrame)
{
currentVideoFrame = videoFrame;
return true;
}
where currentVideoFrame is a const IUncompressedVideoFrame* variable.
void DeviceAgent::eventThreadLoop()
{
while (!m_terminated)
{
doSomethingHere();
// Sleep until the next event needs to be generated, or the thread is ordered
// to terminate (hence condition variable instead of sleep()). Return value
// (whether the timeout has occurred) and spurious wake-ups are ignored.
{
std::unique_lock<std::mutex> lock(m_eventThreadMutex);
if (m_terminated)
break;
const seconds kEventGenerationPeriod{ selectedDelayInSeconds };
m_eventThreadCondition.wait_for(lock, kEventGenerationPeriod);
}
}
}
The thread loop which has been working perfectly well for a simple timed message.
void DeviceAgent::doSomethingHere()
{
// Convert current videoFrame to cv::Mat
cv::Mat img(
/*_rows*/ currentVideoFrame->height(),
/*_cols*/ currentVideoFrame->width(),
/*_type*/ CV_8UC3, //< BGR color space (default for OpenCV)
/*_data*/ (void*)currentVideoFrame->data(0),
/*_step*/ (size_t)currentVideoFrame->lineSize(0));
transfer.executeFTPTransfer(img);
}
Converting the current frame of video to an openCV Mat before handing it over to a Curl based class to encode to .jpg and upload to an FTP site.
Just to re-iterate, running a transfer.executeFTPTransfer() which then simply loaded an image from file and uploaded it, did not cause the server to be upset, although the thread timing was not consistant and it did seem to give up on the fourth or fifth attempt. That I could work on.
But can't see what the issue is now I've involved the incoming video frame.
-
Quick update, it seems to be openCV that it doesn't like. The plugin compiles OK and loads Ok, but when activated the Server stops running and has to restart.
If I remove all reference to openCV the server stays active when the plugin is activated.
I will have to try and include it differently, but meanwhile there is still the issue of the thread timing not being consistent when a function call is made. The basic image transfer takes very little time but doesn't run true to the seconds set. Does a call of this nature need to be handled differently?
Thanks
-
Hello,
The proper place for processing frames is the pushCompressedVideoFrame(const ICompressedVideoPacket* videoFrame), or pushUncompressedVideoFrame(const IUncompressedVideoFrame* videoFrame), not the eventThreadLoop().
See this section of our guide for how to process frames with OpenCV, handle errors, generate events
https://meta.nxvms.com/docs/developers/knowledgebase/235-step-4-adding-object-detection
-
One more thing.
I'd suggest you not to call transfer.executeFTPTransfer(img) directly from the pushCompressedVideoFrame() but rather place the frame to a queue and return from pushCompressedVideoFrame() ASAP.
Create an additional thread that would take a frame from the queue and copy it by transfer.executeFTPTransfer(img).
Please sign in to leave a comment.
Comments
5 comments