Record screen + audio with FFMpeg

$480 for Camstasia? I think not. CamStudio? Buggy as hell. Luckily, we have an excellent FREE cross-platform tool that let’s us easily create a video-recording of your desktop including audio: FFMpeg.

If you are running Windows, download the x64 here.

Extract the downloaded archive and open a command prompt in the bin folder.

To check your version:
ffmpeg --version

ffmpeg version N-79630-g9ac154d Copyright (c) 2000-2016 the FFmpeg developers

To show available input devices for audio:
ffmpeg -list_devices true -f dshow -i dummy


DirectShow audio devices
“Microphone (5- Webcam C170)”

This is the magic string you’ll need to specify in the next, awesome command.

ffmpeg -y -f dshow -i audio="Microphone (5- Webcam C170)" -f gdigrab -video_size 1920x1080 -i desktop -vcodec h264 my-screen-with-audio.mkv

This will record your screen at full-hd encoded using h264 and including audio sourced from your microphone. When you want to stop the recording, press Ctrl+C in command prompt and your video file will be ready, too easy!

If you want to record the screen only (no audio), use:
ffmpeg -f gdigrab -offset_x 0 -offset_y 0 -video_size 1920x1080 -i desktop -vcodec h264 my-screen-only.mkv

Thank you FFMpeg developers!

Play video at specific position and size

Using VLC, we can have a video begin playback at a specific screen location and window size. I found this useful when creating a screen recording of some software where I wanted to have a video overlay playing in the corner of the screen at the same time. Here’s the command line I used (for VLC 2.0.8 on Windows 8.1):

vlc.exe –no-video-deco –no-embedded-video –video-x=1320 –video-y=700 –width=600 –video-on-top –qt-system-tray –qt-start-minimized my-video.mp4 vlc://quit

  • The vlc://quit is a special playlist entry that causes VLC to quit after playback of the preceeding video.
  • Adjust video-x and video-y to set screen position, and set width or height to set window size.
  • The no-video-deco and video-on-top will remove the window chrome, and ensure the video is always on top.

Missing Maximize / Minimize in Gnome

Gnome 3 continues to be abhorant. Not only can I not get to a terminal easily anymore, but there’s no maximize / minimze button on windows? Who designed this and have they used graphical user interfaces for more than a few minutes / hours? Anyway to turn this basic functionality back on using Fedora try (thanks to this thread):

sudo yum install gnome-tweak-tool

Then search for ‘tweak’ in the Gnome 3 Applications menu, open ‘tweak tool’ app and click the ‘Windows’ tab and enable the titlebar options as follows:

maxmin

Geez.

Instantiating a custom view in Android

Creating a custom view/control in Android is fairly simple – here are the steps I used:

  1. Create a new class which extends from the ‘View’ abstract base class. E.g.
    public class MyCustomControl extends View
  2. Provide constructor overloads for ALL of the following prototypes, where initView() is a method in which you perform initialization of things such as Paint objects:
    public MyCustomControl(Context context)
    	{
    		super(context);
    		initView();
    	}
    	
    	public MyCustomControl(Context context, AttributeSet attrs)
    	{
    		super(context, attrs);
    		initView();
    	}
    
    	public MyCustomControl(Context context, AttributeSet attrs, int defStyle)
    	{
    		super(context, attrs, defStyle);
    		initView();
    	}
    
  3. Override onMeasure() in order to scale your control to the parent drawing area, such as shown in this good example.
  4. Do your canvas drawing operations in onDraw on the supplied Canvas object.
  5. Instantiate your custom view in a layout xml file (e.g. main.xml), for example:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    	<com.android.samples.MyCustomControl
    		android:id="@+id/myCustomControl"
        	android:layout_width="fill_parent" 
        	android:layout_height="fill_parent" 
        />
    </LinearLayout>

I found that if I didn’t add the 2nd and 3rd constructors, I got an exception when calling setContentView(R.layout.main) from onCreate() of the main Activity. You can instead construct an instance of the view manually in onCreate() of the main Activity, and then call setContentView(yourCustomViewInstance) if you don’t want to use XML layout.