0

I am trying to record screen using ffmpeg with the following command:

ffmpeg -f x11grab -s 1366x768 -framerate 30 -i :0.0 -c:v libx264 -b:v 1000k out.mp4

which I learned from here.

But I am not able to understand what framerate means in this context.

Here's what I think:

If we were converting a set of images stored in a directory to a video as mentioned here, a framerate of 30 would have meant - 'Display the first 30 images in the first second of the video, the next 30 images in the next second and so on until all the images are used up'.
So far example, if we had 90 images, the length of the resulting video would have been 3 seconds.

In the same fashion, during screencasting, the following should happen:

Supposing that my screen refresh rate is 60 Hz, 60 images per second are being generated and stored in a buffer.
But, since ffmpeg has been given a framerate of 30, it takes the first 30 images (images #1 - #30) from the buffer and produces 1 second of video, then takes images #31 - #60 and produces the next second of video.
That means, during 1 second of recording, 2 seconds of video would be produced.


To test this theory, I ran the following experiment:

I ran a graphical stopwatch on screen and made it run for exactly 10 seconds, while simultanesouly recording the stopwatch going from 1-10.

According to my theory, either the video produced should have been of 20 seconds and shown complete stopwatch count from 1 to 10, or, to keep the video time equal to the recording time, ffmpeg would have generated a video of 10 seconds and shown only half of the stopwatch count from 1 to 5 (The first 30*10 = 300 frames from a total of 600 frames generated by the graphics card during the same time).

But, none of the above two cases happened. Instead, the video's length was 10 seconds and the content was exactly the same as how the screen looked during recording, that is, stopwatch count going from 1 to 10.

I repeated the same experiment using a framerate of 10 instead of 30, and found the same results, that is, the video's length being 10 seconds and the stopwatch count being shown from 1 to 10.

So, what's wrong with my theory ?


The only other theory which I've been able to think of, and which is consistent with my observations is this:

Since, ffmpeg has to record at a framerate of 30 given an input stream of 60 Hz, it skips every other image during video production.
That is, it uses image #1, #3, #5 ... #60 to produce 1 second of video.

But I'm not sure if this is correct.


My system configuration:

  • OS: Ubuntu 16.04

  • ffmpeg version:
    ffmpeg version 2.8.6-1ubuntu2 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 5.3.1 (Ubuntu 5.3.1-11ubuntu1) 20160311 configuration: --prefix=/usr --extra-version=1ubuntu2 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv libavutil 54. 31.100 / 54. 31.100 libavcodec 56. 60.100 / 56. 60.100 libavformat 56. 40.101 / 56. 40.101 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 40.101 / 5. 40.101 libavresample 2. 1. 0 / 2. 1. 0 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 2.101 / 1. 2.101 libpostproc 53. 3.100 / 53. 3.100

  • 1
    Your 2nd theory is right. FFmpeg seeks to preserve temporal relations, so a 60 fps feed configured to receive 30 fps will result in dropping half the frames. – Gyan Jun 10 '16 at 4:20
  • Thanks @Mulvya. Can you tell me one more thing - The two video outputs (with fps 30 and 10) have the same filesize. I understand this might be due to the fact that both the videos have the same bitrate. But, then does that mean that in the 10-fps video, the bits/frame is more and therefore, each frame will be more crisp (more color depth) than the 30-fps one ? – Anmol Singh Jaggi Jun 10 '16 at 8:20
  • In general, yes. But if the bitrate is high enough and the motion is infrequent, you won't notice a big difference. – Gyan Jun 11 '16 at 9:35
  • Since I've got my answer, I want to close the question. Do you want to write the answer or should I do it myself ? – Anmol Singh Jaggi Jun 11 '16 at 9:46
1

FFmpeg is a time-based media processor and as such strives to maintain temporal relation of the input unless instructed otherwise.

The framerate option for the x11grab device sets the grabbing frame rate. If there are fewer or greater frames supplied each second, then ffmpeg will duplicate or drop the difference, respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.