Tutorial: Screencapping With FFMPEG

The last couple of years I’ve been using ffmpeg command line to cap HD and Bluray. Ffmpeg is the program that many popular freeware video converters use to convert videos. There are also lots of GUIs for ffmpeg, but I haven’t one that offers output as images, only video. So that’s why command line.

Examples what what I’ve capped with ffmpeg: Star Trek TNG, DSC, ENT and PIC HD and Blurays. Zahn McClarnon Barkskins, Longmire etc. And all other HD/Bluray caps I’ve made since about 2017.

This is not a suitable method for capping DVDs because those need deinterlacing and resizing, at least not with these particular ffmpeg codes. I use DGIndex, Avisynth, QTGMC and VirtualDub to cap all DVDs.

Install ffmpeg

I have both Windows 10 and Linux Mint running on my laptop, and I have installed ffmpeg on both so it doesn’t matter which side I’m on – I can always cap and the quality of the caps is the same. I used the Wikihow tutorial with pictures originally to learn how to install ffmpeg on Windows, and I recommend using it if you’re on Windows as well. You should periodically update ffmepg by deleting it and then installing a new version.

I’ve never owned a Mac, but the official ffmpeg site has a tutorial to get your started. You might also google for instructions.

Linux Mint, Ubuntu – preferably use either the Package Manager or Software Manager to install ffmpeg, but first check the version on offer. You should install the newest possible version of ffmpeg, and then update periodically. The good thing about Package Manager/Software Manage is that it’ll upgrade ffmpeg along with other software when upgrades are available.

  1. For Windows using this Wikihow tutorial with pictures. Do all parts, including installing, adding environment variable and testing ffmpeg.
  2. MacOS
  3. Linux Mint or Ubuntu – first check if your package manager/software installer offers ffmpeg as one of the installable programs. Alternatively you can use a repository (such as this for Linux Mint 19) to install it.

Once you’ve installed ffmpeg (and added it to environvariables in Windows), you can start capping.

Making Screencaps

Open a Notepad and some other simple text editor, and copy/paste in:

ffmpeg -i "videoname.mkv" -vf "select='not(mod(n\,17))'" -vsync 0 -q:v 1 -vcodec bmp "C:\temp\temp\MovieName_%5d.bmp"

Change videoname.mkv, 17 and C:\temp\temp\MovieName_%5d.bmp as needed. Then open command line window in your video’s directory and copy/paste the code into it, and press enter. Ffmpeg should start running.

Here’s what all that code means:

  • ffmpeg = calls ffmpeg program
  • -i = tells ffmpeg that next bit is the input file DO NOT CHANGE THIS!
  • “videoname.mkv” = The name of your video file. Change as needed. You can also use a full path here such as “D:/Videos/somevideofile.mkv”
  • -vf = needed for crop, select etc filters to work DO NOT CHANGE THIS!
  • – “select=’not(mod(n\,17))'” = selects every 17th frame and screencaps it. CHANGE ONLY THE NUMBER 17 AS NEEDED! 17 produces about 3800-4000 screencaps per an hour episode. Reduce or increase the number as needed.
  • -vsync 0 = necessary to handle frames properly DO NOT CHANGE THIS!
  • -q:v 1 = video quality (highest) DO NOT CHANGE THIS!
  • -vcodec bmp = specifies the output codec, in this case image format bmp. Change this as needed. I use bmp or png. jpg produces bad quality pictures so I never use that.
  • “C:\temp\temp\MovieName_%5d.bmp” = output directory and filename. C:\temp\temp is the directory – change as needed, and MovieName_%5d.bmp is the filename. MovieName can be changes as desired (example: extant_StarTrek_DSC_1x01_Pilot.%5d.bmp
  • %5d.bmp = %5d specifies how many characters the filename shall have, in this case 5 (00001.bmp) and bmp the file format. If you previously chose png or jpg as our output format, change also here accordingly.

Additional useful commands

  • q = When you need to stop ffmpeg in the middle of capping, press “q” on the keyboard.
  • cropdetect=24:16:0″ = when you have a widescreen video/wide black bars on top and bottom), or a 4:3 video (wide black bars on side) do a cropdetect and output a dummy in the same directory the video file is in. Delete the dummy once done.
ffmpeg -ss 600 -i "videofile.mkv" -vf "cropdetect=24:16:0" "dummy.mkv"
let it run for 10 or 20 seconds and then press q. Copy the bit from the code that ran that starts with "crop=" such as "crop=1920:944:0:8"

Now paste the crop bit you copied in previously to the ffmpeg capping code before the select filter. Example:

ffmpeg -i "videoname.mkv" -vf "crop=1920:944:0:8,select='not(mod(n\,17))'" -vsync 0 -q:v 1 -vcodec bmp "C:\temp\temp\MovieName_%5d.bmp"

Let ffmpeg make about a hundred caps and then check them. If everything looks good, let it go on. If not, press “g” on keyboard and adjust the code as needed.

  • -ss 600 = starts processing 10 minutes (600 seconds) in. Useful when at the start there are studio logos, or opening credits are different aspect ratio than the actual movie/episode. Change 600 as required.

Convert To Jpg

Use your favorite image processor/viewer to convert the bmps/pngs to jpg. I use one called XnView Classic, the Batch Processing feature, jpg quality at Best (80-91). Be careful not the compress too much (look at the dark screencaps or dark parts of screencaps, there may not be any blockiness or “hairyness”.)

Notes & Tips

  • Save the ffmpeg code that works for you in simple txt file, that way you don’t always have to remember what it.
  • Always use the same output directory if possible, that way you don’t have to change directory name in the code, only the videofile name.
  • When you use bmp or png as the output, you need a lot of hard disk space to save the resulting screencaps; for an hour tv episode like 15-20GB, and a movie twice or more that, depeding on the length of the movie.
  • Open the command line window in the same directory as your video file is, so you don’t have to specify full path to the video file, only the name.
  • How fast ffmpeg processes the video file depends on how powerful your system is. Mine caps an hour episode in about 8-10 minutes.
  • If may or may not have to use quotes (“blaablaaa”) to surround filename.mkv and the output directory/filename. Depends on whether your systemp understand blank spaces in filenames and directory names or not.
  • You can do other stuff while ffmpeg runs, but I wouldn’t run any processing heavy programs at the same time because that will slow both ffmpeg and the other program down – depends again on how powerful your system is! I can browse internet okay, listen to music and write in Notepad++ okay with this laptop, but don’t like to use Photoshop or convert videos in another program at the same time as an example.


Last updated: July 3, 2020
Created: July3, 2020