Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing Video Recording not working on Linux SDK #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions src/raw_record/ZoomSDKRendererDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,40 @@ ZoomSDKRendererDelegate::ZoomSDKRendererDelegate() {

void ZoomSDKRendererDelegate::onRawDataFrameReceived(YUVRawDataI420 *data)
{
auto res = async(launch::async, [&]{
Mat I420(data->GetStreamHeight() * 3/2, data->GetStreamWidth(), CV_8UC1, data->GetBuffer());
Mat small, gray;

cvtColor(I420, gray, COLOR_YUV2GRAY_I420);
std::cout << "onRawDataFrameReceived." << std::endl;

std::cout << "width." << data->GetStreamWidth() << std::endl;
std::cout << "height." << data->GetStreamHeight() << std::endl;

SaveToRawYUVFile(data);
}

void ZoomSDKRendererDelegate::SaveToRawYUVFile(YUVRawDataI420* data) {

// Open the file for writing
std::ofstream outputFile("out/video.yuv", std::ios::out | std::ios::binary | std::ios::app);
if (!outputFile.is_open())
{
std::cout << "Error opening file." << std::endl;
return;
}
// Calculate the sizes for Y, U, and V components
size_t ySize = data->GetStreamWidth() * data->GetStreamHeight();
size_t uvSize = ySize / 4;

resize(gray, small, Size(), m_fx, m_fx, INTER_LINEAR);
equalizeHist(small, small);

m_cascade.detectMultiScale(small, m_faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30));

stringstream ss;
ss << m_faces.size();
m_socketServer.writeStr(ss.str());
// Write Y, U, and V components to the output file
outputFile.write(data->GetYBuffer(), ySize);
outputFile.write(data->GetUBuffer(), uvSize);
outputFile.write(data->GetVBuffer(), uvSize);

if (m_frameCount++ % 2 == 0) {
Scalar color = Scalar(0, 0, 255);
for (size_t i = 0; i < m_faces.size(); i++) {
Rect r = m_faces[i];
rectangle( gray, Point(cvRound(r.x*m_scale), cvRound(r.y*m_scale)),
Point(cvRound((r.x + r.width-1)*m_scale),
cvRound((r.y + r.height-1)*m_scale)), color, 3, 8, 0);
}

imshow(c_window, gray);
}
});
// Close the file
outputFile.close();
outputFile.flush();
//cout << "YUV420 buffer saved to file." << endl;
}

void ZoomSDKRendererDelegate::writeToFile(const string &path, YUVRawDataI420 *data)
Expand Down
1 change: 1 addition & 0 deletions src/raw_record/ZoomSDKRendererDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ZoomSDKRendererDelegate : public IZoomSDKRendererDelegate {
void onRawDataFrameReceived(YUVRawDataI420* data) override;
void onRawDataStatusChanged(RawDataStatus status) override {};
void onRendererBeDestroyed() override {};
void SaveToRawYUVFile(YUVRawDataI420* data);
};


Expand Down