Desktop Screen capture Script with Ffmpeg for windows 7 (with Audio)

Hello,
I’ve found a lot of interesting and useful posts on this subject.
Too bad… I just needed a simple script to capture my screen (video and audio) and I didn’t find any…
Now, let’s see what I did about that ! A script built around 3 great and free tools.
Thanks to the developpers ! The links are in the next section.

1- The setup : download and install
– Ffmpeg

http://ffmpeg.zeranoe.com/builds/
to download ffmpeg-20141116-git-ce80f9f-win64-static (based on your OS)

-Virtual-audio-capture-grabber

virtual-audio-capture-grabber-device-master.zip from
https://github.com/rdp/virtual-audio-capture-grabber-device.
click on the download ZIP link on the bottom right (saying that just in case, there’re so many links on this page).

– UScreenCapture(x64).zip

from http://www.umediaserver.net/components/index.html (based on your OS)
In my example, FFmpeg installation folder is : C:\Program Files\ffmpeg\bin
(Shall be edited to match your installation).

2- Script (Batch) for Windows

Best saved in a .bat file, in a separate folder. Something like FfmpegScreenNAudioCapture.bat for example.
(<<do not include>> start)

echo off
 del NULL && del *.log && del *.mbtree
 for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
 set datetime=%datetime:~0,8%-%datetime:~8,6%
 rem "C:\Program Files\ffmpeg\bin\ffmpeg" -list_devices true -f dshow -i dummy
 SET FFMPEG=C:\Program Files\ffmpeg\bin\ffmpeg
 set A=raw.avi
 "%FFMPEG%" -f dshow -framerate 25 -i video="UScreenCapture" -f dshow -i audio="virtual-audio-capturer" -r 25 -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_alaw -ab 128k %a% && "%FFMPEG%" -y -i %a% -c:v libx264 -preset medium -b:v 555k -pass 1 -acodec libvo_aacenc -b:a 128k -f mp4 NULL && "%FFMPEG%" -i %A% -c:v libx264 -preset medium -b:v 555k -pass 2 -acodec libvo_aacenc -b:a 128k output%datetime%.mp4 && del raw.avi && del NULL && del *.log && del *.mbtree

(>>do not include>> stop)

3- Comments

echo off
for /f « tokens=2 delims== » %%I in (‘wmic os get localdatetime /format:list’) do set datetime=%%I
set datetime=%datetime:~0,8%-%datetime:~8,6%
>> time and date gathering later used in the file name.

rem « C:\Program Files\ffmpeg\bin\ffmpeg » -list_devices true -f dshow -i dummy
>> just to remember how I found the name of the video and audio capture devices used in this script. (copy and use in the command line to find yours and edit in the following)

SET FFMPEG=C:\Program Files\ffmpeg\bin\ffmpeg
set A=raw.avi
« %FFMPEG% » -f dshow -framerate 25 -i video= »UScreenCapture » -f dshow -i audio= »virtual-audio-capturer » -r 25 -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_alaw -ab 128k %a% && « %FFMPEG% » -y -i %a% -c:v libx264 -preset medium -b:v 555k -pass 1 -acodec libvo_aacenc -b:a 128k -f mp4 NULL && « %FFMPEG% » -i %A% -c:v libx264 -preset medium -b:v 555k -pass 2 -acodec libvo_aacenc -b:a 128k output%datetime%.mp4 && del raw.avi && del NULL && del *.log && del *.mbtree
>> a few variables and things that might be edited:
FFMPEG to set the installation path of ffmpeg.exe
A to set the name of the temporary video+audio file
video= »UScreenCapture » where « UScreenCapture » is the video capture device
audio= »virtual-audio-capturer » where « virtual-audio-capturer » is the audio capture device

And everything else,
>> instructions and parameters used by Ffmpeg to capture and compress in a two pass sequence the video (and audio) to get x264/acc mp4 file.

del raw.avi && del NULL && del *.log && del *.mbtree
>> Cleaning up. Needed to make sure everything will be ok next time we run the script.

4- How to use the script ?

Double click the .bat to run the script.
Press « Q » to stop the capture and wait until compression’s done.
Then check the output file (named output*.mp4) with your video player.
There’s room for improvment. Feel free to post yours =)
Enjoy !

Sources I was happy to find about this little project, thx !

About the same thing, other choices (AntumDeluge)
Stream your Windows desktop using ffmpeg, same thing -other choices (no sound)

About the date and time in a filename

Allow/Block/Check Connection with windows 7 Scripts

3 scripts (Window’s french localization) to make sure that the data received by or sent from a computer is routed through the proxy as intended (mainly to prevent unwanted ip address detection when using a torrent application).

1- When the proxy’s up, close the main connection
netsh interface ip delete dns "Connexion au r‚seau local" all
 route delete 0.0.0.0 192.168.xxx.yyy
 ipconfig /flushdns
 rem netstat -R
 TIMEOUT /T -1
2- When the proxy’s down, open the main connection
ipconfig /flushdns
 netsh interface ip show dns
 netsh interface show interface
 netsh interface ip set address name="Connexion au r‚seau local" static 192.168.xxx.yyy 255.255.255.0 192.168.xxx.zzz 1
 netsh interface IP set dns "Connexion au r‚seau local" static 8.8.8.8 register=none
 netsh interface IP add dns "Connexion au r‚seau local" 8.8.4.4
 timeout -1
3- Check your internet connection and reboot if internet is unreachable
@ECHO OFF
Rem -----------------------------------
 :: popup box's name
 TITLE Test la connexion %USERNAME%
 :DEBUT
 CLS
Rem -----------------------------------
 :: Ping google.fr for 5 secondes
 ECHO Test la connexion...
 PING www.google.fr -n 6 > NUL
Rem -----------------------------------
 :: if errorlevel is 0 then everything's fine
 IF %ERRORLEVEL% == 0 (
 CLS
 ECHO Informations :
 ECHO Site - www.google.fr
 ECHO Etats - [OK]
 ECHO Internet - [OUI]
 TIMEOUT /T 600
 GOTO :DEBUT
 )
Rem -----------------------------------
 :: if errorlevel 1 then the connection's lost
 IF %ERRORLEVEL% == 1 (
 CLS
 ECHO Informations :
 ECHO Site - www.google.fr
 ECHO Etats - [NUL]
 ECHO Internet - [NON]
REM computer shutdown
 shutdown -s -f -t 18
)