Sunday, 16 June 2013

Encoding camera video clips to small decent quality files

I like taking photographs, and I often cary a camera with me. I however rarely use my camera for filming video. Video clips doesn't mean that much to me, and I don't require a lot of quality from them. I just want clips that looks decent with a minimal file size. For that reason I always re-encode the few clips I do occasionally film to ensure I get some relatively small files with a quality I personally find acceptable. The best way to do that is in my opinion with FFmpeg. There is different ways to get FFmpeg installed depending on operating system, but on OS X, one of the easiest ways is probably to install in through MacPorts. The command line I most often use when re-encoding video is simply:

ffmpeg -i {input.ext} -c:v libx264 -b:v 3072k -vf "scale=trunc(oh*a/2)*2:720" -c:a aac -b:a 96k -ar 22050 -ac 1 -strict -2 {output}.mp4

-i input file to re-encode.
-c:v re-encoded video format. In this case libx264 will encode to h264
-b:v bit rate for encoded video. Higher value means better quality.
-vf scale the video to 720 horizontal lines. The width will be calculated to maintain aspect ratio*.
-c:a re-encoded audio format. In this case aac will encode to aac.
-b:a bit rate for encoded audio. Higher value means better quality.
-ar sample rate for audio. Higher value means better quality.
-ac number of channels. 1 means mono.
-strict -2 a parameter that for some reason is required as libx264 is exparimental.

(*)It takes output width (oh), multiplies it by aspect ratio (a), divides by 2, truncates digits after decimal point and multiplies by 2. It guarantees that resulting height is divisible by 2.

Friday, 14 June 2013

Set audio/mpeg filter in Wireshark

In the filter text field simply write http.content_type == "audio/mpeg" and press Apply.

Hide Bootcamp partition in OS X

In terminal write: diskutil info BOOTCAMP
Look for the Volume UUID.
Edit /etc/fstab and add: UUID={Volume UUID} none ntfs ro,noauto 0 0

Disable strict SSH host checking on OS X

To disable strict host checking on OS X, create or edit ~/.ssh/config and add the following lines:

Host {IP Address}
   StrictHostKeyChecking no

A typical example could be:

Host 192.168.1.*
   StrictHostKeyChecking no

Saturday, 1 June 2013

Install Music Player Daemon on the Raspberry Pi

To play music on the Raspberry Pi, a music player is needed. A lot of people are using XBMC for that. I Personally prefer Music Player Daemon or just MPD. One way to install MPD on the Pi is simply to write sudo apt-get install mpd. This will however often install an older version. The best way to get the newest version is to compile it yourself from source. Head over to to download the newest stable version.

The easiest way to download it, is probably just to ssh into you Pi from a computer (if using Windows Putty is an excellent ssh client) and then write:

After download has completed, extract it using tar:
tar -zxvf mpd-{version} (or tar -jxvf mpd-{version}.tar.bz2)

Make sure that all the required libraries and build tools are installed. The INSTALL file has a list. If only MP3, FLAC and streaming support through the standard sound driver is needed, install required libraries by typing:
sudo apt-get install libboost-all-dev libasound2-dev libmad0-dev libid3tag0-dev libflac-dev libflac++-dev libglib2.0-dev libcurl4-openssl-dev libmms-dev

Now in the folder where the MPD source was extracted, configure, compile and install by typing:
sudo make install

Before starting MPD for the first time, MPD needs to be configured.

In home folder create a folder named .mpd (mkdir ~/.mpd).
Copy/rename doc/mpdconf.example from the MPD source directory to .mpd/mpd.conf (cp {mpd-source-location}/doc/mpdconf.example ~/.mpd/mpd.conf).
Then create a folder named playlists in the newly created .mpd folder (mkdir ~/.mpd/playlists).
Finally edit the .mpd/mpd.conf file and enable/changes the following settings.

music_directory            "/media/NAS/Music" #location of music
playlist_directory          "~/.mpd/playlists"
db_file                        "~/.mpd/database"
pid_file                       "~/.mpd/pid"
bind_to_address           "any"
audio_output {
        type                   "alsa"
        name                  "My ALSA Device"
        device                 "hw:1,0"           # Keep 0,0 if using the Pi analog audio
        format                "44100:16:2"
        mixer_type          "software"
        mixer_device       "default"
        mixer_control      "PCM"
        mixer_index        "0"

MPD can now be started by typing mpd in the terminal. To actually control MPD, a remote control is needed. Some can be found in Google Play and Apple App Store.

Mount NAS on boot on the Raspberry Pi

Some time ago I bought a Raspberry Pi to use as a music player. All music is located on a NAS drive. To auto mount a NAS drive on the Pi when it boots, do the following.

Ensure cifs-utils is installed, it should be by default, otherwise simply write:
sudo apt-get install cifs-utils.

Make a directory to mount to (e.g sudo mkdir /media/NAS).

Edit /etc/fstab (sudo nano /etc/fstab) and add the line that will mount the NAS share folder when booting. In my setup the line looks like this:

//NAS/share /media/NAS cifs username=read,password=read,workgroup=WORKGROUP,auto,user 0 0

The share name, username, password and possibly workgroup will of course need to be adjusted to match the configuration of a given NAS.