[FFmpeg-user] a few seconds delay when screen recording with ffmpeg and GPU(Nvidia Tesla T4)

kanata koyama kanata.koyama at babel.jp
Fri Apr 21 10:25:19 EEST 2023

I am trying to figure out how to start a chrome browser on a ubuntu 22.04
machine and take a screen recording with ffmpeg using the GPU,

1. the first few seconds of the video freezes.
2. after that, the video lags behind the audio by a few seconds.

I am having trouble with 2 in particular. Could you please tell me how to
fix it? Thanks!
here is more info👇

Dockerfile (only installation of ffmpeg)

RUN apt-get update \
&& apt-get install -y \
-o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
ffmpeg \

browser launch (puppeteer-core at 19.4.1)
import {launch} from 'puppeteer-core';

browser = await launch({
defaultViewport: null,
headless: false,
ignoreHTTPSErrors: true,
ignoreDefaultArgs: ['--mute-audio', '--enable-automation'],
handleSIGTERM: false,
handleSIGHUP: false,
handleSIGINT: false,
args: [
// Options that might enable usage of hardware GPU
// See:
dumpio: true,
executablePath: '/usr/bin/google-chrome-stable',

a few seconds later, ffmpeg command is executed👇
const recordingProcess = spawn(
// Record entire screen
// Record audio too
// output encoding options
'hevc_nvenc', // H.265
outputFile, // mp4
stdio: ['pipe', 'pipe', 'pipe'],

here is my experiment log👇

- thread_queue_size = 32 -> Video freezes entirely.
- thread_queue_size = 128 -> overall freeze is resolved, but the gap
between audio and video remained.
- thread_queue_size > 128 -> overall freeze is resolved, but the gap
between audio and video is not improved at all.
- vcodec = hevc_nvenc, h246_nvenc -> No improvement
- (b:v, maxrate, bufsize) = (1M, 1M, 0.5M), (2M, 2M, 1M) -> No improvement
- preset: no improvement, but may tend to
    - preset=fast -> audio is slower
    - preset=medium -> audio is faster
    - preset=slow -> audio is faster
- af =
    -> No improvement.
- vsync = 0,1,2 -> no improvement.
- (async,vsync) = (1,1) -> no improvement
- crf = 18 -> no improvement
- (hwaccel,hwaccel_output_format) = (cuda,cuda), (not specified,not
specified) -> no improvement

More information about the ffmpeg-user mailing list