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: http://cricfree.tv/sky-sports-1-live-stream.php. Screenshot of it in mplayer: http://ompldr.org/vZ2NubA.

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://0.0.0.0:1935
...

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://212.7.212.22:1935/lb/" -a "lb/" -f "LNX 11,2,202,251" -W "http://cdn.yycast.com/player/player.swf" -p "http://www.yycast.com" -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://212.7.212.22:1935/lb/" -a "lb/" -f "LNX 11,2,202,251" -W "http://cdn.yycast.com/player/player.swf" -p "http://www.yycast.com" -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://212.7.212.22:1935/lb/" -a "lb/" -f "LNX 11,2,202,251" -W "http://cdn.yycast.com/player/player.swf" -p "http://www.yycast.com" -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://95.211.186.227:1935/live/_definst_>
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://95.211.186.227:1935/live/_definst_" -a "live/" -f "LNX 11,2,202,251" -W "http://cdn.yycast.com/player/player.swf" -p "http://www.yycast.com" -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://95.211.186.227:1935/live/_definst_" -a "live/" -f "LNX 11,2,202,251" -W "http://cdn.yycast.com/player/player.swf" -p "http://www.yycast.com" -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 http://build.rockbox.org/data/rockbox-sansaclipzip.zip -O ~/downloads/rockbox-sansaclipzip.zip
    $ unzip ~/downloads/rockbox-sansaclipzip.zip -d /mnt/usb
  4. Extract the bootloader.
    $ wget http://download.rockbox.org/bootloader/sandisk-sansa/mkamsboot/linux-x86-64/mkamsboot -O ~/downloads/rbinstall/mkamsboot
    $ wget http://download.rockbox.org/bootloader/sandisk-sansa/clipzip/bootloader-clipzip.sansa -O ~/downloads/rbinstall/bootloader-clipzip.sansa
    $ wget http://mp3support.sandisk.com/firmware/clipzip/clipzip01.01.18.zip -O ~/downloads/clipzip_of.zip
    $ unzip ~/downloads/clipzip_of.zip -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?

What?

  • 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?

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

Why?
(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.

gist.io: Writing for hackers

Just recently heard of gist.io – a pastebin services that converts markdown formatted files from https://gist.github.com 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: https://github.com/shabble/irssi-scripts/tree/master/vim-mode

SSD + GPT + grub2 + systemd

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

Background

  • 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: https://gist.github.com/3107896

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

Courtesy of falconindy @ #archlinux

1
2
3
4
5
# 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.

Manually:

(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:

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

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

Automatically:

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:
    https://github.com/w0ng/dwm/blob/master/terminus2.bdf
  2. Update font cache:
  3. $ xset +fp ~/.fonts
    # fc-cache -fv
  4. Save script as ~/.dwm-statusbar.bash:
    https://github.com/w0ng/bin/blob/master/dwm-statusbar
  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:
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
    ...
    /* 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): https://bbs.archlinux.org/viewtopic.php?pid=1096029#p1096029

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--- .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
-.au 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
+.au 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
 # http://wiki.xiph.org/index.php/MIME_Types_and_File_Extensions
-.axa 00;36
-.oga 00;36
-.spx 00;36
-.xspf 00;36
+.axa 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