What is it? Video Identification

Often it is helpful to know what your starting point is. If you have a video with unknown characteristics, you can find out more about it by doing something like this.

mplayer -identify -vo null -ao null -frames 0 video.avi

This should tell you things like the codecs, bitrates, and the resolution.

You can use this with something fancier. Here is how to find out how many frames a video contains.

mplayer -identify -vo null -ao null -frames 0 mysteryvid.mp4 \
| awk 'BEGIN{FS="="} \
       /ID_VIDEO_FPS/{rate=$2} /ID_LENGTH/{time=$2} \
       END{print int(rate*time)-1}'

If the video is on a DVD, use acidrip and select the "copy" options for video and audio codecs. This will give you the video off the disc with unmodified characteristics. Query those with the command above and see what’s really there.

Also consider this.

avconv -i video.avi

Video Editing

Pitivi is an ambitious little editor that seems to stitch together some powerful command line utilities into a GUI. However, though I had some success with it, I also easily discovered its limitations.

For serious editing, and I mean serious, use Blender. The only disadvantage to Blender is it is easy to get overwhelmed in the massive feature set. I abused Blender on underpowered machines and never had it blink—rock solid. It is perhaps the most surprisingly stable software I’ve ever used. See my full notes on Blender.

Backing Up Stubborn DVDs

Some DVDs really piss me off. It’s important that you use a DVD player that is not so fussy about disks and will just follow your instructions to read all the 1s and 0s off the accursed disk. Here’s what you do:

ddrescue -n -b 2048 /dev/dvd output_raw.iso
dvdbackup -M -i output.iso -o dvd_structure
mkisofs -dvd-video -o clean_dvd.iso dvd_structure

Been liking acidrip lately. Good GUI for all the complex mess.

Here’s a project that might be helpful: k9copy


You might consider vlc if mplayer is problematic.

Finding Excerpts To Extract From Larger Video

Often you record all kinds of junk and the cool thing you really wanted is buried in there. Thanks to mplayer or some other clever player with on screen display ("o" in mplayer), you know where exactly you want your excerpted video to begin and end.

This worked for me to find the correct subset clip. This was done on another machine so I could control mplayer from a different location than where it was running full screen.

DISPLAY=:0.0 mplayer -ss 372  -endpos 25 -fs Encode_1080P_4.mp4

The 372 is the starting position in seconds and the 25 is the duration of the clip.

mplayer with the webcam

If your webcam puts a feed in an obvious place, mplayer can probably do nice things with it. Here are some examples.

This takes a single snapshot off the webcam.

mplayer -frames 1 -vo jpeg:outdir=/home/xed/capturedir/ tv://

Here’s a little script that has helped me.


# Need to capture several frames since the first couple are duds.
mplayer -quiet -nosound \
    -tv device=/dev/video0 \
    -ss 143 -frames 3 -vo jpeg:outdir=. tv:// \
    2>/dev/null >/dev/null
# Pick out last one.
mv $(ls 0000[0-9]*.jpg|tail -n1) webcam-$(date '+%Y-%m-%d_%H%M%S').jpg
# Delete the duds. Careful! This isn't very cautious.
rm 0000[0-9]*.jpg

Watch the camera and specify where it is.

mplayer -tv device=/dev/video tv://

Is your camera upside down? This is common with a USB microscope. This might help.

mplayer -vf flip,mirror -tv device=/dev/video0 tv://

Don’t like pixels? Have no fear! Use ASCII using libcaca.

mplayer -vo caca tv://

Or if you need to see a video and you only have a console without any graphics.

CACA_GEOMETRY=$(stty size|awk '{print $2"x"$1}') mplayer -quiet -vo caca tv:/


Mencoder seems to be related to mplayer but Debian seems to have stopped carrying it. What a mess!

Rotating with mencoder

Sometimes you take a video with your phone and it should be in portrait, but players play it in landscape. This command rotated a goofy 3gp video file from my Andriod phone:

mencoder -vf rotate=1 -ovc lavc -oac pcm fromphone.3gp -o portrait.mp4

Adding And Removing Sound Track

Provide your own sound track:

mencoder -vf rotate=1 -oac copy -audiofile st.mp3 -o out90.avi -ovc lavc in.avi


Or mute the thing entirely:

mencoder -v -nosound -o outvid.avi -ovc lavc invid.mp4

Here is the ffmpeg/avconv way to remove the sound (note the -an option which disables audio).

avconv -i invid.avi -vcodec copy -an outvid.avi

This rotates and cuts off the first 3 seconds and nulls the sound track:

mencoder -vf rotate=2 -ss 3 -ovc xvid -oac copy -audiofile /dev/null \
-o t_xed.avi -xvidencopts bitrate=300:pass=2 MVI_1393.AVI

Note that -endpos can be used for clipping the end off video.

Sometimes the -ss option doesn’t really work when I think it should. Here is a way to cut off the beginning of a video. This cuts off the first half a second.

mencoder -v -ss 00:00:20 -nosound -o outvid.avi -ovc lavc invid.mp4


vlc is yet another comprehensive media player. It has tons of tricks. The documentation really seems to depend on what’s compiled into the binary and the developers therefore have a sensible man page that basically directs you to get detailed option help with this.

vlc --longhelp --advanced | less

To play the normal video device (perhaps a webcam).

cvlc v4l2:///dev/video0

Note the cvlc which is presumably for "command line". It’s just an alias for this.

vlc -Idummy v4l2:///dev/video0

This works too for the default video device.

vlc -Idummy v4l2://

I’ve had luck with internet cameras using something like this.

cvlc rtsp://

This could be useful.

cvlc -vvv v4l2:///dev/video0:width=1920:height=1080

In theory you can use screen:// for screen capture.

Here’s how to record something from a camera.

cvlc --rtsp-user root --rtsp-pwd ${P} \
     rtsp:// \

Options that could be useful.

  • -f = full screen.

  • --width = video width.

  • --height = video height.

  • --crop = apparently you can crop which could be handy to filter out the opposite of regions of interest.

  • --sub-file = seems to have a lot of features related to subtitles.

  • --rtsp-user root and --rtsp-pwd ${P}


This article sums up the Real Housewives of libav/ffmpeg quite well: "…it was actually pretty funny to see them acting like children, even though the situation was kind of serious…The main problem is that external projects who want to support both FFmpeg and Libav are just fucked…" Ya, so this is tricky. It sounds like the ffmpeg lead maintainer was being a bit of an imperious wanker and then the avconv guys forked it (or something), started up with their own management style problems, and proved why he needed to be.

I’m finally breaking out avconv to its own section because I use Debian enough to care and I find enough irritating differences.


Here is the avconv way to resize. This shrinks the geometry with -s and removes the audio with -an. This size is quarter HD and used in some driving videos I’ve worked with.

avconv -i -s 960x540 -an dashcam_qHD.mp4


The epic stupidity of telephone cameras means that it is almost the rule rather than the exception that video taken with them will be upside down or in the incorrect mode. Which is portrait mode — the incorrect mode for video is portrait.

To fix this, it seems you have to re-encode it. Super annoying. The following seemed to work for a completely upside down video.

avconv -i upsidedn.mp4 -vf "transpose=1,transpose=1" -codec:v libx264 -codec:a copy ok.mp4

I think that a 90 degree rotation can be achieved by removing one of the "transpose=1" statements. When running this I got a ton of "Past duration too large" warnings which I ignored.

Extracting subset

Here’s the avconv way I got working.

avconv -ss 00:06:00  -i wholegame.mp4 -t 00:00:30 -acodec copy -vcodec copy -async 1 dunk.mp4

Note here that the video is only 30s long. Also note that it is important that the -ss come before the -i option.


ffmpeg is a great tool for converting video from something to something else. See the ffmpeg documentation.

Real Housewives Of FFmpeg

It seems that ffmpeg has gone through some crazy reorganization. It’s hard to tell what’s really going on but it seems there was a fork to avconv which used the Debian package called libav-tools. There was a ffmpeg package that just provided backward name compatibility to avconv. Then there seems to have been something of a reconciliation. Now it looks like there may be an ffmpeg package that is the real thing again, now no longer forked. Whew! The active ffmpeg web site seems like it’s still going strong. Doing a Debian apt-get install libav-tools in Feb 2017 produced a working avconv and no ffmpeg. Here is a discussion of this situation.


If you need to download FFmpeg from source here’s the official web site.

If you’re using Debian or Ubuntu and really need FFmpeg (for OpenCV for example), you may need to compile it from scratch. It’s pretty polite and behaves as you’d expect. You do need to put some prerequisites in place first. Here’s a look at how it’s done.

Find the latest version at: Acquire using one of these.

git clone ffmpeg


apt-get install yasm pkg-config
sudo make install # Puts things in `/usr/local/` by default.

This should give you ffmpeg, ffprobe, ffserver.

Problems with video in OpenCV? That can be related to FFmpeg.

sudo apt-get install libopencv-dev python-opencv

If you’re using a system that has ffmpeg properly provisioned you might be able to just install it with the package manager. Here are some packages I have needed to consider to get things working properly.

sudo apt-get install  libavcodec-dev libavcodec-extra-52 libavcodec-unstripped-52


Check out FFmpeg Little Helper for a web based GUI that generates the correct command line.

Shrinking Videos

A good way to shrink videos from the Canon A590 to send to fb:

ffmpeg -i mvi_0378.avi -f avi -vcodec mpeg4 -s 320x240 -r 20 -ar 22050 -b 1000000 ski2.mpg

Another application to shrink videos to save space (factor of 5 without noticeable quality loss):

ffmpeg -i inputfile.avi -ar 32000 -s 480x360 -b 1252.4k outputfile.avi

The -s is the new size. The -ar is the audio bitrate.

Extracting subset

Here is a way to select a portion of a video to make a smaller one:

ffmpeg -i SK8.mp4 -ss 00:08:10.0 -vframes 5100  -acodec copy -vcodec copy -async 1 OSK8-test.mp4

Note that ffmpeg has a -t option to set the duration time of the video, but I’ve never gotten it to work and have seen reports of others with the same problem. But -vframes does seem to cut off the video at the right place. It’s annoying they don’t just have start time and stop time which would make sense. To get the correct vframes value you have to figure out the duration in seconds you want and then multiply by the frame rate (often 30). To get frame rate, play the video with mplayer and watch its console output for "FPS".

JPEG to Video

The following technique is useful for making stop motion animation videos and videos of slide shows. It takes a list of jpeg files (and only jpeg files as I understand it) and converts them into a video format. The following was able to take hundreds of jpegs and make them into a video that could be uploaded to YouTube.

(Hmmm. This actually doesn’t look right. See farther down…)

avconv \
-i myvid.mp4 \
-ss 00:05:05 \
-t 00:00:03 \
-r 120 \
-s 1280x720 \
-f image2 \

The -r is the framerate, here 120 frames per second (30 is common). These particular settings were to extract video from a GoPro. Note that with this starting offset (-ss) the program can sit there apparently doing not much of anything for quite a while until it gets to the relevant section; I think it must calculate the previous frames since many codecs are basically diffs.

There may be other ways of doing this, but the easiest is to name all the jpegs to use 001.jpg, 002.jpg, etc. If the sequence is broken, ffmpeg will stop encoding. So make sure the names are in order. (Look into using Chris' numbfile program. Try numbfile -z3 -s.jpg *jpg if less than 1000 images).
If you need an animated png, mplayer seems to do that too. Look in the man page for the png video output setting.

This used to work for PNG:

ffmpeg -r 10 -b 64k -qscale 2 -i torcs-0001-0000%04d.png snakeoil.mp4

Now I’ve had better luck with this.

avconv -i torcs-0001-0000%04d.png -r 25  -qscale:v 2 kurinjimala.mp4

This makes a large but high quality video. I’ll let YouTube sort out the details.

Sometimes you have a big collection of jpegs from something like motion and they have messy timestamps in their names. How do you make all the images into a format for something like a technique that needs a numeric printf pattern?

C=0 ;ls /var/lib/motion/*jpg | \
while read F; do echo $F ; cp -v $F $(printf "/tmp/%05d.jpg" $C); : $((C++)); done

Video to JPEG

Just like the other way around, you can pull still images out of video.

ffmpeg -i video.webm -ss 00:00:07.000 -vframes 1 thumb.jpg

Here’s another example. This one takes a still every second (fps=1). The qscale:v is a quality specifier. Apparently 2 is the highest.

ffmpeg -i in.mp4 -qscale:v 2 -vf fps=1 stills%04d.jpg

Note that stuff like fps=1/2 for an image every two seconds.

Video to MP3

Extract mp3 track of the video to sound files with:

ffmpeg -i DubFX-Made.flv -acodec copy DubFX-Flow.mp3

This assumes that the video has an mp3 encoded sound track. YouTube appears to do this. Here’s a more complicated way to do this that might be necessary:

ffmpeg -y -i INPUT.flv -acodec libmp3lame  -ar 22050 -ab 128000 OUTPUT.mp3

Here’s a function that can turn Youtube videos into mp3 files on the fly:

function ripme {
    youtube-dl -q -o - "$1" | \
    ffmpeg -y -i - -acodec libmp3lame  -ar 22050 -ab 128000 "$2.mp3"
} # End function ripme.
# Call like so:
ripme Dire_Straits-Walk_Of_Life

To check what streams, audio and video, are in a video file:

ffmpeg -i inputvideo.flv

To actually convert some other audio stream:

ffmpeg -i inpuvvideofile.flv -ab 128k outputaudiofile.mp3

Where -ab specifies the audio bitrate.

To extract a subset of video to a new video:

mencoder -ss 2693.0 -endpos 1350.0 All_Four_Episodes.avi  -ovc copy -oac copy -idx -o Episode_Three.avi

Not that the -ss is the start always in seconds. The -endpos is more ambiguous. If an -ss is used, it means seconds running time of the subset. If -ss isn’t used, it means the same thing and it actually corresponds to endposition (time of subset from zero). This is why in the example, the "end position" is less than the -ss, starting position.

General ripping:

/usr/bin/mencoder dvd:// -dvd-device /dev/sr0 -ovc xvid -xvidencopts pass=2:bitrate=1000 -ni -alang en -oac mp3lame -lameopts vbr=3 -o moviename.avi

Animated GIFs

First use ffmpeg/avconv to decompose the video.

avconv -i example.mpeg -r 30 -s 160x120 /tmp/gif/out%04d.gif

This didn’t preserve color and probably degrades things. This takes longer, but retains color and makes a nicer final product.

avconv -i example.mpeg -r 30 -s 160x120 /tmp/tiff/out%04d.tiff

Then take the decomposed images and combine them with ImageMagick (which has pretty excellent documentation about animated gifs).

convert -delay 1x30 -layers Optimize /tmp/tiff/* -loop 1 example.gif

A loop setting of 0 will endlessly repeat.


Also use youtube-dl to get videos from YouTube:

youtube-dl -o Nobodys_Fool.flv

Sometimes you get the annoying webm format that mplayer is not so good with (maybe that will get fixed). So it’s sometimes good to try and get a "better" file format, where better doesn’t necessarily mean image quality.

First you need to see what’s available:

youtube-dl --all-formats --get-filename

Then you need to download the one that makes sense:

youtube-dl -f 35

Another useful option is -t which names the file after the title of the video instead of the messy (to us) hashed name.

Make sure you have

sudo apt-get install ffmpeg  libavcodec-extra-53

Also, this can take a Youtube URL and make an mp3 out of it. Very handy.

youtube-dl -t --extract-audio --audio-format=mp3 ''


After having way too much trouble doing simple track substitutions with the command line tools, I installed this:

sudo apt-get install avidemux

And it was able to put an mp3 over a video no problem. I didn’t figure out 1% of what this thing did but it seemed to work for that task pretty easily.

Webcam Tricks

Some webcam problems can be traced to the BIOS. Obvious, but easily overlooked is whether the web cam is enabled in the BIOS. This also is a hint at how to do quite a bit to ensure web cam privacy (i.e. disable it). Also sometimes BIOS updating can be required for Linux to properly see a webcam, especially from a new laptop.


sudo apt-get install cheese

This program is a nice GUI client to the webcam and an easy way to test to see if it’s working properly. Also it can take still snapshots which turns your laptop with a camera into a digital camera. There are "effects" that are helpful when the camera needs to be reversed or turned upside down, etc.

The Program Called "motion"

motion is a very excellent program that will turn on your camera and save what it sees only if there is something changing (if it sees "motion"). This is excellent for security cameras. Fairly easy to use on Ubuntu.

sudo apt-get install motion
sudo vi /etc/motion/motion.conf
sudo /etc/init.d/motion start
ls /tmp/motion # Find output here.

Of course you need to set some sensible settings in the configuration file. But it is well documented with comments and isn’t stupidly designed. Maybe also look in /var/lib/motion/ for the output. Don’t forget to make sure you have plenty of fast writing space to use (e.g. not a USB drive).


The utility recordmydesktop is for making screencasts of graphical sessions on Linux systems.

To install this on Ubuntu systems:

sudo apt-get install recordmydesktop
sudo apt-get install gtk-recordmydesktop

Since I was interested in recording the full screen, I found the best way to use this program was as follows.

First I enter the command to record following a sleep command. This gives me a chance to kick off the thing that I really want to be on the screen (perhaps a slide show or a game).

$ sleep 5; recordmydesktop --no-cursor --fps=5 --display=:0 \
--stop-shortcut=Control+s --s_quality=10 --output=myscreencasttest.ogv

Then before hitting enter, in another terminal (or with the previous command suitably in the background) I do this:

$ feh -FZ ~/slideshow/*png

Then before hitting enter here, I switch to the first terminal, hit enter, and then within my sleep time switch back here and hit enter and 5 seconds after starting the first command, it’s recording what I want.

The man page seems to indicate that long options can be specified without an =. But I’m not so sure this is correct. The = does seem to work.
Before getting too excited about recordmydesktop you should test it out. I found that it sort of worked and perhaps would have been fine for some kinds of demos, however, I wanted to record a slide show at a specific irregular pace and some slides were missing and the audio sync was generally bad using feh or eog as the viewer.

Converting To A YouTube Acceptable Format

Use PiTiVi to "render" the ogv file into something YouTube will accept. The following settings might do the job.

Container: MP4Muxer [mp4mux]
Audio Codec: Ffmpeg ALAC (Apple lossless Audio Encoder) encoder [ffenc_alac]
Video Codec: Ffmpeg MPEG-4 part 2 encoder [ffenc_mpeg4]
Video codec bit rate: 10300000

EasyCap Device

Here are some old (originally from 2010-12-30) notes on how I was able to get an EasyCap USB video capture device to work on Linux.

Setting Up The Driver

The following worked for me. First get the source for the driver:

$ svn co syntekdriver ; cd syntekdriver

There are some dependencies to get sorted out:

$ sudo apt-get ctags

There might be another, but it’s obvious Then compile it:

$ make -f Makefile.standalone

Load the this video driver if it’s not loaded already:

$ sudo modprobe videodev

Now try loading the module you just compiled:

$ insmod stk11xx.ko

Ideally dmesg should show something like:

[ 9309.880242] stk11xx: Syntek USB2.0 Capture device is ready
[ 9309.880353] stk11xx: Syntek USB2.0 Camera is now controlling video device /dev/video0

Using EasyCap For Video Input

Plugged a VCR’s video cable (RCA to RCA) into the yellow jack and did this:

$ mplayer tv://

Worked fine with no other parameters however someone reports success with:

mplayer tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video0

Adding Sound

The video driver works but the sound input doesn’t seem to easily. It might be registered as a different device, but I didn’t notice that and it’s definitely not integrated into the video device.

The solution was to just use the mic input and an RC to 3mm stereo male from a digital camera junk. This way, the analog video source (VCR, Wii, etc) sends video to the EasyCap, but audio goes to a more traditional audio capture and is managed in the normal way, volume controls work as normal.

Here is a suggested command approach to capture dsp as audio which might be useful when dubbing things from the analog signal (ripping VHS tapes, etc).:

$ mencoder tv:// -tv driver=v4l:width=640:height=480:device=/dev/video0:forceaudio:adevice=/dev/dsp:outfmt=uyvy:fps=30 -ovc lavc -oac mp3lame -o video.avi

PowerLead Helmet Cam

Here is the link to the helmet camera I bought in August 2017. The exact name of it according to Amazon is PowerLead Caue PL-05 Mini Sports Camera 1080P Full HD Action Waterproof Sport Helmet Bike Helmet Video Camera DVR AVI. On the box it also says "MINI F9 DVR". The manual is probably excellent if you can read Chinese. The English side left a lot to be desired. The USB manufacturer identifier according to the Linux kernel is "Polaroid Cube" and a SCSI bus message of "LeiSure SportDV" also comes up.


  • Works with Linux just fine.

  • Comes with a lot of physical mounting options.

  • Takes about 2 hrs to charge. Lights go out when it’s fully charged.

  • Uses MicroSD cards. They say 4GB or greater and class 4 or greater.

  • It does seem to be mountable as a USB2.0 mass storage device.

  • It takes rough stills in 1080p(1920x1080) mode. The manual hints that it does not work in 720p but this is false; it does take 720p (1280x720) photos. Look for photos in DCIM/100PHOTO/FILE####.JPG.

  • Video is either 1080p(1920x1080)@30fps or 720p(1280x720)@60fps. Look for videos in DCIM/100VIDEO/FILE####.MOV. Codec seems to be yuv420p.

  • Records sound pretty well. Audio codec seems to be: aac 2ch 1600Hz.


TL;DR: fore button=on/off, aft button=start/stop; long press=on/off/stop, short press=start.

  • Connecting to USB - The seam on the connector’s ground shield faces up, closest to the SD card. If plugged into a running computer it will be a mountable mass storage device.

  • Prepare For Video - On back panel, set bottom slider to video icon (slider left). Set top slider to mode 1080p@30 (slider left) or 720p@60 (slider right).

  • Power On - Hold fore (lens end) button 2 seconds. The lit top fore blue LED and 3 buzzes indicate success.

  • Start Video Recording - Short press of aft top button. Red LED lit and 3 buzzes indicate success, i.e. video is recording.

  • Stop Video Recording - Long press of aft top button. Blue LED stays lit, red LED goes out, and one buzz indicates success.

  • Power off - Long press of fore top button. One buzz and all LEDs out indicates success.

  • Prepare For Still Camera - On back panel, set bottom slider to camera icon (right). Set top slider to mode 1080p@30 (left) or 720p@60 (slider right).

  • Take Still Photo - Short press of aft top button in correct mode. Red LED lit briefly indicates success.

  • Volume - Strangely the volume setting was at 7 when it seems to indicate that the valid values are 0-2. Changing it seemed to have no effect.

Clock Setting

The clock is used to time stamp the files (video and photo mode) and also to display the current time on the recordings (video only). The clock needs to be set to UTC as that is assumed.

To set the system time…
  1. Mount the device itself or an SD card which has already been used in the device.

  2. In the top level directory of the device, look for a file called SportDV.txt.

  3. Edit this file with something that can handle stupid DOS line endings.

  4. Look for this field and change it from N to Y.


    When the camera system powers up, it will perform the update and then reset this back to N automatically.

  5. Look for the following fields and set them with the correct time a short while in the future.

  6. Unmount the camera, make sure it is off and wait for the time you set. At that time turn it on. Keep in mind it takes a couple of seconds of holding the power on button for it to come on. (A smart camera would know how to adjust for that; I didn’t check it.)

To completely turn off the time display embedded in the video, go through the same procedure as for setting the clock. Edit the SportDV.txt file. In addition to adjusting the time components, change the real time clock display setting, RTCDisplay, from 1 (show time) to 0 (don’t show time). Change UPDATE to Y to make changes take effect.