The command below can record screen video by ffmpeg on Windows.
ffmpeg -y -rtbufsize 100M -f gdigrab -framerate 30 -probesize 10M -draw_mouse 1 -i title="Task Manager" -c:v libx264 -r 30 -preset ultrafast -tune zerolatency -crf 25 -pix_fmt yuv420p "video output.mp4"
There may be a problem due to the window size. Add this arugment.
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"
You can type this command to find the name of the target window.
tasklist /v /fi "imagename eq chrome.exe" /fo list
If you find that your video is black/blank on Chrome, you may need to disable the GPU hardware acceleration function.
- For Chrome, you can google it.
- For Chromedriver, add argument: "--disable-gpu".
ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url}
-y (https://www.ffmpeg.org/ffmpeg.html#Main-options) Overwrite output files without asking.
-rtbufsize 100M (https://trac.ffmpeg.org/wiki/DirectShow#BufferingLatency) Prevent some frames in the buffer from being dropped.
-f gdigrab
-f fmt (input/output) Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.
gdigrab (https://www.ffmpeg.org/ffmpeg-devices.html#gdigrab) Win32 GDI-based screen capture device. This device allows you to capture a region of the display on Windows.
-framerate 30 (https://www.ffmpeg.org/ffmpeg-all.html#framerate) Change the frame rate by interpolating new video output frames from the source frames.
-probesize 10M (https://www.ffmpeg.org/ffmpeg-formats.html#Format-Options) Set probing size in bytes, i.e. the size of the data to analyze to get stream information. A higher value will enable detecting more information in case it is dispersed into the stream, but will increase latency. Must be an integer not lesser than 32. It is 5000000 by default.
-draw_mouse 1 (https://www.ffmpeg.org/ffmpeg-devices.html#Options-9) Specify whether to draw the mouse pointer. Use the value 0 to not draw the pointer. Default value is 1
-i title="Task Manager" (https://www.ffmpeg.org/ffmpeg-devices.html#avfoundation)
-c:v libx264 (https://www.ffmpeg.org/ffmpeg.html#Main-options) Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. codec is the name of a decoder/encoder or a special value copy (output only) to indicate that the stream is not to be re-encoded.
-r 30 (https://www.ffmpeg.org/ffmpeg.html#Video-Options)
-preset ultrafast (https://trac.ffmpeg.org/wiki/Encode/H.264#Preset) A preset is a collection of options that will provide a certain encoding speed to compression ratio. A slower preset will provide better compression (compression is quality per filesize). This means that, for example, if you target a certain file size or constant bit rate, you will achieve better quality with a slower preset. Similarly, for constant quality encoding, you will simply save bitrate by choosing a slower preset.
-tune zerolatency (https://trac.ffmpeg.org/wiki/Encode/H.264#Tune) You can optionally use -tune to change settings based upon the specifics of your input. Current tunings include: ...
-crf 25 (https://trac.ffmpeg.org/wiki/Encode/H.264#crf) (http://slhck.info/video/2017/02/24/crf-guide.html) The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default, and 51 is worst quality possible.
-pix_fmt yuv420p (https://ffmpeg.org/ffmpeg.html#Advanced-Video-options)
How to record headless chrome?
I also tried to write a Chrome extension to record the screen, but unfortunately, extensions can not be enabled in headless mode.