Raspberry PI – Static WIFI IP address

Problem

  •  Raspberry PI is configured using Wifi and DHCP by default (Jessie)

Solution

The solution is simple. Open the file /etc/dhcpcd.conf as root (sudo nano /etc/dhcpcd.conf)

At the end of the file, add the following lines:

interface wlan0
static ip_address=192.168.xxx.xxx/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

  • static ip_address: your desired IP address
  • static routers: your gateway
  • static domain_name _servers: your DNS server

Save the file and reboot:

sudo reboot

Fin.

Migrate MySQL to another server

Problem

  • You want to migrate a full MySQL database to another server

Setting

  • Debian/Ubuntu/Raspbian
  • Installed MySQL instance on both servers (sudo apt-get install mysql-server)
  • Root password

Solution

Backup

The basic call to backup a MySQL looks like this:

mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

In our case:

mysqldump -u root -pSTRONGROOTPASSWORD ––all-databases > backup.sql

(no space between -p and the password!)

Copy

scp backup.sql user@host:/home/user

Import

The basic call to import looks like this:

mysql -u root -p[root_password] [database_name] < backup.sql

In our case:

mysql -u root -pSTRONGROOTPASSWORD < backup.sql

Set debian system maintainer password

For the default installation of a MySQL on Debian, Ubuntu or Raspian, a system maintainer password is set by the package. It’s a different one for every instance. By importing the old database, the password for the new instance were overwritten. This is bad, because the MySQL will not start after reboot and other stupid things happen. So you have to restore the correct password. This is stored in /etc/mysql/debian.cnf. To get it do the following:

sudo cat /etc/mysql/debian.cnf | grep password
password = asdfadsfsdafadsgfadf
password = asdfadsfsdafadsgfadf

Setting the password:

mysql -u root -pSTRONGROOTPASSWORD

SET PASSWORD FOR ‘debian-sys-maint’@’localhost’ = PASSWORD(‘asdfadsfsdafadsgfadf’);

flush privileges;

quit;

Fin

 

Compiling Handbrake 0.10.5 on a Raspberry Pi 3

This is a follow up on my benchmarks for the Raspberry Pi 2 (see here).

Question

  1. How fast is software x264 encoding now on a PI 3?

Test Object

To answer the questions I compiled and benchmarked Handbrake on a PI 3. As test videos I chose a full HD video, because nowadays is useless to encode in DVD quality for big screens.

Compile Handbrake 0.10.5

sudo apt-get update && sudo apt-get upgrade
mkdir handbrake
cd handbrake
wget https://handbrake.fr/rotation.php?file=HandBrake-0.10.5.tar.bz2
bzip2 -d HandBrake-0.10.5.tar.bz2
tar xvf HandBrake-0.10.5.tar

sudo apt-get install subversion yasm build-essential autoconf libtool zlib1g-dev libbz2-dev libfribidi-dev intltool libglib2.0-dev libdbus-glib-1-dev libgtk-3-dev libgudev-1.0-dev libwebkit-dev libnotify-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libvorbis-dev libass-dev libsamplerate-dev libogg-dev libtheora-dev libappindicator-dev cmake libx264-dev libmp3lame-dev pkgconf

cd HandBrake-0.10.5/

Now you have to disable the asm support.

Add –disable-asm in ./HandBrake-0.10.2/contrib/x264/module.defs. It should look like this:

X264.CONFIGURE.extra += –disable-asm –disable-lavf –disable-ffms –disable-avs –disable-swscale –disable-gpac –disable-lsmash –disable-cli

And now compiling:

./configure
cd build
make

I ran into an error quite fast while building M4:

./stdio.h:477:1: error: ‘gets’ undeclared here (not in a function)
_GL_WARN_ON_USE (gets, “gets is a security hole – use fgets instead”);
^

This is the fix:

sed -i -e’/gets is a security/d’ ./contrib/m4/m4-1.4.16/lib/stdio.in.h

And once again

make

Compile Handbrake on a Raspberry PI 3
Compile Handbrake on a Raspberry PI 3

Benchmark

For the benchmark i used the “normal” preset (q20, b160, Main profile). The PI was not overclocked.

The performance was overall disappointing but I expected that. As an average frame rate for a full HD video (source: 1920×1080 no croop, 29fps, 7500kbps) i got 2.6fps. This is pretty ok for a PI, but a waste of time.

So, you should not use a PI 3 for software encoding with Handbrake.

Fin.

Raspberry PI – Configure Static IP with /etc/network/interfaces or dhcpcd

[Update] Changed order of the solutions due to comments. Added warning to solution 2.[/Update]

[A simple solution for Wifi can be found here.]

Problem

  • In the default config the Raspberry PI 3 is configured using Wifi and DHCP (Jessie)
  • If you want to use wired ethernet with a static IP config, you have to reconfigure

Solution 1 – dhcpcd

Open dhcpcd.conf

sudo nano /etc/dhcpcd.conf

A valid config would look like this:

interface eth0
static ip_address=192.168.2.77/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

Restart networking and the work is done:

sudo service networking restart

Solution 2 – /etc/networking/interfaces (get rid of the dhcpcd service)

Warning: This solution is only useful, if you do not depend on dhcpcd, e.g. in a wired static IP environment.

Open the interfaces file with

sudo nano /etc/network/interfaces

A correct config would look like this:

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.2.77
netmask 255.255.255.0
gateway 192.168.2.1
dns-nameservers 192.168.2.1

Now you have to stop and disable dhcpcd, because it will make your config useless:

sudo service dhcpcd stop

sudo systemctl disable dhcpcd

Restart networking and the work is done:

sudo service networking restart

Fin

M4 – stdio.h:477

Problem

While compiling M4 you get this error

./stdio.h:477:1: error: ‘gets’ undeclared here (not in a function)
_GL_WARN_ON_USE (gets, “gets is a security hole – use fgets instead”);

Solution

sed -i -e’/gets is a security/d’ /m4-1.4.16/lib/stdio.in.h

 

Raspberry PI – Boot from USB drive or stick

Problem

  • You want to use a USB drive or stick to store the OS and user data because it is more reliable than a normal SD card.
  • You only have a Windows based computer

Solution

The Raspberry can not boot from USB, but it is possible to transfer the root to the USB drive.

The solution consists of 4 steps:

  1. Extract the image from the SD-Card
  2. Copy image on USB drive/stick
  3. Change boot.txt
  4. Delete old root partition

Step 1

Install and configure the OS (Raspbian). After you finished this, remove the SD card from the Raspberry and insert it into your windows computer.

To extract the image from the SD, i used Win32 Disk Imager (Download). It can extract and write images. Just store the image on your hard disk.

disk imager

Step 2

Use the Win32 Disk Imager to write the image to the USB drive. After that, you have two different drives with the identical partition layout.

Step 3

Insert SD card and plug the USB drive in the Raspberry PI. With blkid you see the two identical layout of both disks. mmcblk0p is the SD card, sda the USB drive.

/dev/mmcblk0p1: SEC_TYPE=”msdos” LABEL=”RECOVERY” UUID=”47BE-8134″ TYPE=”vfat” PARTUUID=”000709f6-01″
/dev/mmcblk0p5: LABEL=”SETTINGS” UUID=”4b288679-4f9e-47bc-b72e-5989629d5e7f” TYPE=”ext4″ PARTUUID=”000709f6-05″
/dev/mmcblk0p6: SEC_TYPE=”msdos” LABEL=”boot” UUID=”67B4-B99A” TYPE=”vfat” PARTUUID=”000709f6-06″
/dev/mmcblk0p7: LABEL=”root” UUID=”0b00e3d6-6726-4db3-845d-335e3c5b548e” TYPE=”ext4″ PARTUUID=”000709f6-07″
/dev/sda1: SEC_TYPE=”msdos” LABEL=”RECOVERY” UUID=”47BE-8134″ TYPE=”vfat” PARTUUID=”000709f6-01″
/dev/sda5: LABEL=”SETTINGS” UUID=”4b288679-4f9e-47bc-b72e-5989629d5e7f” TYPE=”ext4″ PARTUUID=”000709f6-05″
/dev/sda6: SEC_TYPE=”msdos” LABEL=”boot” UUID=”67B4-B99A” TYPE=”vfat” PARTUUID=”000709f6-06″
/dev/sda7: LABEL=”root” UUID=”0b00e3d6-6726-4db3-845d-335e3c5b548e” TYPE=”ext4″ PARTUUID=”000709f6-07″

The interesting partition is the root partition. We have to tell the boot system, where the new root partition is located. Get the PARTUUID from the root partition (here from sda7): PARTUUID=”000709f6-07″

Open the /boot/cmdline.txt and change the root like this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=PARTUUID=000709f6-07 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

Step 4

If you would reboot now, the Raspberry would mount the SD card root to / because it’s the first partition he finds with the given ID. Thus you have to delete the old root partition.

For this i used gparted. You also can use fdisk like in this tutorial.

Step 5

Reboot

Fin

 

 

Chuck Versus Handbrake on a Raspberry Pi 2

[Update: A new post is online for Handbrake 0.10.5 and the Raspberry PI 3]

(based on the work of the tech-note-pad and my own for the version 0.9.9)

Questions

  1. How fast is software x264 encoding on a PI 2?
  2. Does grain reduce fps?

Test Object

To answer the questions I benchmarked Handbrake on a PI 2. As test videos I chose two episodes of the series Chuck because the picture quality of the Blu-rays (1080p) is really poor (grain). I used S2.E11 as a standard episode and S2.E12 (Chuck Versus the Third Dimension) since with is the one episode with a proper picture quality (no grain).

Installation

user@localhost:~$ mkdir handbrake
user@localhost:~$ cd handbrake
user@localhost:~$ wget https://handbrake.fr/rotation.php?file=HandBrake-0.10.2.tar.bz2
user@localhost:~$ bzip2 -d HandBrake-0.10.2.tar.bz2
user@localhost:~$ tar xvf HandBrake-0.10.2.tar

user@localhost:~$ sudo apt-get update && sudo apt-get upgrade

user@localhost:~$ sudo apt-get install subversion yasm build-essential autoconf libtool zlib1g-dev libbz2-dev libfribidi-dev intltool libglib2.0-dev libdbus-glib-1-dev libgtk-3-dev libgudev-1.0-dev libwebkit-dev libnotify-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libvorbis-dev libass-dev libsamplerate-dev libogg-dev libtheora-dev libappindicator-dev cmake libx264-dev libmp3lame-dev

(CMake is not necessary but the integrated build process of cmake would take some extra time)

Add –disable-asm in ./HandBrake-0.10.2/contrib/x264/module.defs

user@localhost:~$ sudo ./configure
user@localhost:~$ cd ./build
user@localhost:~$ sudo make
#Make nerd yoga. It takes about one hour.
#The GUI-Version can be found in ./gtk/src
#Handbrake-CLI can be found in the build folder

#If you want to install
user@localhost:~$ sudo make install

handbrake

Benchmark Settings

Setting 1: Main4.0 x264-Preset=VeryFast (Default Handbrake Normal Preset)
Setting 2: Main4.0 x264-Preset=VerySlow
Setting 3: High4.1 x264-Preset=Medium (Default Handbrake High Preset)
Setting 4: High4.1 x264-Preset=VerySlow (Best picture quality)

For every setting:
Video: Tune=Film RF=24
Audio: AAC br=160 DolbyProLogicII + Subtitle

The Raspberry PI 2 is overclocked with the preset “medium” (900MHz).

Results

For Chuck S2.E11:

(in fps) Setting 1 Setting 2 Setting 3 Setting 4
PI 2 3,1 0,26 0,65 0,22
i7 4700MQ @2,4GHz 49,5 7,9 17,3 6,7
i7 3517U @1,9GHz 20,2 2,2 5,8 2,0
Intel Core 2 Duo (T9400) @2,53GHz 11,9 1,3 3,8 1,2
Intel Core 2 Duo (E8400) @3,0GHz 14,9 1,5 4,2 1,6

For Chuck S2.E12:

(in fps) Setting 1 Setting 2 Setting 3 Setting 4
PI 2 3,6 0,47 0,91 0,31
i7 4700MQ @2,4GHz 58,9 11,1 25,7 8,6
i7 3517U @1,9GHz 22,0 2,7 6,9 2,4
Intel Core 2 Duo (T9400) @2,53GHz 16,6 1,9 5,0 2,0
Intel Core 2 Duo (E8400) @3,0GHz 18,5 2,3 5,8 2,3

Answers

  1. The PI 2 could be used for software x264 encoding, but it shouldn’t. If you really like to encode something with the PI 2 you should have a look for the hardware encoding using omx/gstreamer or omxtx.
  2. Yes, grain reduces fps and increases file size if you choose constant quality.