Advertisement
Guest User

Untitled

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