發表文章

目前顯示的是 3月, 2020的文章

Dev-C++ Socket Programing

Dev-C++ Socket Programing 如果編譯器 出現錯誤 "undefine reference to _imp_send" 則需要 在 Tool -> Compiler Option -> General 加入 -lws2_32

Screen Recorder C++ FFmpeg 4.2 on Windows

Screen Recorder C++ FFmpeg 4.2 on Windows 螢幕錄影並儲存為 .mp4 檔案 (使用 Visual Studio 2019) 一. 編譯器設定 1.專案屬性 -> C\C++ -> 一般 -> 其他 Include 目錄 : D:\Dev\ffmpeg-4.2.2-win32-dev\include 2.專案屬性 -> 連結器 -> 輸入 -> 其他相依性 :在最前面加入 D:\Dev\ffmpeg-4.2.2-win32-dev\lib\*.lib;Winmm.lib 3. 專案屬性 -> 連結器 -> 進階 -> SAFESEH : NO 二.------------------------------------Source.cpp------------------------------- #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <thread> #include<time.h> #include <iostream> using namespace std; #define __STDC_CONSTANT_MACROS extern "C" { #include <libavutil/avassert.h> #include <libavutil/channel_layout.h> #include <libavutil/opt.h> #include <libavutil/mathematics.h> #include <libavutil/timestamp.h> #include <libavformat/avformat.h> #include "libavutil/imgutils.h" #include <libswscale/swscale.h> #in
Capture Screen and store it in a buffer C++ on Windows ----------------------------------Source.cpp---------------------- #include <Windows.h> #include <iostream> #include <math.h> #include <stdio.h> using namespace std; HBITMAP GetScreenBmp(HDC hdc) {     // Get screen dimensions     int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);     int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);     // Create compatible DC, create a compatible bitmap and copy the screen using BitBlt()     HDC hCaptureDC = CreateCompatibleDC(hdc);     HBITMAP hBitmap = CreateCompatibleBitmap(hdc, nScreenWidth, nScreenHeight);     HGDIOBJ hOld = SelectObject(hCaptureDC, hBitmap);     BOOL bOK = BitBlt(hCaptureDC, 0, 0, nScreenWidth, nScreenHeight, hdc, 0, 0, SRCCOPY | CAPTUREBLT);     SelectObject(hCaptureDC, hOld); // always select the previously selected object once done     DeleteDC(hCaptureDC);     return hBitmap; } BYTE* get_screen_image(HDC hdc,HBITMAP hBitmap) {     BITMAPINFO
Capture Screen C++ on Windows Capture Screen and store it as a .bmp file 1.----------------------------Source.cpp------------------------ #include<iostream> #include<Windows.h> using namespace std; // file size = sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + dwPaletteSize + dwBmBitsSize BOOL SaveBitmapToFile(HBITMAP   hBitmap, LPCSTR szfilename) {     HDC     hDC;     //当前分辨率下每象素所占字节数              int     iBits;     //位图中每象素所占字节数              WORD     wBitCount;     //定义调色板大小,     位图中像素字节大小     ,位图文件大小     ,     写入文件字节数                  DWORD     dwPaletteSize = 0, dwBmBitsSize = 0, dwDIBSize = 0, dwWritten = 0;     //位图属性结构                  BITMAP     Bitmap;     //位图文件头结构              BITMAPFILEHEADER     bmfHdr;     //位图信息头结构                  BITMAPINFOHEADER     bi;     //指向位图信息头结构                      LPBITMAPINFOHEADER     lpbi;     //定义文件,分配内存句柄,调色板句柄                  HANDLE     fh, hDib, hPal, hOldPal = NULL;     //计算位
Audio Recorder C++ FFmpeg 4.2 on Windows using Visual Studio 2019 1.Install VBCable Set up reference: https://mediarealm.com.au/articles/stereo-mix-setup-windows-10/ 2.Set up C++ property & Linker property in project property (Linker : add Winmm.lib; in somewhere) 3.-----------------------------Souce.cpp--------------------------- #define _CRT_SECURE_NO_WARNINGS //#include <QDebug> //#include <QByteArray> #include <stdio.h> #include <iostream> #define __STDC_CONSTANT_MACROS extern "C" { #include <libavutil/avassert.h> #include <libavutil/channel_layout.h> #include <libavutil/opt.h> #include <libavutil/mathematics.h> #include <libavutil/timestamp.h> #include <libavformat/avformat.h> //#include "libavutil/imgutils.h" #include <libswscale/swscale.h> #include <libswresample/swresample.h> } #include <windows.h> using namespace std; const int NUMPTS = 44100 * 5; int sampleRate
錄製 從音效卡 播放出來的聲音 (Windows 10) Record sound from your sound card on Windows 10 1.Download  VBCable : https://www.vb-audio.com/Cable/index.htm Install it and then reboot When you set the VB Audio Cable as your new Default Playback Device, you won’t be able to hear the audio through the speakers. Thankfully, Windows 10 comes with an easy solution. Open up the Sound Control Panel again, go to the “Recording” tab, and select “Properties”. In the “Listen” tab is a checkbox called “Listen to this device”. 2.Download Audacity 3.open Audacity 編輯 -> 編號設定 -> 裝置 -> 播放 選擇  CABLE Input (...) 編輯 -> 編號設定 -> 裝置 -> 錄製 選擇  CABLE Output (...) 4.Enjoy Reference: https://mediarealm.com.au/articles/stereo-mix-setup-windows-10/ https://www.tenforums.com/drivers-hardware/111899-stereo-mix-no-longer-appears.html#post1389803
圖片
FFmpeg 4.2 Muxing C++ 已成功編譯 ffmpeg-4.2.2-win32-dev\examples 裡的 muxing.c (用 Visual Studio 2019) 見以下源碼 (修改一些) -----------------------------Source.cpp------------------------ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #define __STDC_CONSTANT_MACROS extern "C" { #include <libavutil/avassert.h> #include <libavutil/channel_layout.h> #include <libavutil/opt.h> #include <libavutil/mathematics.h> #include <libavutil/timestamp.h> #include <libavformat/avformat.h> #include <libswscale/swscale.h> #include <libswresample/swresample.h> } #define STREAM_DURATION   10.0 #define STREAM_FRAME_RATE 25 /* 25 images/s */ #define STREAM_PIX_FMT    AV_PIX_FMT_YUV420P /* default pix_fmt */ #define SCALE_FLAGS SWS_BICUBIC // a wrapper around a single output AVStream typedef struct OutputStream {     AVStream* st;     AVCodecContext* enc;     /* pts of the nex