Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

get consistent 60fps while recording X screen with ffmpeg

I wrote the following script to record an X screen for a specified amount of time, to make sure that it's lossless I've separated it into two steps

  1. record for the specified amount in a codec that requires almost no compression (so there's no overhead that might cause frames to be dropped)
  2. re-encode the original video into HEVC to make the filesize significantly smaller
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -vsync 1 -f x11grab -probesize 128M -s 1920x1080 -r 60 -i :0.0 -qscale 0 -vcodec huffyuv -t 00:01:13 "$video.avi" # record the screen losslessly
ffmpeg -hwaccel cuvid -vsync 1 -i "$video.avi" -map 0:0 -c:v:0 hevc_nvenc -crf 23 -preset medium "$video-clean.mp4"

This works just like I expect it to some of the time, but very often it drops a lot of frames (I've seen as many as 10000 frames dropped on occasion)

The gpu is a 1080 TI that's being used just for rendering an X server with a chrome window and recording it, according to nvidia-smi the usage never goes to higher than 50% even in the most extreme cases.

I don't know what else to try, I thought about using a ramdisk to write the file to as it might be an IO problem, but ffmpeg refuses to write to tmpfs (for some reason I can't explain)

question from:https://stackoverflow.com/questions/65925501/get-consistent-60fps-while-recording-x-screen-with-ffmpeg

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Solved it, recording to a tmpfs turned out to be the solution for me, however because I was using the snap version of ffmpeg I couldn't directly write to ram (because of permission issues), so I just compiled ffmpeg myself (needed support for cuda, and since this script runs on an ubuntu-based machine and the apt version of ffmpeg doesn't have access to cuda for some specific encoders I just compiled ffmpeg myself)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...