Scheduled video captures on Ubuntu 14.04 using Bash

David G - DrupalAs I’ve mentioned in other blog posts I occasionally attend E-classes on interesting topics. Lately, I have been attending a Korean 101 course on The instructor, class participants and (informal) course curriculum is great! Occasionally my schedule is tight to attend ever Tuesday/Thursday class meeting, and even if I attend all the classes I fear I could not retain all the content that was presented in the 1 or 2 hour sessions. So when I realized I’d sign up and participate in this course I decided to attempt to script recording my browser window and capturing the audio feed through my speakers to archive and review later. Here are some of the tools, steps and scripts I have used in a workflow to automate these recording sessions.

Studying Alone Sucks! Learn together in live classroms! :D

Studying Alone Sucks! Learn together in live classroms! 😀

My Initial Plans … Otherwise Known As Biting Off More Than You Can Chew.

In the past I’ve used gtk-recordmydesktop to record informative videos I find online, or live streams I attend. But these require I be in front of my computer to select the area of my desktop to record and press RECORD to actually begin a recording session. I would find it hard to automate a GUI application.

So my next thought was that gtk-recordmydesktop is simply a GUI frontend to recordmydesktop. Maybe I can:

  • Script it from the command line using a shell script.

If I can script it from the command line, then I simply need to:

  • Figure out a way to set a schedule and duration for duration; offhand I thought the Linux AT command or CronTab could suffice for this.

Well doing a bit of Googling to scripting recordmydesktop led me to the MAN pages for recordmydesktop where the command line options are discussed and this helpful Youtube video of someone scripting recordmydesktop themselves!

Seeing the above resources gave me hope this was a (relatively) easy task, which others had accomplished before. So after some work I came up with this command:

recordmydesktop --x=100 --channels 2 --freq 44100 --width 1200 \
-height 720 --follow-mouse --no-frame -o /home/dgurba/720.ogv

This is almost a copy of the Youtube video entry (actually I think it is), but after evolving my script it’s vastly different.

Knowing that calling recordmydesktop from the command line could work I moved on to the scheduling problem.

Scheduling the Recording

Initially I tried to run the above example line of code using the AT command, such as:

$> at 7:30pm -f /path/to/script/

Where simply calls recordmydesktop with the options. This would run, but my Environment and configuration for AT was misconfigured and ultimately nothing on the screen was grabbed. Being on a tight deadline with a class later that day, I abandoned AT as a big mystery to me which I didn’t have time to resolve.  😀

In the past I’ve also used Cron to perform such tasks, but I wanted a tool I could start and stop at scheduled intervals (such as the AT command — but you know, that works) and rely less on the system I was currently logged into.

My Current Usable Solution

So I eventually created this script after some trial and error:


hash recordmydesktop 2>/dev/null || {
    echo >&2 "I require RecordMyDesktop but it's not installed.  Aborting.";
if ! [[ $1 =~ $re ]] ; then
   echo "error: Argument 1 (delay) is not a number" >&2; ERROR=1
if ! [[ $2 =~ $re ]] ; then
   echo "error: Argument 2 (duration) is not a number" >&2; ERROR=1
if ! [[ $ERROR -eq 0 ]] ; then
  echo ""
  echo "Usage: $0 [delay] [duration]"
  echo ""
  echo "   [delay] = the length of time in minutes to delay recording"
  echo "   [duration] = the length of time to record"
  echo ""
  echo "   Example: (delay for 1 minute and record for 1 minute)"
  echo "   $0 1 1"
  exit 1

echo " --- Recording Script --- "

RECORD_DATE=`date +%Y-%m-%d:%H:%M:%S`
let "delay= 60 * $1"
let "duration = 60 * $2"

echo " Delaying for $1 mins. Recording for $2 mins."
sleep $delay
recordmydesktop --x 100 -y 90 --channels 2 --freq 22050 --fps 34 --full-shots \
--no-cursor --width 1150 --height 980 -o $FILENAME &
sleep $duration
# Send recordmydesktop the Ctrl+C it wants to Stop recording.
kill -INT $PID

I’ve attempted to keep this script short and sweet and simple. This script takes 2 arguments a delay time in minutes to start recording, and a recording duration in minutes.

If these values are given and the requistite applications are avaiable on the system it then SLEEPs until the delay-duration is passed, and records for N minutes. After N minutes the INTERRUPT signal (Ctrl+C) is sent to the recordmydesktop process.

For my needs the recordmydesktop command has all the options I want for a highquality rip on my home desktop machine. It outputs a file such as nooma.2016-02-23-hh:mm:ss.ogv

This setup works!

Additional Fun Facts

  • Recordmydesktop with this configuration outputs a 1034Mb video file for ~60 minutes of audio and video. Additional scripts I’ve written use ffmpeg to compress these files to more compact webm files, of say ~250Mb. After video optimization the final videos are great quality!
  • Grabbing audio on Ubuntu 14.04 doesn’t work for me unless the application Pulse Audio Volume Control is running in the background and monitoring a recording stream. See:
  • How do you convert .ogv to .webm files? Where $1 is your input file and $2 is your output file you simply call:
    ffmpeg -i $1 -ac 2 -ab 128k -ar 22050 -b 345k $2.webm
  • The Youtube author couldn’t pass a Y option to recordmydesktop. If you look at the MAN pages for recordmydesktop or –help you will see that the Y option is broken and unlike –x=NNN the Y option supports only 1 single dash mark. So you must enter -y=NNN as I did in my script. Hooray for inconstancies!
  • I’m basically (remotely) pressing record and praying it all works if I’m not at my desk! This could fail in spectacular ways;
    • My Internet connection could be interrupted
    • The classroom instructor could be delayed or her webcam not work (has happened)
    • The stream could die.
    • The recording could go over the duration i set to record. (has happened)

At least in my last case above. I initially set the recording session to go for 1.5 hours. But the class lasted a total of 2 hours. So quickly when the script went to process the video I opened a new terminal and simply ran:

$> ./ 0 15

This simply means record for 15 minutes starting NOW! This worked fine in my last class and I probably missed (in total) 5 seconds of audio at most in the class.

… Then I ended up with additional .ogv files for that date. So I simply merged them all:

ffmpeg -f concat -i <(for f in ./*.ogv; do echo "file '$PWD/$f'"; done) -c copy working.ogv

Before transcoding to a webm format. In the future I want to create a more project folder structure that is more friendly to a video editing workflow such as:

$ tree .
├── rash_daily_digest.txt
└── workflow
    ├── archive
    ├── edits
    ├── footage
    └── images

Wherein workflow stores the raw recorded footage, itermediarly derived Edits and final copies of finished works. [Tree is a useful Unix program.]

So, this is 1 of my current pet projects! Where I get to automate something that is otherwise a tedious task.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , | Posted under Linux Usability, Uncategorized, Video | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at

Leave a Reply

Your email address will not be published. Required fields are marked *