2014-01-07

How many lines in a file?

It's an easy (but not clear, please refer to the Note of wc below) question, but sill quite funny.

Tested under the Bash shell on Ubuntu 12.04 32-bit.

(1) wc

cat sample.txt | wc -l

or

wc sample.txt | awk '{print $1}'

awk is used to extract the 1st field.

Note: wc only counts the newline characters! The last line without newline is not counted.  For example:

echo -ne "ab\ncd" | wc -l

would generate 1 (line), not 2.


2013-07-27

Raw Screen Capture

To capture the raw screen, for example: (capture rectangle from (170,8) with width and height (760x650))

ffmpeg -f alsa -i pulse -f x11grab -r 25 -s 760x650 -i :0.0+170,8 -acodec pcm_s16le  -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mov


To cut and compress, for example: (start from second 2 for a duration of 03:26)

ffmpeg -i output.mov -ss 00:00:02 -t 00:03:26 output.mp4


2013-04-09

How to customize Ubuntu 12.04 desktop i386 LTS? (Forbuntu 12.04.2.13)

利用Ubuntu 12.04.2 desktop i386 來做1个台灣版的Linux,就簡單共號做Forbuntu 12.04.2.13(Formosa GNU/Linux based on Ubuntu 12.04.2 subversion 13)。

共iso檔案裝踮USB flash,直接開機,免安裝就會當做一寡簡單的代誌,親像上網、看影片、查資料…。

2个bash script 就會當自動做。

2013-01-22

How to sort films by length?

(1)Version 1

用「ffmpeg -i」來掠影片的長度。

佇「xargs」內底用「bash -c」來執行1个以上的指令。

用「(...)」(subshell)共指令組合起來。

find . \( -name "*.avi" -o -name "*.mp4" -o -name "*.mkv" \) -type f -print0 | xargs -0 -I % bash -c 'echo -ne "%\x00"; (ffmpeg -i "%" 2>&1 | grep Duration);' | awk -F '\x00' '{print $2,$1;}' | sort -k2


 (2)Version 2

簡化Version 1。

檔名「%」愛用「"%"」,通好保護。

find . \( -name "*.avi" -o -name "*.mp4" -o -name "*.mkv" \) -type f -print0 | xargs -0 -I % bash -c 'echo $(ffmpeg -i "%" 2>&1 | grep Duration) "%"' | sort -k2


 (3)Version 3

改用「-exec」。

「{}」愛用「"{}"」。

find . \( -name "*.avi" -o -name "*.mp4" -o -name "*.mkv" \) -type f -exec bash -c 'echo $(ffmpeg -i "{}" 2>&1 | grep Duration) "{}"' \; | sort -k2

2012-08-08

How to capture screen?

ffmpeg -f x11grab -r 25 -s 512x384 -i :0.0+8,40 -b 1500k ~/out.ogg

-f:格式。「x11grab」表示欲對X11的螢幕掠。
-r:frames per second。
-s:size,闊度、懸度。
-i:X11設備編號,通常就是「0.0」。「+8,40」(+x,y)表示欲對佗開始掠。
-b:bitrate,video的bitrate。

2012-07-28

How to backup karaoke DVD?

欲放卡拉OK的DVD 予媽媽唱歌,DVD player煞讀無DVD。愛緊想辦法,先用電腦共卡拉OK DVD備份落來。

(1)mplayer -identify dvd:// | grep -i title

先用mplayer 看有幾條歌(chapter),囥佇佗(title)。


結果有1逝顯示:

ID_DVD_TITLE_2_CHAPTERS=20

表示囥佇title 2,有20條歌。(第1个title四常是menu)



(2)for ((i=1; i<=20; i++)); do mplayer dvd://2 -chapter $i-$i -dumpstream -dumpfile $i.vob; done


用「mplayer」共歌備份落來。1條歌1个檔案。


(3)for ((i=1; i<=20; i++)); do ffmpeg -i $i.vob -b 1500k -acodec libvorbis -ab 160k -ac 2 $i.ogg; done

用「ffmpeg」共備份的vob 轉做「ogg」,較袂佔空間。


2012-05-28

How to backup DVD?

四常用「Brasero」抑是「K3b」,無,用「dvd::rip」。

欲較簡單的,就用「readom」、「wodim」。

(1)wodim --devices

列出會當用的設備。親像:

-------------------------------------------------------------------------
 0  dev='/dev/scd0'    rwrw-- : 'Slimtype' 'DVD A  DS8A4SH'
-------------------------------------------------------------------------



(2)readom dev=/dev/scd0 f=dvd.iso

共dvd 備份做ISO檔案。

「dev=設備名」。

「f=ISO檔名」。


(3)wodim -v dev=/dev/scd0 -eject dvd.iso

共ISO檔案燒做dvd來備份。

「-v」:verbose,顯示進度。

「-eject」:燒好共dvd退出來。