18 January 2013

BASH: Single-Quotes inside a Single-Quoted String

In bash, to escape some characters for the command-line arguments properly, you can use single quotes. E.g.,
$ file 'Some # Weird File Name.odt'
But how about the single quote characters? There are several methods. I found the following ways most convenient.

(1) Replace ' with '\''

Break out of the quoted string, and escape the single quote alone.
 $ file 'My wife'\''s file.txt'
(2) Replace ' with '"'"'

Same idea, but different way of escaping the single quote.
$ file 'My wife'"'"'s file.txt'
So, in Python, you can use:
s = string.replace("'", "'\"'\"'")
or in PHP,
s = str_replace("'", "'\"'\"'", string);

17 January 2013

MPlayer & MEncoder: Manipulating Audio Channels

MPlayer provides powerful controls to manipulate different audio channels.

During playback,

  • ( and ) keys: Adjust audio balance in favor of left/right channel.
  • # key: Cycle through the available audio tracks.
You can add, remove, route, or copy audio channels with the -af channels=nch[:nr:from1:to1:from2:to2:from3:to3:...] option. For example, if there are 2 channels, and you want to copy channel 0 to channel 1 (and thus abandon the original channel 1), you can use -af channels=2:2:0:0:0:1.

You can even mix the channels with specified proportions with the -af pan=... option. Unfortunately, the suboptions are naturally much more complicated. Basically you can specify a 2D matrix to indicate the amount of each source channel that will be mixed to the destination channel.

References: