Friday, 6 September 2013

convert large mov file from iphone to avi (libx264) for storage

use exiftool to inspect EXIF info of the jpe and mov file
exif


----------------original:::------------------------------------------
ExifTool Version Number         : 8.60
File Name                       : IMG_0014.MOV
Directory                       : .
File Size                       : 19 MB
File Modification Date/Time     : 2013:07:19 12:03:22-10:00
File Permissions                : rw-r--r--
File Type                       : MOV
MIME Type                       : video/quicktime
Major Brand                     : Apple QuickTime (.MOV/QT)
Minor Version                   : 0.0.0
Compatible Brands               : qt
Movie Data Size                 : 19979709
Movie Header Version            : 0
Modify Date                     : 2013:07:19 22:03:21
Time Scale                      : 600
Duration                        : 7.27 s
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Track Header Version            : 0
Track Create Date               : 2013:07:19 22:03:13
Track Modify Date               : 2013:07:19 22:03:21
Track ID                        : 1
Track Duration                  : 7.27 s
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 1920
Image Height                    : 1080
Graphics Mode                   : ditherCopy
Op Color                        : 32768 32768 32768
Compressor ID                   : avc1
Source Image Width              : 1920
Source Image Height             : 1080
X Resolution                    : 72
Y Resolution                    : 72
Compressor Name                 : H.264
Bit Depth                       : 24
Video Frame Rate                : 27.011
Camera Identifier               : Back
Frame Readout Time              : 28512 microseconds
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2013:07:19 22:03:13
Media Modify Date               : 2013:07:19 22:03:21
Media Time Scale                : 44100
Media Duration                  : 7.31 s
Media Language Code             : und
Balance                         : 0
Handler Class                   : Data Handler
Handler Vendor ID               : Apple
Handler Description             : Core Media Data Handler
Audio Channels                  : 1
Audio Bits Per Sample           : 16
Audio Sample Rate               : 44100
Audio Format                    : chan
Model                           : iPhone 4S
Software Version                : 6.1.3
Create Date                     : 2013:07:20 08:03:13+10:00
Make                            : Apple
Handler Type                    : Metadata Tags
Make (und-AU)                   : Apple
Creation Date (und-AU)          : 2013:07:20 08:03:13+10:00
Software (und-AU)               : 6.1.3
Model (und-AU)                  : iPhone 4S
Avg Bitrate                     : 22 Mbps
Image Size                      : 1920x1080
Rotation                        : 90

-------------------------------------------------------------------------

ffmpeg -i IMG_0014.MOV -vcodec libx264 -acodec copy IMG.avi

ExifTool Version Number         : 8.60
File Name                       : IMG.avi
Directory                       : .
File Size                       : 7.3 MB
File Modification Date/Time     : 2013:09:06 22:12:03-10:00
File Permissions                : rw-r--r--
File Type                       : AVI
MIME Type                       : video/x-msvideo
Frame Rate                      : 24
Max Data Rate                   : 7.748 kB/s
Frame Count                     : 176
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 24
Video Frame Count               : 176
Quality                         : Default
Sample Size                     : Variable
Image Width                     : 1920
Image Height                    : 1080
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 6220800
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Audio Codec                     : .
Audio Sample Rate               : 43.07
Audio Sample Count              : 315
Encoding                        : AAC
Num Channels                    : 1
Sample Rate                     : 44100
Avg Bytes Per Sec               : 7934
Bits Per Sample                 : 16
Date Created                    : 2013:07:20T08:03:13+1000
Software                        : Lavf54.29.104
Duration                        : 7.33 s
Image Size                      : 1920x1080


------------------------------------------------------------------------
ffmpeg -i IMG_0014.MOV -vcodec libx264 -acodec copy -metadata "tag=value" IMG_tag_value-.avi
ExifTool Version Number         : 8.60
File Name                       : IMG_tag_value.avi
Directory                       : .
File Size                       : 7.3 MB
File Modification Date/Time     : 2013:09:06 22:17:20-10:00
File Permissions                : rw-r--r--
File Type                       : AVI
MIME Type                       : video/x-msvideo
Frame Rate                      : 24
Max Data Rate                   : 7.748 kB/s
Frame Count                     : 176
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 24
Video Frame Count               : 176
Quality                         : Default
Sample Size                     : Variable
Image Width                     : 1920
Image Height                    : 1080
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 6220800
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Audio Codec                     : .
Audio Sample Rate               : 43.07
Audio Sample Count              : 315
Encoding                        : AAC
Num Channels                    : 1
Sample Rate                     : 44100
Avg Bytes Per Sec               : 7934
Bits Per Sample                 : 16
Date Created                    : 2013:07:20T08:03:13+1000
Software                        : Lavf54.29.104
Duration                        : 7.33 s
Image Size                      : 1920x1080


this is not what i want
------------------------------------------------------------------------
ffmpeg -i IMG_0014.MOV -vcodec libx264 -acodec copy -map_metadata 0  IMG_map_matadata_0.avi

ExifTool Version Number         : 8.60
File Name                       : IMG_map_matadata_0.avi
Directory                       : .
File Size                       : 7.3 MB
File Modification Date/Time     : 2013:09:06 22:22:04-10:00
File Permissions                : rw-r--r--
File Type                       : AVI
MIME Type                       : video/x-msvideo
Frame Rate                      : 24
Max Data Rate                   : 7.748 kB/s
Frame Count                     : 176
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 24
Video Frame Count               : 176
Quality                         : Default
Sample Size                     : Variable
Image Width                     : 1920
Image Height                    : 1080
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 6220800
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Audio Codec                     : .
Audio Sample Rate               : 43.07
Audio Sample Count              : 315
Encoding                        : AAC
Num Channels                    : 1
Sample Rate                     : 44100
Avg Bytes Per Sec               : 7934
Bits Per Sample                 : 16
Date Created                    : 2013:07:20T08:03:13+1000
Software                        : Lavf54.29.104
Duration                        : 7.33 s
Image Size                      : 1920x1080

--------------------------------------------------------------------
ffmpeg -i IMG_0014.MOV -vcodec libx264 -acodec copy  IMG_no.avi

ExifTool Version Number         : 8.60
File Name                       : IMG_no.avi
Directory                       : .
File Size                       : 7.3 MB
File Modification Date/Time     : 2013:09:06 22:46:20-10:00
File Permissions                : rw-r--r--
File Type                       : AVI
MIME Type                       : video/x-msvideo
Frame Rate                      : 24
Max Data Rate                   : 7.748 kB/s
Frame Count                     : 176
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 24
Video Frame Count               : 176
Quality                         : Default
Sample Size                     : Variable
Image Width                     : 1920
Image Height                    : 1080
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 6220800
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Audio Codec                     : .
Audio Sample Rate               : 43.07
Audio Sample Count              : 315
Encoding                        : AAC
Num Channels                    : 1
Sample Rate                     : 44100
Avg Bytes Per Sec               : 7934
Bits Per Sample                 : 16
Date Created                    : 2013:07:20T08:03:13+1000
Software                        : Lavf54.29.104
Duration                        : 7.33 s
Image Size                      : 1920x1080

Wednesday, 4 September 2013

Use i3wm in Linux ( with dual screen and virtualbox)

Tiling window manager seems to be a good trend. the reason is: you don't have to go to a particular workspace and maximize the window

add
exec --no-startup-id nm-applet
in ~/.i3/config , so that network manager will be displayed in the tray.
two problems here:
1 the taskbar is not displayed properly
2 sometimes the autoscroll in chromium is not working.

-------------let virtualbox working perfectly with i3 with dual screen--------------

1. go to virtualbox->file->preference->input-> untick auto capture keyboard. (If unticked, the windows system will have the previlege to use win key, resulting in the failure of switching between workspaces)
2. put two screen of virtualbox separately on two monitors, each monitor is on different workspace (for example, monitor 1 has workspace 5, that display one virtualbox screen, monitor 2 has workspace 6, which display another virtualbox screen)
3. disable seamless mode, maximum mode.
4. configure ~/.i3config
add
bindsym $mod+z workspace 7;workspace 8
bindsym $mod+x workspace 3;workspace 4
bindsym $mod+c workspace 5;workspace 6
bindsym $mod+shift+z workspace 1;workspace 2

# for merge into new window
bindsym $mod+M focus left;split v;layout stacking;focus right;move left
bindsym $mod+comma focus right;split v;layout stacking;focus left;move right
WARNING: do not add any space to the digits, otherwise the workspace name will be 2[space] rather than 2. semicolon means to separate commands.
5. $mod+shift+c to reload
6. run
# VBoxManage setextradata global GUI/Customizations noMenuBar,noStatusBar


to disable the menubar and status bar in virtualbox windows

now every time we press $mod+c, we come into windows world, when we press $mod+z, we go back to i3 world.  
7. sloving keybinding problem: now the master key in i3wm is windows logo key, which conflicts with some shortcut within windows. (e.g., win+e=explorer, win+left arrow=place window by half screen, win+l=lock pc) for the window move, one can still keep using win key + numbers at number keyboard when numlock is disabled. To make full use of win logo key in guest machine, one has to map the win key to some idle keys (e.g., application key next to right control). it is not easy to change the regstration, we decided to use a software called Sharpkeys (becareful when using it 1. FROM on the left means the key that will be pressed, To on the right means the original function that one needs to be mapped out 2. if messed up, it is better clean all out , log in&out, then reconfiguire, because the modifided key doesn't hold the default function, which will be confusing)
Alternative solution to 7:

the basic idea is that the left windows logo key is used for i3wm, while the right one are still used on the right. However, I had some problem by make the keybinding changed on default.
the problem was if i put the following in ~/.Xmodmap
remove Mod4 = Super_R
add Mod3 = Super_R

and put
exec i3 --force-xinerama
if [ -s ~/.Xmodmap ]; then
    xmodmap ~/.Xmodmap
fi

in ~/.xinitrc, it doesn't change the key bindings at all (the reason I didn't delete this part is to remind myself of the wrong way). the way to work around it is to add the following to ~/.xinitrc

xmodmap ~/.Xmodmap &&
exec i3 --force-xinerama
if one does not put --force-xinerama, the two screens will be considered as one workspace, which may be good for some people. the we assign the left logo key as i3 mod, right one used for windows.

[chenming@T5500 ~]$ xmodmap
xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        Super_R (0x86)
mod4        Super_L (0x85),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

8. Problems on changing host machine:
when guest is set as 64bit, after copy the file to another host, it says

VT-x/AMD-V hardware acceleration has been enabled, but is not operational. 
Certain guests (e.g. OS/2 and QNX) require this feature.

Please ensure that you have enabled VT-x/AMD-V properly in the BIOS of your
host computer.

this problem can be solved by enabling Intel Virtualization Technology in bios (but remember, may be only this one, nothing else. this happens for my dell 960 pc.

this method is quite good to integrate the performance of dual screen. as i3wm has to enable xinerama, which treats two monitor as separate worspaces. using the above mentioned way could "integrate" two screen together.

Tips: use $mod+d to run a command in a new window, so you don't have to launch an application from a terminal always.
   It is better not use shift or alt key when changing into windows workspace. It is found that the shift key can be "sticked" after switch so that single clicking the icon in the taskbar becomes not focusing the window, but open another new one.

#-----------------------------------------
make ati drivers work
in /usr/src/linux/.conf

# CONFIG_DRM_LOAD_EDID_FIRMWARE is not set
CONFIG_DRM_TTM=m         # this is newly added

#
# I2C encoder or helper chips
#
# CONFIG_DRM_I2C_CH7006 is not set
# CONFIG_DRM_I2C_SIL164 is not set
# CONFIG_DRM_I2C_NXP_TDA998X is not set
# CONFIG_DRM_TDFX is not set
# CONFIG_DRM_R128 is not set
CONFIG_DRM_RADEON=m         # this is newly added
# CONFIG_DRM_RADEON_UMS is not set
# CONFIG_DRM_NOUVEAU is not set


this is equivalent to
Processor type and features --->
<*> MTRR (Memory Type Range Register) support
Device drivers --->
   Graphics support --->
   <M> /dev/agpgart (AGP Support) --->
      (The agpgart option is not present on 64-bit kernels; just choose your chipset support.)
      <M> Intel 440LX/BX/GX, I8xx and E7x05 support
      (Enable your chipset instead of the above.)
   <M> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
      <M> (Select your graphics card from the list)

at manual setup
#---------------------------------
can not find rxvt.
install rxvt



-----------------------change i3 as default manager-----------------
put
exec i3

in

~/.xinitrc

actually .xinitrc is the configureation file to specify which wm or de one wants to 

# -----------------add module on boot---
echo 'modules="dbus"' >>/etc/conf.d/modules
#---------------------------------------------


 ------- use mod+printscreen to cropscreen and save ----------------- 
Put the following lines in ~/.i3/config

bindsym  --release $mod+p exec --no-startup-id ~/Dropbox/scripts/scrot_s_2
bindsym  --release $mod+Print exec scrot -s -e 'mv $f ~/Pictures '

the content in ~/Dropbox/scripts/scrot_s_2 are

#!/bin/bash
scrot -s '%Y-%m-%d--%s_$wx$h_scrot.png' -e 'mv $f ~/Pictures'

--------------Make USB 2.0 work on client Windows--------------
1. install Virtualbox Guest Additions in the windows client
2. install Virtualbox extention pack from windows host. this can be done by executing

# emerge -av virtualbox-extpack-oracle
However, it is found that sometimes the installed atom can not be identified by Virtualbox system, as one can not see anything from File->preference->extentions. The way to solve this problem is to download the extention file from website and import the package from extention tab. Then the system will notice one extention has been installed.

--------------allow two virtual machine communicate-------------
There are three methods
Method 1:
(a) Run the following command
VBoxManage dhcpserver add --netname intnet --ip 10.0.1.1 --netmask 255.255.255.0 --lowerip 10.0.1.2 --upperip 10.0.1.200 --enable
(b) change the network adaptor into internal network, and make sure the name of the network is intnet.
(c) if one wants to have public access, e.g., internet, another adapter can be added with NAT network
The disadvantage of this method is the host computer can not access virtual machine at all.

Method 2
(a) choose


1.  make sure to reinstall nvidia and virtualbox after kernel update

my configureation in ~/.xinitrc is as follows
xmodmap ~/.Xmodmap &&
exec i3  --force-xinerama

eval "$(dbus-launch --sh-syntax --exit-with-session)"
export XMODIFIERS="@im=fcitx"
export QT_IM_MODULE=<module>
export GTK_IM_MODULE=<module>

every time I have to run xrdb ~/.Xresources to get the configuration of xterm right. However, sometimes it is needed to use win+shift+r to reload the i3wm as new terminal can not be generated by win+enter. Usually for the second time, everything would be fine.

Every time once new kernel is update, one needs to rebuild nvidia and virtualbox driver, respectively, after the new kernel gets booted.


For the nvidia driver one should do:
emerge -av --quiet-build=y nvidia-drivers

To check the status of the nvidia driver, one can do the following as root.
#journalctl -b |grep "nvidia"
#find /lib/modules -type f -name "nvidia.ko" -print
#eselect kernel list
see http://forums.gentoo.org/viewtopic-p-7591752.html#7591752 for details

If the above things were not done, one may not be able to go to x server using startx.

For the virtualbox, one should run
emerge -1 @module-rebuild
for m in vbox{drv,netadp,netflt}; do modprobe $m; done

Later after version 4.3.18, virtualbox has changed its lisence into PUEL. To further update this, one needs to do
ACCEPT_LICENSE="PUEL" emerge -av virtualbox-bin



-----------------map window key in guest to menukey-----------------
i3wm takes window key as the control key. this is a bit problematic for the guest windows as it is usual to use window key to map the windows.
This problem can be get around by map the win function in guest to other unused key, for example menukey. by using AutoHotkey app. only one liner in the configuration file is able to accomplish this:

Appskey::LWin

Remember to reload the configuration after putting in the mapping.


-----------------dual task bar in the guest windows-----------------
It is very normal to work in linux host in one screen, while windows guest in the other.
However, it is found that it is quite annoying when the guest windows doesn't have the window you want to see, to maximize the winodw, one has to go to the guest screen with task bars to nomalize it.
This issue can be convinently solved by installing dual monitor task bar, an open source application.
after the install, the window displayed in the specific screen will be listed in the bars.
n.  make trackpad less sensitive
following http://askubuntu.com/questions/483707/14-04-touchpad-is-too-sensitive
xinput set-prop "ETPS/2 Elantech Touchpad" "Synaptics Finger" 50 90 255
xinput set-prop "ETPS/2 Elantech Touchpad" "Synaptics Noise Cancellation" 20 20





Tuesday, 3 September 2013

notes on installing gentoo with linux kernel 3.10 on toshiba laptop

When you learn Red Hat, you learn Red Hat, when you learn debian, you learn debian, when you learn Slackware/gentoo, you learn Linux

This is one of the reasons I decided to swap into slackware and gentoo.

different from mainstream linux which provides intall guides and be able to boot, gentoo has to be installed by chrooting from a working distro. now there are three stages to start from. however, it is suggested to be started from the stage three, as one didn't miss too much for the first two stages, together with the fact that it is very time consuming for the first two stages. I decided to start from the stage 3.

I used 


as installation guidance. it is very straightforward

here I just made some notes on the things that are be aware of during the installation:

1. it is suggested from the manual that one use minimal cd to install which provides all the required tools for compiling. However, I realized that using this approach can not connect to wifi still. therefore, I decided to use systemrescue cd and ubuntu. it turns out that both are almost the same, if one follows the instruction neatly.

2. it is also suggested from the manual that one separate /boot with /. i did that for my install. however, from the web, i do found that it is not necessary to do so if one don't want to. I will not install that in the next run.

3. commands

mount /dev/sda2 /mnt/gentoo
cd /mnt/gentoo/
mount -t proc proc /mnt/gentoo/proc   # required

it is still not clear why this is needed.


mount -o rbind /dev /mnt/gentoo/dev
mount -o rbind /sys /mnt/gentoo/sys   # needed

this two are very important --rbind sets /mnt/gentoo/dev to /dev recursively, so that the /dev at guest gentoo is equivalent to the host /dev. this is very important at the very beginning, because thereare not too much device working in the gentoo installation. also it is important because the linking file can point to the target properly

cp -L /etc/resolv.conf /mnt/gentoo/etc/
copy dns info

chroot /mnt/gentoo /bin/bash

remember once we rescue a crashed system (like scientificlinx) we use another medium to boot the pc and gain the root priviliage of the broken system and to work further.

source /etc/profile
export PS1="(gentoo) $PS1"

then we just follow the instruction to finish the installation. 

but the trouble part is how to install wifi driver in gentoo linux? mine is rtl8188. I tried to make driver downloaded from both rtl website and backports. but they all failed to install. (something like autoconf.h file do not exist any more. for backports, it is installed properly, but still may not be able to work) 
  later on I understood that after kernel 3. 8192 driver has been integrated into the kenel as modual. therefore, one has enable

CONFIG_RTLWIFI=m
CONFIG_RTL8192CE=m

at /usr/src/linux/.config file.

and recompile and install.

after that one still need

emerge linux-firmware 

to automatically find the driver

also one needs

ln /etc/init.d/net.lo /etc/init.d/net.wlp2s0
(wlp2s0 is the wifi name, which is not wlan0 as usual)

then one can use command 
/etc/init.d/net.wlp2s0 start
/etc/init.d/net.wlp2s0 restart

some useful commands for wifi
ifconfig wlp2s0 up
ethtool -i wlp2s0
iw wlp2s0 scan 
iwlist scan

other commands used during install
emerge htop
emerge net-wireless/wireless-tools
emerge app-editors/vim
emerge sys-apps/pciutils   # get ispci
emerge linux-firmware

emerge sync  #  apt-get update
emerge -DNu  world 
update-env
update-etc

so far the network is working, the next stage is just try to enrich the system and make it like a normal system.

another thing that needs to be aware is that once using wext driver in wpa_supplicant there are some problem, the wifi will not be connected. therefore, one has to use -Dnl8011 instead.

loss during install 1. two day working time 2. my windows 7 is mistakenly deleted during a install

#----------------------------------
make wicd work

# /etc/rc.d/dbus restart
# /etc/rc.d/wicd restart
# wicd-gtk


#--------------------------
wpa_supplicant -c /home/chenmingl/Desktop/wpa_supplicant.conf -i wlp2s0 -Dnl80211


make ati drivers work
in /usr/src/linux/.conf

# CONFIG_DRM_LOAD_EDID_FIRMWARE is not set
CONFIG_DRM_TTM=m         # this is newly added

#
# I2C encoder or helper chips
#
# CONFIG_DRM_I2C_CH7006 is not set
# CONFIG_DRM_I2C_SIL164 is not set
# CONFIG_DRM_I2C_NXP_TDA998X is not set
# CONFIG_DRM_TDFX is not set
# CONFIG_DRM_R128 is not set
CONFIG_DRM_RADEON=m         # this is newly added
# CONFIG_DRM_RADEON_UMS is not set
# CONFIG_DRM_NOUVEAU is not set


this is equivalent to
Processor type and features --->
<*> MTRR (Memory Type Range Register) support
Device drivers --->
   Graphics support --->
   <M> /dev/agpgart (AGP Support) --->
      (The agpgart option is not present on 64-bit kernels; just choose your chipset support.)
      <M> Intel 440LX/BX/GX, I8xx and E7x05 support
      (Enable your chipset instead of the above.)
   <M> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
      <M> (Select your graphics card from the list)

at manual setup
#---------------------------------

if one wants to use wpa_managager, one has to stop dbus which supports networkmanager and wicd

/etc/init.d/dbus stop

#---make network manager work--------------------------------
# NetworkManager
# startx
#but the priviliage problem still exists, that is why i decided to go to gnome to try my luck

# the problem for wicd is if I run
# wicd
# wicd-gtk or wicd-client
the system didn't actually find network for it

there is a trick to work around this problem, which is to startx by root, set the wireless settings, then go back logon as normal user.


The problem for wpa_supplient is that it always connects and disconnects. which is very annoying

#------------------can not emerge  gnome-extra/gnome-user-docs----
this happens when I tries to emerge gnome
# MAKEOPTS=-j1 emerge -1 gnome-user-docs
#


#--------------------no GUI on VLC and virtualbox---------------
one has to ad qt4 in /etc/portage/make.conf file sothat it will be enabled.
#--------------------install chinese input in gentoo------------
now ibus does not have ebuild on ibus-table-wubi so we have to use another input method
Fcitx is a very good alternative for chinese input purpose.
but one has to be careful before installing that, one has to uninstall ibus completelly.
otherwise there will be problem in using ctrl+space to change input method.
#-------------------no sound problem after installing gentoo-----------------
once i came across a problem on sound card in gentoo.
I have installed the sound card properly in linux kernel,
and from lsmod, we can find the sound card module are properly loaded on boot
however, from pulsemixer I can not find any sound device.
it turns out to be a problem of the group. I need to add my user name to audio by
# usermod -a -G audio chenming

Saturday, 24 August 2013

make videos by linux + PowerDirector

Recently I need to do a video project for my daughter's birthday. the project involves two chapters: the first chapter is to slide her photos with 0.2 seconds interval, each photos has approximately the same head size and eye position is close. The second chapter is to combine all of the interesting videos of her.


The first one is going to be massive if one uses gimp or photoshop to do that. therefore, I decided to use scripts to handle these problem. After digging, I found opencv in python and matlab has the function of finding faces from files. So I decided to use opencv as a start. I found a code (updated from http://stackoverflow.com/questions/13211745/detect-face-then-autocrop-pictures) I did further change so that each output file has put the face right in the middle with same size (translations and scaling)

here is the working scripts :


'''
Sources:
http://opencv.willowgarage.com/documentation/python/cookbook.html
http://www.lucaamore.com/?p=638
'''

#Python 2.7.2
#Opencv 2.4.2
#PIL 1.1.7

import cv #Opencv
import Image #Image from PIL
import glob
import os


# x correction
adj=0.05
# the width of output image
picx = 1024.1
# the height of output image
picy = 768.1
# the x ratio of picture in the whole output image
xpra=0.4
# the x ratio where picture starts
xra = (1-xpra-adj)/2
# the y ratio where picture starts
yra = (picy-xpra*picx)/picy/2



def DetectFace(image, faceCascade, returnImage=False):
    # This function takes a grey scale cv image and finds
    # the patterns defined in the haarcascade function
    # modified from: http://www.lucaamore.com/?p=638

    #variables    
    min_size = (200,200)
    haar_scale = 1.1
    min_neighbors = 3
    haar_flags = 0



    
    # Equalize the histogram
    cv.EqualizeHist(image, image)

    # Detect the faces
    faces = cv.HaarDetectObjects(
            image, faceCascade, cv.CreateMemStorage(0),
            haar_scale, min_neighbors, haar_flags, min_size
        )

    # If faces are found
    if faces and returnImage:
        for ((x, y, w, h), n) in faces:
            # Convert bounding box to two CvPoints
            pt1 = (int(x), int(y))
            pt2 = (int(x + w), int(y + h))
            cv.Rectangle(image, pt1, pt2, cv.RGB(255, 0, 0), 5, 8, 0)
    if returnImage:
        return image
    else:
        return faces

def pil2cvGrey(pil_im):
    # Convert a PIL image to a greyscale cv image
    # from: http://pythonpath.wordpress.com/2012/05/08/pil-to-opencv-image/
    pil_im = pil_im.convert('L')
    cv_im = cv.CreateImageHeader(pil_im.size, cv.IPL_DEPTH_8U, 1)
    cv.SetData(cv_im, pil_im.tostring(), pil_im.size[0]  )
    return cv_im

def cv2pil(cv_im):
    # Convert the cv image to a PIL image
    return Image.fromstring("L", cv.GetSize(cv_im), cv_im.tostring())

def imgCrop(image, cropBox, boxScale=1):
    # Crop a PIL image with the provided box [x(left), y(upper),
    # w(width), h(height)]

    # Calculate scale factors
    xDelta=max(cropBox[2]*(boxScale-1),0)
    yDelta=max(cropBox[3]*(boxScale-1),0)

    # Convert cv box to PIL box [left, upper, right, lower]
    PIL_box=[cropBox[0]-xDelta,
             cropBox[1]-yDelta,
             cropBox[0]+cropBox[2]+xDelta,
             cropBox[1]+cropBox[3]+yDelta]

    return image.crop(PIL_box)

def faceCrop(imagePattern,boxScale=1):
    # Select one of the haarcascade files:
    #   haarcascade_frontalface_alt.xml  <-- Best one?
    #   haarcascade_frontalface_alt2.xml
    #   haarcascade_frontalface_alt_tree.xml
    #   haarcascade_frontalface_default.xml
    #   haarcascade_profileface.xml
    faceCascade = cv.Load(
        '/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml')
    #  faceCascade = cv.Load('haarcascade_frontalface_alt.xml')

    imgList=glob.glob(imagePattern)
    if len(imgList)<=0:
        print 'No Images Found'
        return

    for img in imgList:
        pil_im=Image.open(img)
        cv_im=pil2cvGrey(pil_im)
        faces=DetectFace(cv_im,faceCascade)
        if faces:
            n=1
            for face in faces:
               #  scale factor new/old
               scf=(picx*xpra)/face[0][3]
               #  new =old*scf
               rsx=int(pil_im.size[0]*scf)
               rsy=int(pil_im.size[1]*scf)
               resizedImage=pil_im.resize(
                   (rsx,rsy)
                   ,Image.ANTIALIAS)
               croppedImage=imgCrop(
                   resizedImage,
                   (int(face[0][0]*scf-xra*picx),int(face[0][1]*scf-yra*picy),int(picx),int(picy)),
#                   (int(face[0][0]*scf),int(face[0][1]*scf),int(picx),int(picy)),
#                   (int(face[0][0]*scf),int(face[0][1]*scf),int(face[0][2]*scf),int(face[0][3]*scf)),
                   boxScale=boxScale)  
               croppedImage2=imgCrop(pil_im, face[0],boxScale=boxScale)
               fname,ext=os.path.splitext(img)
               #resizedImage.save(fname+'_resized'+str(n)+ext)
               croppedImage.save(fname+'_r_c'+str(n)+ext)               
               croppedImage2.save(fname+'_cropori'+str(n)+ext)
               n+=1
        else:
            print 'No faces found:', img



            
def test(imageFilePath):
    pil_im=Image.open(imageFilePath)
    cv_im=pil2cvGrey(pil_im)
    # Select one of the haarcascade files:
    #   haarcascade_frontalface_alt.xml  <-- Best one?
    #   haarcascade_frontalface_alt2.xml
    #   haarcascade_frontalface_alt_tree.xml
    #   haarcascade_frontalface_default.xml
    #   haarcascade_profileface.xml
    faceCascade = cv.Load('haarcascade_frontalface_alt.xml')
    face_im=DetectFace(cv_im,faceCascade, returnImage=True)
    img=cv2pil(face_im)
    img.show()
    img.save('test.png')


# Test the algorithm on an image
#test('testPics/faces.jpg')

# Crop all jpegs in a folder. Note: the code uses glob which
# follows unix shell rules.
# Use the boxScale to scale the cropping area. 1=opencv box,
#    2=2x the width and height
#faceCrop('/home/debianchenming/Downloads/1/*.JPG',boxScale=1)
faceCrop('/media/D0CC0864CC0846E6/Portrait/secondtime/12-12-09/*.JPG',boxScale=1)

Thursday, 22 August 2013

Slackware study

1. i found my laptop (toshiba is not happy with network-manager). when it is scheduled on boot by


# chmod +x /etc/rc.d/rc.networkmanager
the computer freezes without starting X desktop.
so i just switch it off by
# chmod -x /etc/rc.d/rc.networkmanager
and use wpa_supplicant to connect to internet

later I found enable wicd on boot is also problematic (system freezes when input username in). so I have to disable that on boot as well.
# chmod -x /etc/rc.d/rc.wicd

#ifconfig wlan0 up
#slackpkg update
note that before update, one has to enable the mirrors as by default they are commented out. so just go to mirror location:
## mirror location
/etc/slackpkg/mirrors

and uncomment the mirror you want to use

#slackpkg install-new
#slackpkg upgrade-all
#slackpkg clean-system

# upgradepkg --install-new /home/chenming/Downloads/slapt-get-0.10.2p-x86_64-1.tgz

# slapt-get --update
# slapt-get -i htop

remember, real slackers install software from compilling.
I have found that to install chromium, one has to install libevent first. it can be found from
http://slackbuilds.org/repository/14.0/libraries/libevent/

that is also required by i3 (However, i3 requires libev, which is in confilict with libevent. but most software requires libevent.).

apparantly sbopkg does not solve dependency problem properly. but still it gives a better way to easy install packages.

for the virtualbox, it seems as if one can direct install the binary files provided by official website

i3 can be installed easily from sbopkg.




Tuesday, 20 August 2013

How to connect to wifi through wpa_supplicant and wicd-cli (in particular get connected to eduroam in australia)


iw(list/config) can only handle WEP.
You need wpa-supplicant for this.
sudo apt-get install wpasupplicant
In /etc/wpa_supplicant.conf you put your ssid and password.
gksu gedit /etc/wpa_supplicant.conf 
Example:
network={
            ssid="ssid_name"
             psk="password"
}
Assuming your interface is wlan0 you can connect to it with...
wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant.conf -Dwext && dhclient wlan0
C--------------------------------

Now I have a case for connecting it in eduroam in australia.

first, make a file named as "wpa_supplicant.conf" on the desktop.


ctrl_interface=/var/run/wpa_supplicant
eapol_version=1
ap_scan=1
fast_reauth=1
network={
 ssid="eduroam"
 scan_ssid=1
 key_mgmt=WPA-EAP WPA-NONE IEEE8021X
 eap=PEAP
 phase2="auth=PAP auth=MSCHAPV2"
 identity="PUT YOUR account name here"
 password="PUT YOUR password here"
priority=2
auth_alg=OPEN
}
 be aware that you need to put account name and password in the file

then run
# wpa_supplicant -c /home/chenming/Desktop/wpa_supplicant.conf -iwlan0 -Dwext
# dhclient wlan0
enjoy!
##-----------------------------another comments ------------------------

in scientific linux distro, the current version is 6.4, which only support wicd 1.7.0, however, it has been found that this wicd 1.7.0 does not work well with eduroam. if one has to stick SL, compile wicd 1.7.2 from source is required, I did that in SL and found it is be very buggy, in particular, when using wicd-gtk to specify connectionn type and passwork and so on, the window can not be closed. then I decided to use wicd-cli, a command line based app to connect the 1.7.2 to eduroam. So far from the man page, I can't see any thing that is equivalent to -c in wpa_supplicant which specifiy the connection type and these sort of things. however, those information is needed for complex eduroam. so I dicided to stop and just wait when redhat update to 7.

make satellite toshiba laptop working well with linux

This type of laptop has got a wired hardware so that it doesn't work properly with:
1. debian wheezy: problem freeze at logon window.
2. ubuntu 12.04: freeze at logon
3. archlinux can not install
4. debian live disk. freeze at install.
5. scientific linux 6.4. the speed to eduroam is very slow. (same thing apply to debian squeeze)

I have tried many network drivers for RTL8188ce, like from official web, linuxwireless, none of them work properly. later on I found this wireless driver is working properly with wicd, however, once it is in version 1.7.0, it always show wrong password. (which I found is a bug)

it looks as if we 1. not using gnome 3, 2. using wicd 1.7.2, all the problems may solve out automatically. therefore, I dicided to use lubuntu, which uses lxde as default desktop.

however, again wicd becomes wired. after excuting

    $ sudo service wicd start

it doesn't working properly. it turns out that there is another bug in wicd (wicd is really buggy!!)

https://bugs.launchpad.net/ubuntu/+source/wicd/+bug/1132529

to solve it out I did:


  rm /etc/resolv.conf
    ln -s /run/resolvconf/resolv.conf
    rm /var/lib/wicd/resolv.conf.orig
    ln -s /run/resolvconf/resolv.conf /var/lib/wicd/resolv.conf.orig

and removed network-manager. Now the speed working fantastically!!!