Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <vector>
- #include <chrono>
- #include <numeric>
- #include <vfw.h>
- #include "avi_utils.h"
- #pragma comment(lib, "Vfw32")
- int main()
- {
- DIBSECTION dibs;
- BITMAPINFO bmi;
- std::vector<unsigned long long> times(100);
- HAVI avi = CreateAvi("test.avi", 50, nullptr); // 50ms is the period between frames
- HDC hdcScreen = ::GetDC(HWND_DESKTOP);
- HDC hdcShot = ::CreateCompatibleDC(hdcScreen);
- int cx = GetDeviceCaps(hdcScreen, HORZRES);
- int cy = GetDeviceCaps(hdcScreen, VERTRES);
- void *pBits = nullptr;
- memset(&bmi, 0, sizeof(BITMAPINFO));
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = cx;
- bmi.bmiHeader.biHeight = cy;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = 32;
- bmi.bmiHeader.biCompression = BI_RGB;
- HGDIOBJ hbmpShot = CreateDIBSection(hdcScreen, &bmi, DIB_RGB_COLORS, (void**)&pBits, nullptr, 0);
- HGDIOBJ hbmpSys = SelectObject(hdcShot, hbmpShot);
- GetObject(hbmpShot, sizeof(dibs), &dibs);
- for( size_t i = times.size(); i--; ) {
- auto start = std::chrono::high_resolution_clock::now();
- ::BitBlt(hdcShot, 0, 0, cx, cy, hdcScreen, 0, 0, SRCCOPY);
- AddAviFrame(avi, &dibs);
- auto finish = std::chrono::high_resolution_clock::now();
- times[i] = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count();
- }
- ::ReleaseDC(HWND_DESKTOP, hdcScreen);
- SelectObject(hdcShot, hbmpSys);
- ::DeleteObject(hbmpShot);
- ::DeleteDC(hdcShot);
- CloseAvi(avi);
- printf("Time: %f\n", double(std::accumulate(times.begin(), times.end(), (unsigned long long)0)) / times.size());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement