Using ffmpeg to record screencasts compatible with Vimeo


Summary:


This command breakdown explains the ffmpeg command specific to screen captures using h.264 and mp3 lame.

This command line procedure captures your left hand screen using h.264 high quality capture settings. Your audio is encoded in mp3, and is captured in 320mb/s 44100 khz audio from your default laptop audio mic, or from a headset with a mic jack.

Prerequisites:

Set Default Monitor:


  1. Open gnome-display-properties (System > Preferences > Monitors)
  2. Drag the screen you want to capture to be on the left.
  3. Click the left monitor in the dialog.
  4. Write down the resolution displayed. This is required in the command line procedure.
  5. Click Set As Default.
This now sets the record target display as 0.0, or DEFAULT.

Get Packages:

Install Codecs from RPM Fusion Non-free repo
  • Install the @rpmfusion-nonfree repo
  • sudo yum install ffmpeg lame-devel
Install Codecs from RPM Fusion Free repo
  • sudo yum install h264enc x264 x264-devel

Background:


The ffmpeg command is broken down into the following primary parts:
  • input
  • output (encode)
  • output container (filename).

To record your desktop, you require two input sources to be configured:
  • Audio from your laptop mic, USB headset, or 3.5 minijack microphone/headset
  • Video from the desktop of your computer.

Input

Audio Input Parameters

  • -f alsa (specify an input format for alsa audio)
  • -i plughw:0,0 (specify the input type for the default internal sound card (mic pickup in laptop, or if you are using a mic connected to the mic jack such as the one for the Logitech H230)
    NOTE:
    • If you are using a USB headset or mic, plug in the device and run “cat /proc/asound/cards”
    • You will get a listing of plugged in sound cards.
    • change “plughw:0,0, to plughw:[n],0. Where [n] corresponds to the sound device you just plugged in.

Video Input Parameters

  • -f x11grab (specify an input format of X11 Screen Capture)
  • -s 1680x1050 (specify screen’s resolution. Note there are NO SPACES in resolution)
  • -r 24 (specify a framerate of 24 fps)
  • -b 100k (specifies the framerate capture. Although Vimeo recommend bitrate to be 5000, ffmpeg doesn’t
  • -bf 4 (specify the MPEG B-frame type you want to capture is for MPEG-4. Other options are BF 1 for MPEG-1 and BF 2 for MPEG 2). You are recording to MP4 format, so select MP4 to match).
  • -g 15 (specify “Groups of Pictures” to have PAL compression [NTSC is 16])
  • -i :0.0+0,0 (0.0 specifies the $DEFAULT (system default) monitor display. The second set of numbers after the + specify the offset value from the left-hand display. So if you want to capture the second screen, and the L/H monitor runs 1680x1050, the offset value is 1680). The setting as specified captures the left screen.

CRUCIAL: -s and -r *must* appear before -i on the command line. You are passing the frame rate and screen resolution *to* the display and capture area. Place it after -i and you are specifying these values for the *next* input format.

Output

ffmpeg output properties are set using codecs and their specific settings. You need settings for both Audio and Video.

Specify the Output (encode) properties in the order you specified the input types:

Audio Output Parameters

  • -acodec libmp3lame (specifies that you will encode using mp3 libraries. These encode fine when pushed to Vimeo.)
  • -ar 44100 (specifies the audio frequency is 44100 khz, which is the Vimeo maximum)
  • -ab 320k (specifies the audio bitrate is 320kbps, which is the Vimeo maximum)

Video Output Parameters


  • -vcodec libx264 (specifies the h.264 codec)
  • -vpre lossless_fast (specifies lossless fast encoding is used. You don’t need to use lossless_medium or lossless_high to get better quality.

Output Container

Finally, the output file name, which is added as the last command line argument. Ensure it has the .mp4 container extension in the name.

Usage Example

ffmpeg -f alsa -i plughw:0,0 -f x11grab -s 1680x1050 -r 24 -b 100k -bf 4 -g 15 -i :0.0+0,0 -acodec libmp3lame -ar 44100 -ab 320k -vcodec libx264 -vpre lossless_fast Desktop_Recording.mp4



This captures the left screen at 1680x1050 resolution. The framerate is 24fps. The audio is encoded in MP3 format at 44100 khz / 320kbps. The file saved is Desktop_Recording.mp4, and is saved in the same directory you executed this command in.


To stop the recording, press Ctrl+C. in the termnal.
You have read this article ffmpeg / Screencasting / Vimeo with the title Using ffmpeg to record screencasts compatible with Vimeo. You can bookmark this page URL http://azaquery.blogspot.com/2011/10/using-ffmpeg-to-record-screencasts.html. Thanks!

No comment for "Using ffmpeg to record screencasts compatible with Vimeo"

Post a Comment