How to Record Video for Your Selenium Tests Using FFmpeg

How to Record Video for Your Selenium Tests Using FFmpeg

Video for Your Selenium Tests Using FFmpeg

Using screenshots for your Selenium tests when they fail is cool, but there are some limitations. For example, it’s hard to know exactly what happened before a failure occurred using a snapshot. In my case, the biggest issue is that our applications sometimes have random modal popups appear that cause the Selenium image to be just a black screen — at least that’s my theory.

The problem is that the image only shows the browser’s viewport, not the full desktop. Rather than a screenshot, I feel that having a video recording would better help me to debug what is actually happening.


My solution is to have our CI system start the recording before our test run, then stop it after the entire test scenario is completed.

Since our test log files are time stamped, we can navigate to that time in the video recording to see what was going on. This method is kind of crude, since it will record nonstop, but it’s a good first step. 

To do this we choose FFmpeg. (You could, of course, bypass all this by simply using Sauce Labs, which has a much more advanced video recording option.)

FFmpeg is an open-source, command line video/encoding software utility that allows you to record video and audio of your desktop. The first issue I found with it is that it’s not very clear how to go about installing FFmpeg, and what commands you need to use to create a recording. So, I decided to document what I had to do to get it working on my machine and share it with you.

What you’ll need for recording Selenium test runs:

First, install FFmpeg

  • To install, navigate to
  • Select the static version that you need
  • Extract to a location on your hard drive. (I chose C:\ffmpeg)
  • Next, go to Start>Run and enter sysdm.cpl
  • Under the System Properties dialog, click on the Advanced tab
  • Next, click on the Environment Variables
  • Under the User Variables section, click on the . button
  • Under the New User Variable dialog, enter:
  •    Variable name: path
  •    Variable value: c:\ffmpeg\bin (or the path the where you unzipped ffmpeg to)
  • To verify that ffmpeg is installed, go to Start>Run>cmd
  • In the CMD window, type ffmpeg – version
  • You should see something like this:
  • Next, while you’re still at the command line, type the following to see what video devices, if any, you currently have installed:
 ffmpeg –list_devices true –f dshow –i dummy


Notice that when I do this I get the error message Could not enumerate video devices (or none found).

This means that my machine doesn’t currently have any DirectShow video devices installed. FFmpeg needs a video device to use in order to record.

Install Screen_Capture_Recorder

The screen capture tool I chose was screen_capture_recorder, because it’s a free, open-source “screen capture” device. If you got the same video device error I did, you can easily install a valid video device by following these steps:

     ffmpeg –list_devices true –f dshow –i dummy

You should now see a valid video device listed:


Cool. Now it’s time to record!

Command to record a screen capture using ffmeg

  • Navigate back to a command line window and to the ffmpeg\bin directory and enter the following:
 ffmpeg -f dshow -i video="screen-capture-recorder" -r 30 -vcodec mpeg4 -vtag xvid -qscale:v 0 bddrun.mkv
  • Press Q to stop recording

How to view the recording?

Notice how ffmpeg saves the recording as a .mkv file. In order to view it, you’ll need to first convert to an mp4 file.

  • Open a command line window
  • Navigate to the location of your .mkv file. Mine is under C:\ffmpeg\bin
  • Enter the following:
     ffmpeg –I name_of_yourFile.mkv –codec copy bddTestRun.mp4
  • Navigate to the directory where you converted your file. You should now see a .mp4 version of your recording:
  • Double click to play it back


Make sure your cmd.exe screen buffer size has a wide enough width.


Make a recording batch file

Instead of always having to type this command, whenever you want to record, you can create a batch file that contains the ffmpeg record command by following these steps:

  • Open up Notepad
  • Enter the following:
        ffmpeg -f dshow -i video="screen-capture-recorder" -r 30 -threads 0 bddrun.mkv
  • Save as record.bat
Tej - September 30, 2015

Hi Joe,

We do recording using MonteMedia Library,, Is there any advantage of doing this with FFmpeg? or is this just an alternative


    Joe Colantonio - September 30, 2015

    It depends on your needs. I would say this is an alternative but on the MonteMedia library site it says that its an experimental library for my personal studies! Because of this I choose FFmpeg become it seemed like a more mature solution. But go with what works for you :)

Conrad Braam - October 2, 2015

Damn, beaten to it. I always suspected this was easy to do using ffmpeg. Thanks for the legwork all done for us here Joe!

    Joe Colantonio - October 7, 2015

    Thanks Conrad!

Automate the Planet - October 4, 2015

[…] with Neo4j using C# – Andreas Kollegger Advanced Locator Strategies – Isaac Murchie How to Record Video for Your Selenium Tests Using FFmpeg – Joe Colantonio The True ROI of Test Automation – (Abstracta) How Software […]

Mohan - November 26, 2015

Hi Joe,

Will this “ffmpeg” work on Linux environment? We are running headless selenium automation scripts hosted on jenkins in Linux OS but I am not sure how to record the execution with “ffmpeg” + “screen_capture_recorder” !

Narendra - April 21, 2017

Does this capture the operations performed on headless browser like phantomjs?

    Joe Colantonio - April 21, 2017

    Not sure – it’s a headless browser so what would there be to see?

John Stewart - August 10, 2018

Is there a thread safe method that will work on Selenium Grid? All the solutions I have looked at for C# Selenium don’t work on Grid.

Click here to add a comment

Leave a comment: