9 comments on “Recording the Screen of the Windows Desktop Using FFmpeg

  1. Dear Jordan,
    this is a great post.

    Is there a way to define portion of screen to be captured.
    Like X,Y starting point, WIDTH and HEIGHT in pixels.
    I woul like to capture a video from windows application running in a form.

    Best regards,

    • I know this is possible on Linux / Unix. I’m not sure about Windows. I will do some investigating.

      — Edit —

      It is probably dependent on the codec / encoder used.

    • I just remembered that I wrote a batch file to do this. You use the “crop” video filter but you will need a 3rd party utility to find the window’s dimensions & position. I’ve used one before but I can’t think of what it was called. Unfortunately, this method only captures a section of the screen so you won’t be able to move the window around.

      The format of the crop video filter is: -vf crop=”w:h:x:y”

      So, if you wanted to capture a window that was 450px by 300px & the upper left-hand corner was located at position 101,115 you would use the filter like this: -vf crop=”450:300:101,115″

      The downfall to using this method is that FFmpeg still processes the entire screen which uses up more memory & system resources. There may be a better way to do it. Here is a reference video for how to achieve what you want on a Linux system. It may help: https://www.youtube.com/watch?v=R3elvGxZyTo

  2. Pingback: Screen (and Audio) capture with Ffmpeg, windows 7 command line How To | oNym

  3. Pingback: Recording the Screen of an X11 (Unix/Linux/BSD) Desktop Using FFmpeg | AntumDeluge

  4. As an FFMPEG novice, the breakdown you gave on how to record screencasts really helps me to understand what the code does. Thank you!
    I am still struggling with a few elements.
    • How to obtain stereo audio instead of mono (ac 1/2?)
    • How to set the aspect ratio to 1080 x 1920
    • For now video container format .mp4 won’t work only .mov

    I’m trying to get an HD h264 .mov file hence the use of libx264

    My code:
    ffmpeg -rtbufsize 1500M -f dshow -r 25 -i video=”screen-capture-recorder”:audio=”virtual-audio-capturer” -crf 0 -vcodec libx264 -x264opts keyint=1 -acodec pcm_s16le -ac 1 -ar 44100 “test 2.mov”

    • As far as video containers go, I recommend using .mkv, a.k.a. Matroska ( https://en.wikipedia.org/wiki/Matroska ). To my understanding, it is the most versatile of all the current containers & supports the most video, audio, & even subtitle formats. If you want to use .mp4 container, it is most commonly used for AVC/H264 video (libx264) & AAC audio. I believe it also support Xvid video & MP3 audio. You can always capture into the .mkv container than convert your video later to a format support by .mp4.

      About the aspect ratio, I think what you are referring to is known as the “Display Aspect Ratio” (DAR). There is also “Pixel Aspect Ratio” (PAR) & “Storage Aspect Ratio”. I don’t know much about the differences between them, but you can read up about aspect ratios on Wikipedia ( https://en.wikipedia.org/wiki/Pixel_aspect_ratio ).

      It has been a while since I messed with FFmpeg screen recording, & I am a bit rusty. I don’t recall at the moment exactly the details of setting aspect ratio. But check out these answers given on StackOverflow: https://stackoverflow.com/questions/24087249/ffmpeg-change-resolution-of-the-video-with-aspect-ratio

      According to that link, I believe to set the Display Aspect Ratio you either want to use the “-aspect” option before the video encoder (or perhaps after) or the “-setdar” video filter. You can use the format “W:H”. I believe the ratio for 1080×1920 is 9:16 or (1:1.77) ( https://en.wikipedia.org/wiki/16:9 ).

      “-aspect 9:16 -vcodec libx264”


      “-vcodec libx264 -vf setdar=9:16”

      According to the StackOverflow link, it sounds like if “setdar” doesn’t work, try “setsar” which sets “Storage Aspect Ratio”.

      However, the thought has crossed my mind that you simply want your video dimensions to be 1080×1920. If that is the case, I believe the video filter “scale” is what you want to use:

      “-vcodec libx264 -vf scale=1080×1920”

      You can optionally set aspect ratio filters simultaneously:

      “-vcodec libx264 -vf scale=1080×1920,setdar=9:16”

      P.S. Sorry for the late reply & I hope this helps if you haven’t already found a solution.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s