星期五, 3月 27, 2015

簡單 ImageMagick convert 指令

縮放圖片以填滿指定大小:
Resize the image to fill the requested size. Some portion of the image may be clipped:
convert input.png -resize 100x100^ -gravity center -extent 100x100 output.png
縮放圖片在指定大小以內:
Resize the image to fit the requested size and maintaining the aspect ratio. Some portion of the output image may be blank:
convert input.png -resize 100x100 -gravity center -extent 100x100 output.png
縮放圖片到指定大小,不保持長寬比例:
Resize the image to the requested size ignoring the aspect ratio:
convert input.png -resize 100x100\! output.png
取GIF動畫的第一格:
Obtain only the first frame in an animated GIF file:
convert input.gif\[0\] output.png

星期三, 1月 21, 2015

簡單 ffmpeg 使用

由於版權問題 ffmpeg 官網並不提供已編譯的二進位執行檔下載。建議自己編譯 ffmpeg 的原始碼,或者從官方推薦的第三方網站下載已編譯的二進位執行檔:
Mac 版 ffmpeg 下載: http://evermeet.cx/ffmpeg/
Win 版 ffmpeg 下載: http://ffmpeg.zeranoe.com/builds/

下載 HKTV m3u8 影片
ffmpeg -i m3u8網址 -strict -2 hktv.mp4
剪片 (時間格式:時:分:秒.千分一秒 00:00:00.000) 參考文章
ffmpeg -ss 開始時間 -i 原影片檔案路徑 -t 長度 -c copy -avoid_negative_ts 1 output.mp4
轉換成 mp4
ffmpeg -i 原影片檔案路徑 -f mp4 -c:v libx264 -c:a aac -strict -2 output.mp4
合併字幕 (注意: 需要開啟 libass 支援) 參考文章
# 合併ass字幕:
ffmpeg -i 原影片檔案路徑 -vf "ass=字幕檔.ass" -f mp4 -c:v libx264 -c:a aac -strict -2 output.mp4
# 合併srt字幕:
ffmpeg -i 原影片檔案路徑 -vf "subtitles=字幕檔.srt" -f mp4 -c:v libx264 -c:a aac -strict -2 output.mp4
合併多段影片 參考文章
ffmpeg -f concat -i <(for f in ./*.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4
(將會持續更新...)

星期五, 10月 24, 2014

常用 curl 指令

將網頁內容直接輸出到螢幕上:
curl 網址
將網頁內容儲存到檔案:
curl -O 網址
將網頁內容儲存到指定檔案名稱:
curl -o filename.txt 網址
捨棄網頁內容:
curl 網址 > /dev/null
捨棄所有輸出:
curl 網址 2>&1 > /dev/null 或者 curl -s 網址 > /dev/null
捨棄所有輸出並在背景執行:
curl 網址 2>&1 > /dev/null &

傳送 POST 資料:
curl -d "name=howang&foo=bar" 網址
傳送 Cookie 資料:
curl -b "cookie1=hello;cookie2=world" 網址
允許不受信任的 SSL 證書:
curl -k 網址
更改 User-Agent: (這裏以Chrome作示範)
curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36" 網址
加入 HTTP Referer:
curl -e "http://www.example.com" 網址
加入自訂 HTTP Header:
curl -H "X-Test: foo" 網址
指定 HTTP request method:
curl -X GET 網址
登入 HTTP Basic Authentication:
curl -u "username:password" 網址
跟隨 HTTP 重新導向:
curl -L 網址
囉唆模式: (除錯用)
curl -v 網址

星期三, 3月 06, 2013

在 linux 上使用 gitolite 架設 git 伺服器

基本上按著 gitolite 官方說明就可以,唯一難題是官方說明書沒教我們怎開設 gitolite 專用的登入帳號,花了點時間 Google 就有答案了。

adduser --system --shell /bin/bash --gecos 'git version control' --group --disabled-password --home /home/git git
# copy my public key file (howang.pub) into /home/git
cp howang.pub /home/git/
chown git:git /home/git/howang.pub
# switch to the git user
su - git
# install and setup gitolite
git clone git://github.com/sitaramc/gitolite
mkdir -p $HOME/bin
gitolite/install -to $HOME/bin
bin/gitolite setup -pk howang.pub
exit
# clone the gitolite-admin repo
git clone git@localhost:gitolite-admin
cd gitolite-admin
# here I edit the config files and add public keys
# after that, commit and push to apply the new configurations
git commit -m "updated config"
git push origin master

星期四, 1月 17, 2013

Raspberry Pi 筆記

第一步,更新:
sudo apt-get update
sudo apt-get upgrade -y

安裝並轉用 vim:
sudo apt-get install vim
sudo update-alternatives --config editor

設定 reverse tunnel:
sudo apt-get install autossh
# allow connect to SSH via port 65522 on server.tld
autossh -NfR 65522:localhost:22 user@server.tld
# add the above line with @reboot prefix in crontab
crontab -e

安裝 VNC:
sudo apt-get install tightvncserver
# run it once to set password
tightvncserver
# start vnc server with display 0 at 1920x1080 resolution
vncserver :0 -geometry 1920x1080 -depth 24

安裝 Firefox:
sudo apt-get install iceweasel

安裝 Chrome:
# Install ttf fonts
sudo apt-get install ttf-mscorefonts-installer ttf-wqy-zenhei
# Install Chromium (Open Source version of Chrome)
sudo apt-get install chromium-browser

播放 MP3:
sudo apt-get install alsa-utils ntpdate mpg123 python-virtualenv libshout3 libshout3-dev pkg-config python-dev
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 1
mpg123 filename.mp3

設立 AirPrint:
sudo apt-get install avahi-daemon avahi-discover libnss-mdns cups cups-pdf python-cups
sudo usermod -aG lpadmin pi
# add "Allow from @Local" to Location section of / , /admin and /admin/conf
sudo vim /etc/cups/cupsd.conf
# add mine types for AirPrint
sudo echo '#
# "$Id: $"
#
# AirPrint type
image/urf urf string(0,UNIRAST<00>)
#
# End of "$Id: $".
#
' | sudo tee /usr/share/cups/mime/airprint.types > /dev/null
sudo echo '#
# "$Id: $"
#
# AirPrint
# Updated list with minimal set 25 Sept
image/urf application/pdf 100 pdftoraster
#
# End of "$Id: $".
#
' | sudo tee /usr/share/cups/mime/airprint.convs > /dev/null
sudo service cups restart
### go to https://raspberrypi:631/ and setup the printer
# download and run the airprint-generate script
wget https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
chmod 0755 airprint-generate.py
sudo ./airprint-generate.py -d /etc/avahi/services
sudo service avahi-daemon restart

設定時區:
sudo dpkg-reconfigure tzdata

播放 H.264 / MP4 影片:
omxplayer filename.mp4

### Key bindings
# Key   Action
#  1    Increase Speed
#  2    Decrease Speed
#  j    Previous Audio stream
#  k    Next Audio stream
#  i    Previous Chapter
#  o    Next Chapter
#  n    Previous Subtitle stream
#  m    Next Subtitle stream
#  s    Toggle subtitles
#  q    Exit OMXPlayer
# Space Pause/Resume
#  p    Pause/Resume
#  -    Decrease Volume
#  +    Increase Volume
# Left  Seek -30
# Right Seek +30
# Down  Seek -600
#  Up   Seek +600

暫停/繼續一個 process:
kill -STOP <pid>
kill -CONT <pid>

(將會持續更新...)