screen(not)recording
This commit is contained in:
parent
70420600a0
commit
fd96a88fc6
@ -43,7 +43,7 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
@ -73,6 +73,9 @@
|
|||||||
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<VcpkgUseStatic>true</VcpkgUseStatic>
|
<VcpkgUseStatic>true</VcpkgUseStatic>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<VcpkgUseStatic>true</VcpkgUseStatic>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
@ -107,9 +110,11 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
|
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
@ -122,6 +127,7 @@
|
|||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "addWatermark.h"
|
#include "addWatermark.h"
|
||||||
|
|
||||||
void captureScreen(std::string file_screenshot)
|
inline void captureScreen()
|
||||||
{
|
{
|
||||||
|
std::string file_screenshot = "screenshot_" + std::to_string(time(NULL)) + ".bmp";
|
||||||
|
|
||||||
HDC hdcScreen;
|
HDC hdcScreen;
|
||||||
HDC hdcDIB;
|
HDC hdcDIB;
|
||||||
HBITMAP hbmDIB;
|
HBITMAP hbmDIB;
|
||||||
|
@ -1,8 +1,56 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../Include/Include.h"
|
#include "../Include/Include.h"
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
|
||||||
void screenRecorder(std::string file_video)
|
inline void screenRecorder(std::string ffilename)
|
||||||
{
|
{
|
||||||
std::string command = "ffmpeg -f gdigrab -framerate 60 -i desktop -c:v libx264 -preset ultrafast -tune zerolatency -crf 25 -pix_fmt yuv420p " + ("C:\\Users\\" + (std::string)std::getenv("USERNAME") + "\\Documents\\vos.team\\video\\" + file_video);
|
std::string filename = "video.avi"; //temporary fix
|
||||||
system(command.c_str());
|
|
||||||
|
int screen_width = GetSystemMetrics(SM_CXSCREEN);
|
||||||
|
int screen_height = GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
cv::Size screen_size(screen_width, screen_height);
|
||||||
|
|
||||||
|
int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
|
||||||
|
|
||||||
|
// Create video writer object
|
||||||
|
cv::VideoWriter writer(filename, fourcc, 60.0, screen_size);
|
||||||
|
|
||||||
|
// Check if writer is ready
|
||||||
|
if (!writer.isOpened())
|
||||||
|
{
|
||||||
|
std::cout << "Error opening video file" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capture screen and write frames to video file
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// Capture screen image
|
||||||
|
HDC hScreen = GetDC(NULL);
|
||||||
|
HDC hDC = CreateCompatibleDC(hScreen);
|
||||||
|
HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, screen_width, screen_height);
|
||||||
|
HGDIOBJ hOld = SelectObject(hDC, hBitmap);
|
||||||
|
BitBlt(hDC, 0, 0, screen_width, screen_height, hScreen, 0, 0, SRCCOPY);
|
||||||
|
cv::Mat img = cv::Mat(screen_height, screen_width, CV_8UC4);
|
||||||
|
//cv::cuda::GpuMat img = cv::cuda::GpuMat(screen_height, screen_width, CV_8UC4);
|
||||||
|
GetBitmapBits(hBitmap, screen_width * screen_height * 4, img.data);
|
||||||
|
cv::cvtColor(img, img, cv::COLOR_RGBA2RGB);
|
||||||
|
|
||||||
|
// Write frame to video file
|
||||||
|
writer.write(img);
|
||||||
|
|
||||||
|
// Release resources
|
||||||
|
SelectObject(hDC, hOld);
|
||||||
|
DeleteDC(hDC);
|
||||||
|
DeleteObject(hBitmap);
|
||||||
|
ReleaseDC(NULL, hScreen);
|
||||||
|
|
||||||
|
// Check for escape key to exit loop (doesn't work)
|
||||||
|
if (GetAsyncKeyState(VK_ESCAPE))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release video writer and close windows
|
||||||
|
writer.release();
|
||||||
|
cv::destroyAllWindows();
|
||||||
}
|
}
|
@ -10,7 +10,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string file_screenshot = "screenshot_" + std::to_string(time(NULL)) + ".bmp";
|
std::string file_screenshot = "screenshot_" + std::to_string(time(NULL)) + ".bmp";
|
||||||
std::string file_video = "video_" + std::to_string(time(NULL)) + ".mp4";
|
|
||||||
|
|
||||||
switch (msg)
|
switch (msg)
|
||||||
{
|
{
|
||||||
@ -26,11 +25,12 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
else if (wParam == 3)
|
else if (wParam == 3)
|
||||||
{
|
{
|
||||||
captureScreen(file_screenshot);
|
captureScreen();
|
||||||
}
|
}
|
||||||
else if (wParam == 4)
|
else if (wParam == 4)
|
||||||
{
|
{
|
||||||
screenRecorder(file_video);
|
std::thread t(screenRecorder, file_screenshot);
|
||||||
|
t.join();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
@ -104,6 +104,5 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
UnregisterHotKey(hwnd, 3);
|
UnregisterHotKey(hwnd, 3);
|
||||||
UnregisterHotKey(hwnd, 4);
|
UnregisterHotKey(hwnd, 4);
|
||||||
|
|
||||||
exit(0);
|
|
||||||
return Msg.wParam;
|
return Msg.wParam;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user