Archive for the ‘Linux’ Category.

RTMPDump: Watch live flash streams in mplayer

Flash on Linux sucks. You may find it useful to stream live flash streams to mplayer (or vlc).

Example live flash stream: Screenshot of it in mplayer:

Redirect RTMP traffic through to local port:

$ sudo iptables -t nat -A OUTPUT -p tcp --dport 1935 -j REDIRECT

Start RTMP Server to hold sniffed RTMP info:

$ rtmpsrv

RTMP Server v2.4
(c) 2010 Andrej Stepanchuk, Howard Chu; license: GPL

Streaming on rtmp://

Open or refresh the link to live flash stream in your web browser. The corresponding rtmpdump command output will be printed in the RTMP Server window. e.g.

rtmpdump -r "rtmp://" -a "lb/" -f "LNX 11,2,202,251" -W "" -p "" -y "kjghfsdm" -o kjghfsdm.flv

Close RTMP Server with Ctrl-C:

^CCaught signal: 2, cleaning up, just a second...

Delete previously added iptables rule:

$ sudo iptables -t nat -D OUTPUT -p tcp --dport 1935 -j REDIRECT

Test sniffed rtmpdump command, omitting output:

$ rtmpdump -r "rtmp://" -a "lb/" -f "LNX 11,2,202,251" -W "" -p "" -y "kjghfsdm"

RTMPDump v2.4
(c) 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team; license: GPL
WARNING: You haven't specified an output file (-o filename), using stdout
Connecting ...
INFO: Connected...
ERROR: rtmp server sent error
ERROR: rtmp server requested close

If similar errors are received, analyse sniffed command with the verbose flag, -V:

$ rtmpdump -r "rtmp://" -a "lb/" -f "LNX 11,2,202,251" -W "" -p "" -y "kjghfsdm" -V

DEBUG: Property: <Name:              level, STRING: error>
DEBUG: Property: <Name:               code, STRING: NetConnection.Connect.Rejected>
DEBUG: Property: <Name:        description, STRING: Connection failed: Application rejected connection.>
DEBUG: Property: <Name:                 ex, OBJECT>
DEBUG: (object begin)
DEBUG: Property: <Name:           redirect, STRING: rtmp://>
DEBUG: Property: <Name:               code, NUMBER: 302.00>
DEBUG: (object end)
DEBUG: Property: <Name:           clientid, NUMBER: 1754134368.00>

This log shows errors due to unhandled URL redirection. Update rtmpdump command to reflect direct URL:

$ rtmpdump -r "rtmp://" -a "live/" -f "LNX 11,2,202,251" -W "" -p "" -y "kjghfsdm" -V

DEBUG: Property: <Name:              level, STRING: status>
DEBUG: Property: <Name:               code, STRING: NetConnection.Connect.Success>
DEBUG: Property: <Name:        description, STRING: Connection succeeded.>
DEBUG: Property: <Name:               data, OBJECT>

Error message is now gone. Remove verbose option. Pipe output to mplayer:

$ rtmpdump -r "rtmp://" -a "live/" -f "LNX 11,2,202,251" -W "" -p "" -y "kjghfsdm" | mplayer -

Other things to try in case of rtmpdump errors:

  • Adding the --live option.
  • Using --port 80.
  • Increase cache when piping to mplayer: rtmpdump... | mplayer -cache 4096 -

Rockbox on Sansa Clip Zip: manual installation

I purchased a 4gb Sansa Clip Zip from Amazon after researching online for a small, minimalistic, convenient mp3 player.

What is Rockbox?

Rockbox is an open-source firmware replacement for compatible mp3 players. It provides additional functionality, efficiency, customisability and improved playback quality.

At time of writing, the only thing that hasn’t been fully ported is the sudoku plugin.

Manual Installation
For automated installation, you could use the rbutil package from the AUR, which provides a simple GUI interface. However, the GUI interface has a qt dependency. I don’t use any other qt applications, so I opted for the manual installation method.

See the Rockbox wiki for complete instructions.

  1. Ensure that the player’s USB setting is on MSC (Mass Storage Class).
    On the Clip Zip -> Settings -> System Settings -> USB Mode -> MSC
  2. Plug in the player and mount it as a normal user.
    $ sudo mount -o uid=$(id -u),gid=$(id -g),fmask=113,dmask=002 /dev/disk/by-label/SANSA\\x20CLIPZ /mnt/usb
  3. Extract the firmware.
    $ wget -O ~/downloads/
    $ unzip ~/downloads/ -d /mnt/usb
  4. Extract the bootloader.
    $ wget -O ~/downloads/rbinstall/mkamsboot
    $ wget -O ~/downloads/rbinstall/bootloader-clipzip.sansa
    $ wget -O ~/downloads/
    $ unzip ~/downloads/ -d ~/downloads/rbinstall
  5. Install the bootloader.
    $ cd ~/downloads/rbinstall
    $ chmod +x mkamsboot
    $ ./mkamsboot clpza.bin bootloader-clipzip.sansa patched.bin
    $ cp patched.bin /mnt/usb/clpza.bin
  6. Unmount the player. Unplug the usb. Wait for firmware update to finish.
    $ sudo umount /mnt/usb

tl;dr: Why systemd?


  • systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts.
  • It can act as a drop-in replacement for SysVinit.
  • Arch Linux will eventually fully migrate to systemd.


  • When it’s ready. For the foreseeable future, both SysVinit and systemd will be supported.

(From tomegun @ Arch Forums)

  • It’s hot-pluggable.
  • It tracks all daemons and processes.
  • It’s modular.
  • It makes better use of udev and dbus.
  • It reduces dependencies between daemons.
  • It’s easier to sandbox configuration options.
  • It’s a cross-distro project.
  • It can use distro-independent service files.
  • It uses logind to properly manage user sessions.
  • It’s faster or just as fast as SysVinit for most users. Writing for hackers

Just recently heard of – a pastebin services that converts markdown formatted files from into HTML.

Useful for those times you want to quickly share info that’s off-topic to your blog and to an audience of non manpage readers. Why markdown? It’s prettier than plain text and syntactically much simpler than html. GitHub users should like this.

Vim mode in Irssi

I came across an Irssi script that provides vim-like keybindings for the input line.

The script allows you to toggle between INSERT, COMMAND and EX modes.

In my vimrc and zshrc, I’ve already got jj mapped to Esc when in INSERT mode. The Irssi script provides this mapping by setting:

/set vim_mode_cmd_seq j

Another useful feature is the mode indicator, best used in conjunction with uberprompt.

From the README, the following common keybindings are supported:

  • Command mode: Esc <Ctrl-C>
  • Cursor motion: h l 0 ^ $ <Space> <BS> f t F T
  • History motion: j k gg G gg
  • Cursor word motion: w b ge e W gE B E
  • Word objects: aw aW
  • Yank and paste: C<y p P>
  • Change and delete: c d
  • Delete at cursor: x X
  • Replace at cursor: r
  • Insert mode: i a I A
  • Switch case: ~
  • Repeat change: .
  • Repeat: ftFT: ; ,
  • Registers: "a-"z "" "0 "* "+ "_
  • Line-wise shortcuts: dd cc yy
  • Shortcuts: s S C D
  • Scroll the scrollback buffer: Ctrl-E Ctrl-D Ctrl-Y Ctrl-U Ctrl-F Ctrl-B
  • Switch to last active window: Ctrl-6/Ctrl-^
  • Switch split windows: <Ctrl-W j Ctrl-W k>
  • Undo/Redo: u Ctrl-R

Get the script at:

SSD + GPT + grub2 + systemd

Summary of my new Arch setup optimised for SSD. See ArchWiki for more tweaks.


  • Specs: GA-EP45-DS3L, C2D E8400, 4GB DDR2, 512MB HD4850, 1x 640GB WD Black, 2x 1TB WD Green
  • Purchased: 120GB Intel 330 SSD

BIOS/UEFI settings

  • Firmware: EFI/UEFI instead of BIOS
  • SATA Mode: AHCI instead of IDE

Pre Installation

  • Partition: GPT instead of MBR

Arch Installation

  • Filesystem: ext2 for /boot; ext4 for the rest
  • fstab options: noatime, discard
  • Bootloader: GRUB2 instead of GRUB1/GRUB Legacy

Post Installation

  • Init: systemd instead of sysvinit
  • I/O scheduler: noop instead of cfq

Misc Output

systemd-analyze, gdisk, df, fstab, ls:

Udev: Changing SSD’s default (CFQ) I/O Scheduler

Courtesy of falconindy @ #archlinux

# set a larger readahead size
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/read_ahead_kb}="1024"
# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"

To verify:

$ cat /sys/block/sda/queue/scheduler
noop [deadline] cfq

ALSA: Switch audio output to USB Headset

I recently purchased a USB headset.
Here’s how to get it working with ALSA, manually and automatically.


(From ALSA ArchWiki)

Load module:

# modprobe snd_usb_audio

Verify that module is loaded:

$ lsmod | grep snd_usb_audio
snd_usb_audio          93519  3 

Find corresponding card ID:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 2: P780 [Plantronics GameCom 780], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

Set card ID as default audio device in ~/.asoundrc:

defaults.ctl.card 2
defaults.pcm.card 2

The manual method works fine if the headset is always plugged in.


It would be better if we could automatically change the default audio device based on whether the USB headset is plugged in or not. This can be achieved by using udev rules.

Add the following to /etc/udev/rules.d/00-local.rules:

# Set USB headset as default sound card when plugged in
KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"

# Restore default sound card when USB headset unplugged
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"

udev automatically detects changes to rules. However, you will need to unplug and replug the headset for changes to be be triggered.

Audio applications need to be restarted whenever default card changes. If anyone knows a way of switching audio devices without restarting applications (using ALSA, not Pulseaudio), please let me know.

DWM: A pretty statusbar

dwm uses xsetroot to pipe text into its statusbar.
By default, the statusbar does not support colours and does not support xbm icons.
You could get this functionality by using third party apps such as dzen with conky.

To get this functionality natively within dwm 6.0:

  • Patch your dwm config with jasonwryan’s statuscolors-6.0
  • Take a look at jasonwryan’s dwm-status script the dzen website for some ideas of what text can be piped
  • Follow Lokaltag’s tutorial to draw symbols into your favourite bitmap font.
  • Look at dzen’s icon packs for some ideas of what can be drawn.

Here’s what my statusbar currently looks like (click for full length image):

For the lazy, here’s how to get the statusbar to look like the above:

  1. Save font as ~/.fonts/terminus2.bdf:
  2. Update font cache:
  3. $ xset +fp ~/.fonts
    # fc-cache -fv
  4. Save script as ~/.dwm-statusbar.bash:
  5. Allow script to be executed:
    $ chmod +x ~/.dwm-statusbar.bash
  6. Apply jasonwryan’s statuscolors-6.0 patch
  7. Change font and statuscolors options in dwm/config.h:
    /* appearance */
    static const char font[]            = "-*-terminus2-medium-r-*-*-12-*-*-*-*-*-*-*";
    #define NUMCOLORS 6
    static const char colors[NUMCOLORS][ColLast][8] = {
      // border foreground background
      { "#073642", "#657b83", "#002b36" }, // 1 = normal (grey on black)
      { "#b58900", "#eee8d5", "#002b36" }, // 2 = selected (white on black)
      { "#dc322f", "#002b36", "#b58900" }, // 3 = urgent (black on yellow)
      { "#073642", "#839496", "#073642" }, // 4 = lightgrey on brightblack
      { "#073642", "#073642", "#002b36" }, // 5 = brightblack on black
      { "#073642", "#002b36", "#073642" }, // 6 = black on brightblack
  8. Add statusbar script to ~/.xinitrc:
    ~/.dwm-statusbar.bash &
  9. Restart X

Edit: This appears to be a better solution (I haven’t tried it yet, though):

Better dircolors with Solarized

When using the recommended Solarized colours in ~/.Xresources, dircolors output isn’t very distinguishable.

Here’s what it looks like:

Here’s what we want:

Copy the default dircolors to $HOME

$ dircolors -p > ~/.dir_colours

Make the following changes to ~/.dir_colours

--- .dir_colours.orig	2012-04-21 19:48:39.029808008 +1000
+++ .dir_colours	2012-04-21 18:28:38.645813921 +1000
@@ -68,8 +68,8 @@ TERM xterm-debian
 #NORMAL 00 # no color code at all
 #FILE 00 # regular file: use no color at all
 RESET 0 # reset to "normal" color
-DIR 01;34 # directory
-LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
+DIR 00;34 # directory
+LINK 00;36 # symbolic link. (If you set this to 'target' instead of a
  # numerical value, the color is as for the file pointed to.)
 MULTIHARDLINK 00 # regular file with more than one link
 FIFO 40;33 # pipe
@@ -85,7 +85,7 @@ STICKY_OTHER_WRITABLE 30;42 # dir that i
 OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
 STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
 # This is for files with execute permission:
-EXEC 01;32
+EXEC 00;32
 # List any file extensions like '.gz' or '.tar' that you would like ls
 # to colorize below. Put the extension, a space, and the color init string.
 # (and any comments you want to add after a '#')
@@ -184,19 +184,19 @@ EXEC 01;32
 .ogv 01;35
 .ogx 01;35
 # audio formats
-.aac 00;36 00;36
-.flac 00;36
-.mid 00;36
-.midi 00;36
-.mka 00;36
-.mp3 00;36
-.mpc 00;36
-.ogg 00;36
-.ra 00;36
-.wav 00;36
+.aac 00;33 00;33
+.flac 00;33
+.mid 00;33
+.midi 00;33
+.mka 00;33
+.mp3 00;33
+.mpc 00;33
+.ogg 00;33
+.ra 00;33
+.wav 00;33
 # 00;36
-.oga 00;36
-.spx 00;36
-.xspf 00;36 00;33
+.oga 00;33
+.spx 00;33
+.xspf 00;33

Finally, run the following line to append to the colours to ~/.bashrc or ~/.zshrc:

$ echo "eval $(dircolors ~/.dir_colours)" >> ~/.zshrc