Advertisement
Guest User

Untitled

a guest
Aug 6th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. #include <windows.h>
  2. #include <vector>
  3. #include <chrono>
  4. #include <numeric>
  5. #include <vfw.h>
  6. #include "avi_utils.h"
  7.  
  8. #pragma comment(lib, "Vfw32")
  9.  
  10. int main()
  11. {
  12.     DIBSECTION dibs;
  13.     BITMAPINFO bmi;
  14.     std::vector<unsigned long long> times(100);
  15.     HAVI avi = CreateAvi("test.avi", 50, nullptr); // 50ms is the period between frames
  16.     HDC hdcScreen = ::GetDC(HWND_DESKTOP);
  17.     HDC hdcShot = ::CreateCompatibleDC(hdcScreen);
  18.     int cx = GetDeviceCaps(hdcScreen, HORZRES);
  19.     int cy = GetDeviceCaps(hdcScreen, VERTRES);
  20.     void *pBits = nullptr;
  21.     memset(&bmi, 0, sizeof(BITMAPINFO));
  22.     bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  23.     bmi.bmiHeader.biWidth = cx;
  24.     bmi.bmiHeader.biHeight = cy;
  25.     bmi.bmiHeader.biPlanes = 1;
  26.     bmi.bmiHeader.biBitCount = 32;
  27.     bmi.bmiHeader.biCompression = BI_RGB;
  28.     HGDIOBJ hbmpShot = CreateDIBSection(hdcScreen, &bmi, DIB_RGB_COLORS, (void**)&pBits, nullptr, 0);
  29.     HGDIOBJ hbmpSys = SelectObject(hdcShot, hbmpShot);
  30.     GetObject(hbmpShot, sizeof(dibs), &dibs);
  31.  
  32.     for( size_t i = times.size(); i--; ) {
  33.         auto start = std::chrono::high_resolution_clock::now();
  34.         ::BitBlt(hdcShot, 0, 0, cx, cy, hdcScreen, 0, 0, SRCCOPY);
  35.         AddAviFrame(avi, &dibs);
  36.         auto finish = std::chrono::high_resolution_clock::now();
  37.         times[i] = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count();
  38.     }
  39.     ::ReleaseDC(HWND_DESKTOP, hdcScreen);
  40.     SelectObject(hdcShot, hbmpSys);
  41.     ::DeleteObject(hbmpShot);
  42.     ::DeleteDC(hdcShot);
  43.     CloseAvi(avi);
  44.     printf("Time: %f\n", double(std::accumulate(times.begin(), times.end(), (unsigned long long)0)) / times.size());
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement