Friday, October 29, 2004

Mutimedia stuff

To create avi or mpeg files from a DVD or VCD, first get disk info (such as titles, chapters, audio languages and subtitle languages) by using mplayer:
Code:
$ mplayer dvd:// -v (-aop list=volume,extrastereo:volume=120 -vf lavcdeint)
$ mencoder dvd://1 -chapter 20-22 -o tiger.avi -oac copy -ovc copy -alang en -slang zh
$ mencoder vcd://1 -ss 00:02:23 -of mpeg -o output.mpeg -oac mp3lame -ovc copy -endpos 00:00:15
$ mencoder dvd://1 -chapter 20 -o tiger.avi -oac mp3lame -ovc divx4 -aid 130 -sid 1 -endpos 50mb


Type 'mencoder -ovc help' to find out available video codecs.
A two pass procedure:
Code:
$ mencoder dvd://1 -oac copy -aid 128 -o movie.avi -ovc lavc -lavcopts vcodec=mpeg4:vhq:vpass=1 -vf scale=640:480,crop=640:344:0:66,lavcdeint -vobsubout sub-en.txt -sid 1
$ mencoder dvd://1 -oac mp3lame -o movie.avi -ovc lavc -lavcopts vcodec=mpeg4:vhq:vpass=2 -vf scale=640:480,crop=640:344:0:66,lavcdeint


To create a mpg file that plays a photo slideshow,type:
Code:
$ img2mpg -d 4 -w sound.wav -o show.mpg -i /path/to/*.jpg


To merge 2 avi files, type:
Code:
$ avimerge -o big.avi -i small01.avi small02.avi


'Img2mpg' is one of the 'mjpegtools' while 'avimerge' belongs to 'transcode'; to verify, type:
Code:
$ qpkg -fp img2mpg


Note: img2mpg has been removed from mjpegtools > -1.6.1.90, it seems it has been incorporated into digikamplugins.
You must have installed 'gentoolkit' to use the 'qpkg' command.

Extracting audio from VOBs/MPEGs/AVIs

MPlayer can be used easily to extract sound. The -vo null options tells MPlayer not to show the video.
Code:
VOB -> AC3:
$ mplayer -vo null -nogui -alang de -dumpaudio -dumpfile lang-de.ac3 *vob
This will extract the German audio to a file called lang-de.ac3.


Code:
VOB -> WAV:
$ mplayer -vo null -nogui -aid 128 -ao pcm -aofile lang-de.wav *vob
This will extract audio track no. 128, downmix the AC3 sound to PCM and write the results to lang-de.wav.


Code:
MPG -> MP2:
$ mplayer -vo null -nogui -dumpaudio -dumpfile audio.mp2 myvideo.mpg
This will extract the audio to a file called audio.mp2.


Code:
AVI -> WAV:
mplayer -vo null -nogui -ao pcm -aofile audio.wav myvideo.avi
This will extract the audio, convert it to PCM and write the resulting .WAV to audio.wav.


I'm not listing all possible options. Generally use -dumpaudio -dumpfile newaudio.extension if you want to extract the audio without processing and -ao pcm -aofile newaudio.wav if you want the WAV itself. Here's a simple one-liner:
Code:
mplayer -ao pcm -aofile audio.wav video.vob ; normalize audio.wav ; oggenc audio.wav audio.ogg


The following is a simple command to rip vob files from a dvd:
Code:
$ mount /mnt/cdrom && vobcopy /mnt/cdrom -l -n 1 -O . -t "vob"


It will create a vob directory in the current directory. To convert these vob files into mpeg (from filename.vob to final.mpg):
Code:
$ tcextract -i filename.vob -t vob -x mpeg2 > movie.m2v
$ tcextract -i filename.vob -a 0 -x ac3 -t vob > movie.ac3
$ mplex -f 8 -o final.mpg movie.*


Konqueror also works, just mount the DVD and copy the vob files.

A ~/.asoundrc that works:
Code:
pcm.mymixer {
type dmix
ipc_key 1024
slave {
pcm "hw:0,0"
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}

pcm.!default {
type plug
slave.pcm "mymixer"
}


pcm.dsp0 {
type plug
slave.pcm "mymixer"
}

ctl.mixer0 {
type hw
card 0
}

Friday, October 22, 2004

Schubert's Piano Sonata No.21 D960

Today I bought Kovacevich's EMI recording of Schubert's greatest piano sonata. I've got several recordings of this sonata already, namely those of Kempff, Curzon and Richter; they are very different interpretations, now I've got one more. I always like Kovacevich's Beethoven, yet this is his first Schubert CD I've got.

Among the great composers for the piano, Schubert was himself no virtuoso. This is reflected in the absence of bravura passages in his piano works which, perhaps with the exception of the Wanderer Fantasy, make no great technical demands on a performer. This is not to say that his piano works are easy to perform. On the contrary, as most of his piano sonatas display a flexibility of structure and an adventurous handling of harmony and tone, they cause problems to many players. A good pianist can make a big difference to what a Schubert's sonata should sound like, this is especially the case with his late sonatas; those are long musical soliloquies that constantly repeat and reformulate themes as if they were persistent memories. They may sound terribly boring if the player cannot bring out the cogency of the longer spans; in the hands of a great player, however, they become the most sublime and breath-taking music. Kovacevich is certainly an artist of such caliber; his account sounds fresh and bold, yet not without introspectiveness; the tonal beauty and depths of feeling he brings to this sonata is very impressive indeed.

His complete Beethoven cycle is available now, it's simply a matter of time before I grab a box; it costs about US$100, I guess I need to wait for a sale.

用dnscache做dns resolver

此文最初发表于LinuxSir论坛:http://www.linuxsir.org/bbs/showthread.php?s=&threadid=93585&highlight=djbdns

djbdns 是bind的最佳替代品;它比bind小,安全,容易设置。dnscache只是djbdns的一个组件,主要是用来处理user queries的caching DNS server。这有一篇文章是介绍djbdns的,是FreeBSD的设置,和gentoo是不大一样的:http://ezine.daemonnews.org/200210/ezdjbdns.html,不过可以了解一下原理。
安装dnscache很简单:
代码:
# emerge djbdns
# dnscache-setup


dnscache会被(缺省)安装到/var/dnscache下,回答完一些有关ip的问题之后,会产生一个新的/etc/resov.conf,原本的会备份为resolv.conf.orig。然后启动服务:
代码:
# /etc/init.d/svscan start
# rc-update add svscan default


然后试一下:
代码:
# host www.gentoo.org
www.gentoo.org has address 199.246.73.203
www.gentoo.org has address 198.63.211.235

注:host命令属于net-dns/bind-tools


cache 的大小是可以改的(缺省是1m),只要修改/var/dnscache/env/CACHESIZE里的数字即可。 /var/dnscache/env/DATALIMIT也要做相应的改动,而且必须比CACHESIZE大。如果你的cache大小是10m,这10m 的DNS lookups会令到你经常去的网站的resolving的过程变得飞快!

Tuesday, October 19, 2004

有關系統備份

此文最初發表於Gentoo台灣論壇: http://forums.gentoo.org.tw/viewtopic.php?t=41975

大家都知道要做資料備份及設定檔的備份。但有沒有想過做整個系統的備份呢?例如自己不小心rm -rf或是chmod -R 777敲得太快後面打了/ 之後還沒來得及打目錄就按了Enter;系統被入侵;斷電導致整個硬碟完蛋;又或是系統被自己莫名其妙地搞壞了最終都不懂怎麼修復等等。這時候似乎只有重 裝了,但Gentoo重裝可不是一件輕鬆的事喔!如果你做了整個系統的備份就不用怕了!Windows裡有Ghost,linux下有Partimage和Mondorescue,但始終我還是覺得unix常見的工具反而是最具靈活性的。

用LiveCD或Knoppix開機,並將根分區掛好:/mnt/gentoo。如果你的/boot,/usr用的是獨立的分區或硬碟,你必須把它們分別掛到/mnt/gentoo/boot ,/mnt/gentoo/usr等目錄裡。然後:
代碼:

# cd /mnt/gentoo
# tar -cz --exclude-from /mnt/gentoo/root/exclude-list -iv * | split -a 1
-b 700m - /path/to/mybackup.tar.gz-

這樣會產生好幾個包mybackup.tar.gz-a, mybackup.tar.gz-b等等,每個最大700m(方便燒碟)。exclude-list可以事先寫好,類似這樣:
usr/portage/distfiles
var/tmp/portage
home/yourusername/music
home/yourusername/video

並放到你的gentoo分區的/root裡。
注意存放備份包的地方要有足夠的空間,如果在不同的分區,事先要掛好。
還原的時候,先要在有關的分區上重建檔案系統,並象以上所說的那樣掛載好,然後:

代碼:

# cd /mnt/gentoo
# cat /path/to/mybackup.tar.gz-* | tar xzvpf

為什麼要用LiveCD啟動呢?這是因為運行中的系統並非靜態,不應該簡單地去tar根目錄;有的程序如partimage甚至要求卸載備份的分區。當然 也有可以在運行中的系統做完全備份的程序啦,Mondorescue就是一個例子;這些程序都頗為複雜,不過有興趣的朋友可以自己試試。

我自己有個分區裝了個後備系統。這樣每當其他系統出了問題,我不至於沒機子用。這個後備系統我平時很少用,更不會去瞎调;但我機子的grub是從這裡裝 的,備份或搶修其他分區也是在這裡做的。這個後備系統本來是Knoppix的硬碟安裝(因為現在Knoppix硬碟安裝實在是太容易了),不過我已經把它 換成了gentoo了(已經有了備份就什麼都不用怕了)!

LinuxSir論壇的gao_linfeng寫過一篇使用dd的備份方案挺有意思的: http://bbs.linuxsir.org/showthread.php?s=&threadid=113474

另外,如果想備份partition table,可以:
代碼:

# dd if=/dev/hda of=mbr.bak bs=512 count=1

還原:
代碼:

# dd of=/dev/hda if=mbr.bak bs=512 count=1

Monday, October 18, 2004

win4lin在Gentoo Linux 2.6内核下的安装

此文最初發表於Gentoo官方論壇: http://forums.gentoo.org/viewtopic.php?t=171727&highlight=
此中文版轉自Gentoo中文社區,並經Hans Joanphan校定: http://gentoo.linuxsir.org/doc/cn/win4lin.xml


1. 从Portage中安装win4lin

如果你的内核选用win4lin-sources-2.6.7-r5,这个内核相对gentoo-dev-sources-2.6.7-r14要简陋一些,安装win4lin则可直接使用。
代码 1.1: win4lin-sources-2.6.7-r5下的安装


# ACCEPT_KEYWORDS="~x86" emerge win4lin

注释:
这个不推荐使用。


2. 手动安装win4lin

相对来说,内核gentoo-dev-sources-2.6.7-r14则比较常用些,打的补丁也比较多,功能比较丰富。但是portage中并不可以直接在这个基础上安炸win4lin,我们可以手动安装。

首先从这儿下载内核补丁:mki-adapter26_1_3_6.patch和Kernel-Win4Lin3-2.6.7.patch
然后准备编译内核,先把内核源码备份一下,如下:
代码 2.1: 备份内核源码


# cd /usr/src
# cp -a linux-2.6.7-gentoo-r14 win4lin
# rm linux
# ln -s win4lin linux
# cd linux
# nano -w Makefile

注释:修改“EXTRAVERSION = ”,比如改成“-win4lin-r14”之类以便识别


把下载的mki-adapter26_1_3_6.patch和Kernel-Win4Lin3-2.6.7.patch拷到目录下,然后给内核打补丁:
代码 2.2: 给内核打补丁
# patch -p1 < Kernel-Win4Lin3-2.6.7.patch > patch.log 2>&1
# patch -p1 < mki-adapter26_1_3_6.patch >> patch.log 2>&1
# less patch.log


如果patch.log里没错误,就可以开始编译kernel了。注意以下这些要编进kernel:
  • Enable loadable module support
  • System V IPC
  • Kernel support for ELF binaries
  • Networking support
  • TCP/IP networking
  • ISO 9660 CD-ROM filesystem support
  • Include NeTraverse Win4Lin Support
编译完成后,用新的内核重启。

3. 配置win4lin

如果你想确认win4lin是否已经正确的编入内核中,你可以:
代码 3.1: 确认win4lin是否编入内核
# modprobe mki-adapter
# cat /proc/mki-adapter/version

注释:
按照本文的安装方法,应该显示为1.3.6。如果在使用modprobe或cat发生错误,
你新编译的内核可能未正确的编译好或启动。


确认win4lin已经编入内核后,便可以安装win4lin:
代码 3.2: 安装win4lin
# emerge -O win4lin


现在的稳定版是win4lin-5.1.1,可以到/var/db/pkg/app-emulation下看看。
把windows CD放入光驱,进行初始设定:
代码 3.3: win4lin的初始化
# mount /mnt/cdrom
# ebuild /var/db/pkg/app-emulation/win4lin-5.1.1/win4lin-5.1.1.ebuild config

注释:
如果显示有问题可以先启动win4lin服务,
# /etc/init.d/Win4Lin start
然后用以上ebuild。。。那个指令再试一次。


完成之后,用一个有效的license号码代替/var/win4lin/install下license.lic里那个。然后便可以启动服务和安装windows:
代码 3.4: 安装windows
# /etc/init.d/Win4Lin start (或restart,如果你之前已经启动了服务的话)
// 最好以普通用户身份安装windows
$ installwindows


在询问网络的安装方式的时候,可以选择Winsock模式。接着就可以看到windows的安装画面了。最后将win4lin添加到默认运行级别中,即可每次电脑启动后直接使用你的win4lin了。
代码 3.5: 添加Win4lin到默认运行级别
# rc-update add Win4Lin default


Sunday, October 17, 2004

Gentoo Linux

I've been using linux for quite some time now, Gentoo linux is my distribution of choice. Here's a screenshot of my KDE desktop:

Welcome to my blog!

So suddenly I've become a blogger!
现在就开始我的博客生涯吧!
現在就開始我的部落客生涯吧!