Learning ffmpeg-screen recording to achieve recording

The project needs a screen recording function. I saw a way to use Qt timer + screenshot + avilib to generate AVI + ffmpeg to combine video and audio:

Qt C++ screen recording function realization (avilib+ffmpeg) and dynamic library generation

https://blog.csdn.net/qq_35769071/article/details/125323624

After using it, there are many problems; first, the pos in the 32-bit avilib is a signed long type, if the size of the image to be saved is larger than the effective range of the long type, it will crash; if the resolution is 1920*1080, the video It can only be saved for about 2 minutes; secondly, the video and audio are recorded separately and need to be merged with ffmpeg.exe. If the continuous recording is 2 hours, the large files of avi and mav are merged with ffmpeg, which may cause problems;

A colleague found an open source C# example, Captura-9.0.0-beta4, which can support recording in selected regions; the bottom layer is realized by the ffmpeg command called by process;

I still think that the ffmpeg library of C++ should be used to realize this function;

The classmate recommended the basic ffmpeg book and the Windows library available for compilation. If necessary, you can download it from the link below;

Link: https://pan.baidu.com/s/1xnHlS0KLUelzSqT5nUleLg

Extraction code: hl1q

Here is an address for ffmpeg to realize screen recording;

FFMPEG screen recording (1) ---- recording desktop

https://blog.csdn.net/peilinok/article/details/102981560

It contains the common usage of ffmpeg, and an open source code for screen recording:

https://gitcode.net/mirrors/peilinok/screen-recorder?utm_source=csdn_github_accelerator

ffmpeg used

Problems encountered:

Need to turn off the log printing of ffmpeg

av_log_set_level(AV_LOG_ERROR);

If you need to record an extended screen, you need to use the record_desktop_duplication class in Recorder to obtain all adapter information according to get_adapters. The coordinates of the main screen start from (0,0), and the extended screen is calculated relative to the coordinates of the main screen ;

auto adapters = d3d_helper::get_adapters(&error, true);

Modify in the function get_dst_adapter, the logic in for needs to record the information of each adapter in the adapters, and then decide to record the screen; there is another question, how to get the zoom ratio of the screen?

int record_desktop_duplication::get_dst_adapter(IDXGIAdapter ** adapter)

If the main screen is zoomed, you need to calculate the position relative to 1920*1080. Take my screen as an example:

Guess you like

Origin blog.csdn.net/liushao1031177/article/details/128624358