Compress Native System Screen Recording
Problem Statement
The native screen recording in Windows/MacOS has very high quality, so that the video are usually too large to share with others. For example, a 2-hour screen recording on MacOS consumes 14 GB memory!
However, we noticed that the screen recording from zoom/tencent meeting is very light-weight. A 2-hour screen recording costs only hundreds of megabytes!
So, if we want to share the screen recording from native system to others, can we convert it to the one like the zoom? It has smaller file size and the video is quality is enough for watching.
Observation & Analysis
We get two videos, from Tencent Meeting (tencent.mp4
) and Windows Native recording (windows.mp4
) respectively:
tencent.mp4 |
windows.mp4 |
|
---|---|---|
Duration | 6.7s | 11.6s |
File Size | 261KB | 11675KB |
We found that the size of tencent.mp4
is far smaller (~20x) than the windows.mp4
! Let’s analysis some details by the ffprobe
provided by ffmpeg
:
1 | # Description: Get the information of the video file using ffprobe |
And here are some key observations comparison:
- Codec Profile:
tencent.mp4
uses the H.264 High Profile, which is suitable for high resolution and high compression efficiency.windows.mp4
uses the H.264 Main Profile, which typically has slightly lower compression efficiency compared to the High Profile.
- Frame Rate:
tencent.mp4
has a relatively low frame rate (approximately 15 fps), which helps to reduce file size.windows.mp4
has a higher frame rate (60 fps), which significantly increases the file size.
- Bit Rate:
tencent.mp4
has a very low bit rate (184243 bps), which greatly reduces file size but may affect video quality.windows.mp4
has a very high bit rate (7457076 bps), which ensures higher video quality but also results in a much larger file size.
- Audio Settings:
tencent.mp4
has mono audio and a lower sampling rate (32000 Hz), which helps to reduce file size.windows.mp4
has stereo audio and a higher sampling rate (48000 Hz), which increases file size.
Solution
From the analysis above, we come up the plan to reduce the video file size. We use ffmpeg
to convert the videos. The following Python script helps making the ffmpeg
commands:
1 | # Description: This script compresses a video file using ffmpeg with some preset parameters. |
The output command example:
1 | ffmpeg -i input.mp4 -vcodec libx264 -profile:v high -crf 23 -preset fast -b:v 184k -r 15 -pix_fmt yuv420p -acodec aac -b:a 128k -ar 32000 -ac 1 compressed_output.mp4 |
To convert the file, we apply the high profile, a low crf, a low bitrate and framerate. You may export the video and check whether the video is over-compressed.
Apple Silicon Acceleration
For Apple Silicon users, we may apply the Apple’s own H264 encoding library for acceleration. The command may look like this:
1 | # Apple's H264 encoder |
The output command example:
1 | ffmpeg -i input.mp4 -vf "scale=1920:-2,fps=15" -c:v h264_videotoolbox -q:v 10 -acodec copy compressed_output.mp4 |