Capturing Video (How I Did It)

One of the common questions we get here at is how we produce our videos. Shawn produced a howto video on some ways of doing it. The following describes how I capture my videos and also the script that I use to add the Linux Journal logo watermark to it.

The video capture howto part of the article is fairly simple: I use xvidcap:

$ xvidcap --cap_geometry 640x480

The --cap_geometry argument sets the initial size of the capture area so that I always get the same size video. This is also a requirement for my watermark adding script.


I keep my videos short and just recapture them if I make a mistake during the capture process. If you need to capture long videos, redoing the entire thing each time you make a mistake is probably not feasible so you'll need to use some kind of video editing tool for the final editing. Numerous video editing tools exist, check out our recent articles on LiVES: LiVES1, LiVES2, and LiVES3.

A couple of notes about xvidcap: it, at least the version that I'm using, tends to crash quite often. Don't attempt to capture and review the captured video more than a couple times without restarting xvidcap. If you have a recalcitrant audio setup, as I seem to, run a quick "test test test" capture before you dive in to make sure everything is working correctly and your sound level is set correctly. By default xvidcap saves captured videos to the file test-0000.mpeg, make sure to rename the file if you want to save it before capturing a new video.

Once I've got a video captured I add the Linux Journal logo watermark to the video by running my script:

$ sh --left video.mpeg

The script accepts either --left or --right and uses that to determine which image file to use (I have 2 files, one with the logo on the left and the other on the right). If --left is specified it looks for the file logo-left-640x480.jpg, if --right, then logo-right-640x480.jpg. The geometry portion of the overlay file name (eg 640x480) is based on the size of the captured video, so if you were to capture at 1024x768 you'd need a file named logo-left-1024x768.jpg. To create an overlay image you merely need an image or the right size with a gray background, specifically the color #808080.

When the script runs it adds the overlay to the input video and creates two output videos of the same base name, one with a .mp4 extension and one with a .ogv extension. The script also accepts the option --remove-audio, which removes the audio track from the output videos.

One of the things in the script that you will probably need to change is the ffmpeg command that does the overlay:

ffmpeg -sameq $opts -i $mpeg -vhook "/usr/lib64/vhook/ -f $logo" $mp4

The location of the watermark library will most likely be different on your system (I use openSUSE). If you have a very recent version of ffmpeg you may even need to change how this is done as the -vhook capability may have been removed as it's been deprecated and replaced by a different mechanism.

The full source code for the script appears below:


function usage()
	if [[ "$*" ]]; then
		echo "$*" >&2

	cat >&2 <<EOF
Usage: $(basename $0) OPTIONS FILE.mpeg
  --left          Add logo on left side
  --right         Add logo on right side
  --remove-audio  Remove audio stream from converted videos
	exit 1

function error()
	echo "$*" >&2
	exit 1

while [[ "$1" ]]
	case "$1" in
		usage "Unrecognized option $1"
		if [[ "$mpeg" ]]; then usage "Unexpected argument: $1"; fi
		if [[ "$mext" != 'mpeg' ]]; then error "Invalid mpeg file: $mpeg"; fi

if [[ ! "$mpeg" ]]; then usage; fi

geometry=$(file $mpeg | grep -P -o '\d+ x \d+' | tr -d ' ')
if   [[ $left -eq 1 ]]; then
elif [[ $right -eq 1 ]]; then
	error "Specify one of --left or --right"

if [[ ! -f $logo ]]; then error "Logo file not found: $logo"; fi

if [[ $remove_audio -ne 0 ]]; then opts='-an'; fi

mp4=$(basename $mpeg .mpeg).mp4
ogv=$(basename $mpeg .mpeg).ogv

rm -f $mp4 $ogv
ffmpeg -sameq $opts -i $mpeg -vhook "/usr/lib64/vhook/ -f $logo" $mp4
ffmpeg -sameq $opts -i $mp4 $ogv

# vim: tabstop=4: shiftwidth=4: noexpandtab:
# kate: tab-width 4; indent-width 4; replace-tabs false;

Mitch Frazier is an embedded systems programmer at Emerson Electric Co. Mitch has been a contributor to and a friend of Linux Journal since the early 2000s.

Load Disqus comments