Click here to Skip to main content
15,795,318 members
Articles / Operating Systems / Windows

Video Screen Capture with Audio

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
4 Jan 2021CPOL3 min read 14K   483   11   8
Most flexible and comprehensive yet very simple FFMpeg-based command captures all screen activity in a video file, optionally with audio
FFMpeg does it all. However, the combination of video and audio capture raises some delicate problems. The present article explains all the options and considerations for Windows


Synchronization between Audio and Video
Batch File


Capturing video from a camera is commonplace. I wanted to capture video from the computer screen, for example, to produce a video lecture. I’ve noticed several CodeProject articles describing different means of capturing everything which happens on the computer screen. I did not found what I wanted. Some solutions are bound to some obsolete video containers or obsolete components, others are over-complicated or don’t work properly.

At the same time, the solution is way simpler and is readily available: compact, open-source, and built for most platforms FFMpeg does it all.


Basically, everything is done using FFMpeg with this command line:

    -f dshow -i audio="Stereo Mix (Realtek Audio)" ^
    -f gdigrab -itsoffset 00:00:0.6 -i desktop -c:v libx264rgb ^
        -framerate 24 -crf 20 -preset ultrafast ^

Two f “enforce format” options define the methods of capturing video. Unfortunately, these methods and corresponding -i “input” options are platform-dependent. So far, I’ve sorted out the usage only for Windows, but later may need to do the same with Linux.

The first line after ffmpeg is optional and defines audio capture, two following lines — video capture. The audio capture depends on the device to be used. Sometimes, this is the audio produced by computer software, and this is the case shown in the command line above. In other cases, we need the capture from a microphone.


First of all, why using H264 (AVC) standard? The answer is: for the same reason as ultrafast: performance. Usually, we don’t need the best compression, we need the algorithm which gives us good quality but not overwhelms the CPU and other resources. If encoding is slow, it won’t encode frames in time, and it can even delay the computer operation. In this situation, AVC is a very good choice. If you have a better idea, you can always replace the codec (-c:v) parameter and codec options (next line) with something else.

Naturally, for final production, the resulting video will require transcoding using some more advanced codec with good quality and much better compression. At the time of writing, I strongly recommend the most advanced AOMedia AV1, but it can be something else. Please see FFMpeg documentation.

Video capture parameters:

Constant Rate Factor crf: valid values: 0-51, 0 is lossless, 23: default, 51: worse possible quality.

Frame rate framerate; common frame rates: 24, 25, 30, 48, 50, and 60

Presets: ultrafast, superfast, veryfast, faster, fast, medium (default), slow, veryslow; for the specific purpose of capture, we need the operation to be fast enough, caring of the compression factor much less. Perfectly compressed video with the best quality can be achieved after transcoding for production.


Audio capture is more sophisticated, as everything depends on system settings and the desired effect of capturing. On my very typical system, I have two recording devices “Microphone (Realtek Audio)” and “Stereo Mix (Realtek Audio)”. To obtain the list of available and enabled devices, use

ffmpeg -list_devices true -f dshow -i dummy

The use of a microphone is obvious, and “Stereo Mix” can be used to capture sounds produced by software.

The required device should be enabled in system settings: legacy control panel => Sound => (“Change sound card settings” => Recording) or (“Manage Audio Devices”).

Synchronization between Audio and Video

It was the first problem I noticed: the delay between video and audio. The parameter itsoffset solves this problem. In the command line sample shown above, it fixes the delay of audio relative to video by delaying video.

If this parameter is placed in the audio line, it will delay audio relative to video.

Batch File

@echo off
set tool=c:/app/Media/ffmpeg/bin/ffmpeg.exe

set videodelay=00:00:0.6
set framerate=24
set quality=20
set microphone="Microphone (Realtek Audio)"
set mix="Stereo Mix (Realtek Audio)"
set audioChoice=%mix%

set outputFile=%1
if "%outputFile%"=="" set /p outputFile=Output file name: 
if "%outputFile%"=="" goto:request-file

%tool% ^
    -f dshow -i audio=%audioChoice% ^
    -f gdigrab -itsoffset %videodelay% -i desktop -c:v libx264rgb ^
        -framerate %framerate% -crf %quality% -preset ultrafast ^

The file name is requested by the script or entered as a command-line parameter, other parameters are rarely changed, can be adjusted manually.

The user will need to edit the path to “ffmpeg.exe” or setup the PATH environment variable accordingly.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
United States United States
Physics, physical and quantum optics, mathematics, computer science, control systems for manufacturing, diagnostics, testing, and research, theory of music, musical instruments… Contact me:

Comments and Discussions

GeneralThis is a helpful article Pin
Bryan Wagan27-May-21 19:02
Bryan Wagan27-May-21 19:02 
AnswerRe: This is a helpful article Pin
Sergey Alexandrovich Kryukov3-Jun-21 14:56
mvaSergey Alexandrovich Kryukov3-Jun-21 14:56 
Questionsounds promising ... Pin
Christ Kennedy29-Jan-21 10:13
mvaChrist Kennedy29-Jan-21 10:13 
AnswerRe: sounds promising ... Pin
Sergey Alexandrovich Kryukov30-Jan-21 10:00
mvaSergey Alexandrovich Kryukov30-Jan-21 10:00 
QuestionAnother 5 Pin
AndyChisholm6-Jan-21 7:46
AndyChisholm6-Jan-21 7:46 
AnswerRe: Another 5 Pin
Sergey Alexandrovich Kryukov6-Jan-21 8:14
mvaSergey Alexandrovich Kryukov6-Jan-21 8:14 
GeneralMy vote of 5 Pin
S Houghtelin5-Jan-21 8:26
professionalS Houghtelin5-Jan-21 8:26 
AnswerRe: My vote of 5 Pin
Sergey Alexandrovich Kryukov5-Jan-21 9:40
mvaSergey Alexandrovich Kryukov5-Jan-21 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.