NixNet/_posts/2018-08-12-lossless-screen-...

24 lines
2.1 KiB
Markdown
Raw Normal View History

2018-12-14 05:47:01 +00:00
---
layout: post
2018-12-15 05:52:02 +00:00
title: Lossless screen recording
2018-12-16 18:54:24 +00:00
subtitle: Never waste resources with OBS again
2018-12-16 18:53:02 +00:00
description: Recording your screen (or monitor(s)) with ffmpeg for a high-quality lossless video that uses very little system resources
2018-12-15 05:52:02 +00:00
categories: minimalism
cover: /assets/ffmpeg-lossless.png
2018-12-15 00:56:04 +00:00
date: 2018-08-12 17:15:20
2018-12-14 05:47:01 +00:00
---
I've been trying off and on for the past few weeks to figure out how to record my 1920x1080 monitor. The recording is going to be some music videos for a friend. Originally, it was just going to be a single background image for the whole video then I had the idea of using [cava](https://github.com/karlstav/cava) in a transparent terminal on top of the background. This didn't work at all because it actually kept freezing when I tried to record it. So I tried switching to [ncmpcpp](http://ncmpcpp.rybczak.net/) visualiser. This still had horrible lag. So I've been puzzling over how to use ffmpeg to *losslessly* record my second monitor. I finally figured it out and have pasted the command below.
`ffmpeg -video_size 1920x1080 -framerate 30 -f x11grab -draw_mouse 0 -i :0.0+1366,0 -c:v libx264 -crf 0 -preset ultrafast output.mkv`
This is the exact command I used; I'll modify it so you know what to edit for your use-case 😉
`ffmpeg -video_size <target-resolution> -framerate 30 -f x11grab -i :0.0+<width-of-unused-monitor>,0 -c:v libx264 -crf 0 -preset ultrafast <filename>.mkv`
If you do *not* want the cursor recorded, add `-draw_mouse 0` directly after `x11grab` like I did in the first command.
My video was 470mb for a ~13 minute video. If you're going to archive the recording or are concerned about file size, re-encode it losslessly but with a slower preset. As the initial recording was lossless and the re-encode is lossless too, there will be no absolutely no loss is quality . . . *anywhere*. I also highly recommend using this as a general purpose screen recorder if you have a low-end system. Previously, I was using OBS and the lag in the video was incredible but with ffmpeg, it's smooth as butter. The command for re-encoding is below:
`ffmpeg -i output.mkv -c:v libx264 -crf 0 -preset veryslow output-smaller.mkv`
![](/assets/ffmpeg-lossless.gif)