Wiki source code of Video Capture of Computer Screens
Last modified by Drunk Monkey on 2024-10-09 05:32
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
1.1 | 1 | {{box cssClass="floatinginfobox" title="**Contents**"}} |
![]() |
1.3 | 2 | {{toc depth="3" start="2" numbered="true"/}} |
![]() |
1.1 | 3 | {{/box}} |
4 | |||
5 | == Required Programs == | ||
6 | |||
7 | 1. [[VLC Media Player>>https://www.videolan.org/vlc/]] - required for playback of just about any kind of video content you can imagine | ||
![]() |
5.1 | 8 | 1. [[7-zip>>https://www.7-zip.org]] - you will need this to extract the contents of the FFmpeg files, which are stored as a 7z archive. Mac OSX will use [[Keka>>https://www.keka.io/en/]] |
![]() |
1.1 | 9 | 1. [[FFmpeg>>http://ffmpeg.org/download.html]] - the ultimate Swiss Army Knife multitool of multimedia encoding/decoding |
10 | |||
11 | == Installation == | ||
12 | |||
13 | 1. VLC installs are straight forward. Run the installer and you're done. | ||
14 | 1. FFmpeg is a bit more complicated, and it depends on your platform. | ||
15 | |||
![]() |
3.1 | 16 | ---- |
![]() |
1.1 | 17 | |
18 | (% class="row" %) | ||
19 | ((( | ||
![]() |
3.1 | 20 | (% class="col-xs-12 col-xs-6" style="border-right:black solid 1px;" %) |
![]() |
1.1 | 21 | ((( |
![]() |
1.2 | 22 | === Windows === |
![]() |
3.1 | 23 | |
![]() |
5.1 | 24 | 1. Run the VLC installer |
![]() |
27.1 | 25 | |
![]() |
5.1 | 26 | 1. Install 7-zip |
![]() |
27.1 | 27 | |
![]() |
26.1 | 28 | 1. Extract the contents of the FFmpeg zip file into a suitable directory. I going to use C:\Local\ffmpeg\ as my FFmpeg installation location for this example. You should see something similar to this: |
![]() |
27.1 | 29 | [[image:image-20220127221835-1.png]] |
30 | \\The contents of the ffmpeg filder should look like this: | ||
![]() |
18.2 | 31 | [[image:image-20220127225738-2.png]] |
32 | \\Select all the files and move them into the installation directory. That is C:\Local\ffmpeg\ in this example. | ||
33 | [[image:image-20220127225847-3.png]] | ||
![]() |
3.1 | 34 | |
![]() |
18.2 | 35 | 1. Next, add the location of the ffmpeg\bin directory to the system path. This is necessary so you can run the command from the command line from a command shell. |
36 | \\Go to the file explorer, and look in the left hand folder list for "This PC" or "My PC" or whatever it is called on your system. | ||
37 | [[image:image-20220127230601-5.png]] | ||
38 | \\When you find it, right click in it to bring up the local context menu and select Properties | ||
39 | [[image:image-20220127230404-4.png]] | ||
40 | \\In newer versions of Windows, the properties page looks like this: | ||
41 | [[image:image-20220127230803-6.png]] | ||
42 | \\Look for the "Advanced system settings" (right middle in the above screenshot) and click on it | ||
43 | [[image:image-20220127230949-7.png]] | ||
44 | \\Select "Environment Variables" and the following screen will appear | ||
45 | [[image:image-20220127231106-8.png]] | ||
46 | \\In the top half of the User variables section is an entry called "Path". Select it and click on "Edit". Do not edit the path of the System variables section unless you know what you are doing. | ||
47 | [[image:image-20220127231323-9.png]] | ||
48 | \\Click on "New" and add the following "C:\Local\ffmpeg\bin" | ||
49 | [[image:image-20220127231805-12.png]] | ||
50 | \\and then click on the "Move up" button until that new entry appears at the top of the list | ||
51 | [[image:image-20220127231836-13.png]] | ||
52 | \\Click on OK, and ffmpeg will be available for use on the command line. | ||
53 | [[image:image-20220127232109-14.png]] | ||
54 | \\Click on OK to close the Environment Variables settings, and then click on OK to close the System Properties. | ||
![]() |
22.1 | 55 | |
56 | 1. Start a command line window by typing cmd.exe into the search bar and open the Command Prompt | ||
57 | [[image:image-20220127232411-15.png]] | ||
58 | |||
59 | 1. in that command prompt, type in "ffmpeg" and you should see this: | ||
60 | [[image:image-20220127232635-16.png]] | ||
61 | \\If you get an error like this, either you typed in the command incorrectly (as I did in the following example) or you did not configured your user path correctly and you have to go back and correct it | ||
62 | [[image:image-20220127232731-17.png]] | ||
![]() |
22.2 | 63 | \\You are now ready to capture video |
![]() |
18.2 | 64 | ))) |
65 | |||
![]() |
1.1 | 66 | (% class="col-xs-12 col-xs-6" %) |
67 | ((( | ||
![]() |
1.2 | 68 | === Mac OSX === |
![]() |
5.1 | 69 | |
70 | 1. Install VLC | ||
![]() |
28.1 | 71 | |
![]() |
5.1 | 72 | 1. Install Keka |
![]() |
28.1 | 73 | |
74 | 1. Install FFmpeg through the use of [[HomeBrew>>https://brew.sh]] (recommended because of all the other useful things you can install if you like this kind of stuff) or install the statically linked binary version of the [[FFmpeg binaries>>http://ffmpeg.org/download.html]] from [[https:~~/~~/evermeet.cx/ffmpeg/>>https://evermeet.cx/ffmpeg/]]. This file will need to be placed into a directory that's on your path (not yet described how to do) | ||
75 | \\The statically linked installation is going to be faster and easier to do than the homebrew version. | ||
![]() |
1.1 | 76 | ))) |
77 | ))) | ||
78 | |||
![]() |
24.1 | 79 | ---- |
80 | |||
![]() |
24.2 | 81 | == Video Capture == |
![]() |
24.1 | 82 | |
83 | ---- | ||
84 | |||
![]() |
23.1 | 85 | (% class="row" %) |
86 | ((( | ||
87 | (% class="col-xs-12 col-xs-6" style="border-right:black solid 1px;" %) | ||
88 | ((( | ||
![]() |
31.1 | 89 | === Windows === |
![]() |
3.1 | 90 | |
![]() |
22.2 | 91 | Open a command window, and run the following commands: |
92 | |||
93 | >(% style="font-size:14px" %)cd Desktop | ||
94 | >(% style="font-size:14px" %)ffmpeg -f gdigrab -t 6 -draw_mouse 1 -framerate 60 -i desktop -c:v libx264rgb -crf 0 -preset ultrafast screenCapture.mkv | ||
95 | |||
96 | (% style="font-size:14px" %)This will create a video file called "screenCapture.mkv" on your desktop that you can replay using VLC Media Player. | ||
97 | |||
![]() |
28.1 | 98 | (% style="font-size:14px" %)The parameters to the ffmpeg command have the following meanings |
![]() |
22.2 | 99 | |
![]() |
30.1 | 100 | (% class="grid min" %) |
![]() |
22.2 | 101 | |-f gdigrab|gdigrab is the windows framebuffer, where the screen is stored |
![]() |
28.2 | 102 | |-t 6|capture 6 seconds of video and exit. 3600 = 1 hour, 14400 = 4 hours. If you omit this parameter, the capture will continue until you press [Control C] to gracefully tell ffmpeg to stop |
![]() |
28.1 | 103 | |(% style="font-size:14px" %)-framerate 60|if you want to see the candles paint second by second, you should have a framerate of at least 60. Technically speaking, you actually need 120, but let's not get too crazy. |
![]() |
22.2 | 104 | |-draw_mouse 1|capture the mouse pointer |
105 | |-i desktop|capture the entire desktop - remember to maximize your window | ||
106 | |-c:v libx264rgb|this video encoder will preserve the rgb color values losslessly | ||
107 | |-crf 0|lossless compression | ||
108 | |-preset ultrafast|save the data as quickly as possible, don't waste too much time compressing the data | ||
![]() |
24.3 | 109 | |
110 | If you want to save the for long term storage, you can losslessly compress the file even further with the following command | ||
111 | |||
112 | >(% style="font-size:14px" %)fmpeg -i screenCapture.mkv -c:v libx264rgb -crf 0 -preset veryslow screenCaptureS.mkv | ||
113 | |||
![]() |
25.1 | 114 | It'll take a while, but it will create a video file that should be less than half the size of the original. |
![]() |
23.1 | 115 | ))) |
![]() |
22.2 | 116 | |
![]() |
23.1 | 117 | (% class="col-xs-12 col-xs-6" %) |
118 | ((( | ||
![]() |
31.1 | 119 | === Mac OSX === |
![]() |
24.3 | 120 | |
![]() |
28.1 | 121 | Open a terminal window and run the following commands: |
![]() |
24.3 | 122 | |
![]() |
33.1 | 123 | >(% style="font-size:14px" %)cd ~~/Desktop |
124 | >(% style="font-size:14px" %)ffmpeg -f avfoundation -t 6 -pixel_format 0rgb -capture_cursor 1 -capture_mouse_clicks 1 -framerate 60 -i "1:" -filter:v "format=yuv444p" -c:v libx265 -crf 0 -preset ultrafast screenCapture.mkv | ||
![]() |
28.1 | 125 | |
126 | (% style="font-size:14px" %)This will create a video file called "screenCapture.mkv" on your Desktop that you can replay using VLC Media Player. | ||
127 | |||
128 | (% style="font-size:14px" %)The parameters to the ffmpeg command have the following meanings | ||
129 | |||
![]() |
31.1 | 130 | (% class="lined min" %) |
![]() |
28.1 | 131 | |-f avfoundation|gdigrab is the windows framebuffer, where the screen is stored |
![]() |
28.2 | 132 | |-t 6|capture 6 seconds of video and exit. 3600 = 1 hour, 14400 = 4 hours. If you omit this parameter, the capture will continue until you press [Control C] to gracefully tell ffmpeg to stop |
![]() |
28.1 | 133 | |(% style="font-size:14px" %)-framerate 60|if you want to see the candles paint second by second, you should have a framerate of at least 60. Technically speaking, you actually need 120, but let's not get too crazy. |
134 | |-pixel_format 0rgb|get the data as RGB colors instead of some bizzzare color model | ||
135 | |-capture_cursor 1|capture the mouse pointer | ||
136 | |-capture_mouse_clicks 1|and capture the clicks with an onscreen visual notification | ||
![]() |
33.1 | 137 | |-i "1:" |
138 | \\\\-i title="window title"|((( | ||
![]() |
36.1 | 139 | capture the first screen. Not really important unless you have multiple screens and you are not capturing the primary screen. Use '##ffmpeg -f avfoundation -list_devices true -i ""##' to list the capturable devices on your computer |
![]() |
33.1 | 140 | \\to capture a particular window |
141 | ))) | ||
![]() |
28.1 | 142 | |-filter:v "format=yuv444p"|transform the input colors into this color format, which is fairly quick when converting from RGB and without too much color shifting |
143 | (I'm still looking to improve upon this - the windows encoding has an exact RGB color modelling which means no color shift) | ||
144 | |-c:v libx265|encode the video using H.265 compression. It makes for smaller videos without consuming too much processing time | ||
145 | |-crf 0|lossless compression | ||
146 | |-preset ultrafast|save the data as quickly as possible, don't waste too much time compressing the data. | ||
147 | |||
148 | There is no point in trying to compress this video any further with these parameters. Further compression will require a lot of time and cpu power to see any further gain. | ||
![]() |
24.2 | 149 | ))) |
150 | ))) | ||
![]() |
32.1 | 151 | |
![]() |
32.2 | 152 | == Audio Capture == |
![]() |
32.1 | 153 | |
![]() |
32.2 | 154 | === Windows === |
155 | |||
156 | === Mac OSX === | ||
157 | |||
158 | |||
159 | == References == | ||
160 | |||
![]() |
32.1 | 161 | FFmpeg documentation: |
162 | |||
163 | * [[https:~~/~~/ffmpeg.org/documentation.html>>https://ffmpeg.org/documentation.html]] | ||
164 | |||
165 | Lossless capture: | ||
166 | |||
167 | * [[https:~~/~~/video.stackexchange.com/questions/25034/lossless-capture-with-ffmpeg>>https://video.stackexchange.com/questions/25034/lossless-capture-with-ffmpeg]] | ||
168 | * [[https:~~/~~/video.stackexchange.com/questions/8305/lossless-screen-recording-software>>https://video.stackexchange.com/questions/8305/lossless-screen-recording-software]] | ||
169 | * [[https:~~/~~/trac.ffmpeg.org/wiki/Capture/Desktop>>https://trac.ffmpeg.org/wiki/Capture/Desktop]] | ||
170 | |||
![]() |
33.1 | 171 | Video editing programs |
172 | |||
173 | * black magic davinci resolve | ||
174 | * kdenlive | ||
175 | * shotcut | ||
176 | |||
![]() |
34.1 | 177 | == Tips == |
178 | |||
179 | Screen capture portion of a screen | ||
180 | |||
181 | >(% style="font-size:14px" %)ffmpeg -y -f avfoundation -t 6 -pixel_format 0rgb -capture_cursor 1 -capture_mouse_clicks 1 -framerate 60 -i "1:" -filter:v "format=yuv444p" -filter:v "crop=1920:1080:320:180" -c:v libx265 -crf 0 -preset ultrafast screenCapture.mkv | ||
182 | |||
![]() |
35.1 | 183 | (% style="font-size:14px" %)extract audio |
184 | |||
185 | (% style="font-size:14px" %)ffprobe <videofile> to determine the audio format | ||
186 | |||
187 | (% style="font-size:14px" %)ffmpeg -i <filename> -y -ss 01:50:47.0 -t 0:02:03 -vn -c:a copy <outputaudio>.aac (assuming audio is aac as determined by ffprobe above) | ||
188 | |||
189 | |||
![]() |
32.1 | 190 |