Archive for the ‘Uncategorized’ Category

Bonding Ethernet and Wireless interfaces for extra Speed & Reliability.

December 22, 2015

I recently moved home and now my home server needs to be situated in a different room than my router.  I tried running the server on wifi only but it was a bit frustrating despite using dual band router and dual band USB interface.  Speed is still nothing like gigabit ethernet and sometimes there were problems remounting nfs shares on resuming my desktop from sleep.  Next I tried a TP-Link Gigabit Powerline kit.  This is better but still very noticably slower than regular wired gigabit ethernet.  My next idea was to bond the Powerline ethernet and wireless ‘N’ interfaces in order to aggregate the interfaces for a speed boost and for fail over reliability.  This works!

Here’s the key: ignore almost all the examples and howtos you found on Google.  There are some very confusing and complicated and downright wrong explanations and examples out there.  I also suspect that some people just prefer to do it the hard way.

Anyway, here’s my set up and what worked for me:

My router gives me 4 Gigabit ethernet ports and dual band wifi.  The wifi is encrypted with WPA2 PSK (CCMP).  I have static addresses for my desktop and printer.  Other stuff gets an address via DHCP.

One Gigabit port is used to connect with a Powerline adapter.  Another port goes to my desktop and another to my printer/scanner.

My server runs Debian Jessie 8.2.  It is on another floor and is connected by ethernet to another Powerline adapter which is paired to the one at the router.  The server also has a USB dual band wireless adapter.  The wireless driver is in the standard Debian kernel and the firmware was available from a package in Debian’s non-free repo.

So, to get the network interfaces bonded I neeeded to install ifenslave and then reboot or restart networking service.

# apt-get install ifenslave && reboot

Next edit /etc/network/interfaces so it looks like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

allow-hotplug eth0
auto eth0
iface eth0 inet manual
bond-master bond0

allow-hotplug wlan1
auto wlan1
iface wlan1 inet manual
bond-master bond0
wpa-ssid “MY_SSID”
wpa-psk “MY_SECRET_KEY”
wireless-channel “36”

auto bond0
iface bond0 inet static
bond-mode 0
bond-miimon 100


Naturally you need to specify your own SSID and key and of course your own preferred IP address, netmask and gateway.  You might not need to specify the wireless channel.  I found it useful to do so in order to avoid using the more congested 2.4GHz band.

I specified a static address on the server but did not reserve an address on the router, which does the sane thing and allocates the address requested  by the server.  This works perfectly for me but may not work on a busier LAN.

I reboot.  It works!

Here’s the proof:

# ifconfig
bond0 Link encap:Ethernet HWaddr 00:1d:72:a0:dc:ed
inet addr: Bcast: Mask:
inet6 addr: fe80::21d:72ff:fea0:dced/64 Scope:Link
RX packets:2436064 errors:0 dropped:2995 overruns:0 frame:0
TX packets:2438371 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1741347675 (1.6 GiB) TX bytes:4336225638 (4.0 GiB)

eth0 Link encap:Ethernet HWaddr 00:1d:72:a0:dc:ed
inet6 addr: fe80::21d:72ff:fea0:dced/64 Scope:Link
RX packets:1213626 errors:0 dropped:0 overruns:0 frame:0
TX packets:582146 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:746352277 (711.7 MiB) TX bytes:2081911527 (1.9 GiB)

lo Link encap:Local Loopback
inet addr: Mask:
inet6 addr: ::1/128 Scope:Host
RX packets:528 errors:0 dropped:0 overruns:0 frame:0
TX packets:528 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:67546 (65.9 KiB) TX bytes:67546 (65.9 KiB)

wlan1 Link encap:Ethernet HWaddr 00:1d:72:a0:dc:ed
RX packets:1222485 errors:0 dropped:0 overruns:0 frame:0
TX packets:1856282 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:994998751 (948.9 MiB) TX bytes:2254380081 (2.0 GiB)



Bash Video Thumbnailer

September 1, 2012

Video thumbnail: a montage of screenshots from a video file, often accompanied by some file info.  Like this:

I wasn’t satisfied with the thumbnailers I had tried for a few reasons:

  • usually incredibly slow
  • work with some files/formats but not others
  • usually don’t understand anamorphic video and make shots with bad aspect ratio
  • often require X and a graphical desktop

So I decided to make my own bash script, videothumbs, that:

  • is quicker than the stuff I already tried
  • works with every video codec and container that my OS supports
  • gets the damn aspect ratio right!
  • works on headless or non-gui systems

And here it is:

20 March 2013: New version at now makes all thumbs with ffmpeg as changes in newer versions of mplayer and some containers caused problems.

As you can see from the image above (click for full size), videothumbs creates an image identically named as the input file except for the file extension, 1024 pixels wide with 4 columns of 10 images.  At the top is some basic file info: file name, video codec and dimensions, audio codec and number of channels.

There is only one user option -o

“videothumbs -o  path  mymovie.mkv”

to have the thumbnail image output to path instead of the same directory as mymovie.mkv.

It uses mplayer or ffmpeg (depending on file type) to grab/create the images and imagemagick’s montage command to make the thumbnail sheet.  It’s quickest with files in Matroska (.mkv) or .mpg/.mpeg  containers.  MPlayer grabs uncompressed png frames really quickly from mkv or mpg but can choke seeking to a specific point in avi files (I think because a position specified in seconds doesn’t always correspond to a keyframe) and on some mp4 files (I don’t know why).  So, for everything that isn’t in mkv/mpg, videothumbs falls back to using ffmpeg to create the images.  This is slower, but still better than hanging….  For a quick comparison I booted Windows XP and made a thumbnail sheet using Media Player Classic: it took absolutely ages and was much slower than my script.

I’ve tested videothumbs on the following containers:

mkv, mp4, avi, vob, wmv, mov, divx, mpg

which contained various codecs:

video: h264, divx/xvid, wmv3, Sorenson Media Video 3 (Apple QuickTime), mpeg2 (DVD), ogv, ogg

audio: aac, ac3, dts, mp3, ogg vorbis, mp2, ima4 (Quicktime)

and probably some others too.  So far everything worked.  YMMV.  I’m running Debian Stable (Squeeze) with (proper) ffmpeg and mplayer from the unofficial repositories.  I have no idea if this script will work with libav as it does with ffmpeg.

ffmpeg autocrop bash script function

June 1, 2012

This ffmpeg auto crop function is derived from this mplayer based script from the mplayer mailing lists in 2005

My one differs a little.  It runs cropdetect with a 2x rounding because I only encode with  x264 which doesn’t require the ‘divisible by 16’ dimensions of older encoders (in theory there is an efficiency penalty with x264 like with the old divx/xvid encoders, but in practice the penalty is so tiny as to be effectively non-existent) and it always crops an extra 2 pixels from each side because it’s so usual for DVDs/vobs/rips to have a picture which has line of slightly different luminosity at one or more borders that the human eye sees easily but isn’t detected at all by cropdetect algorithms (and yes I’m the kind of person who runs mplayer with -noborder for manual crop detection so my eye is not tricked by edge effects).

It works as a stand alone script or you can just drop it as a function in to your own script and use the crop value it produces (usual mplayer/mencoder/ffmpeg  w:h:x:y syntax).