星期三, 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>

(將會持續更新...)

星期一, 1月 14, 2013

不用任何外置裝置在 MacBook Air 上重裝 Window 7

標題很長,但因為我的處境太奇怪,所以只好寫成這樣...
方法主要根據 SevenForums 上的 How to Install Windows 7 FAST without a DVD or USB Device,再加上幾個步驟。

我的處境:
  • 電腦: Apple MacBook Air
  • 沒有光碟機
  • 沒有 USB Disk
  • 主系統: Mac OS X 10.8
  • BOOTCAMP 系統: Windows 8
使用軟件:
目的: 移除超難用而且兼容性太低的 Windows 8,重新安裝 Windows 7

步驟:
  1. 在 OS X 上,使用 vmware-rawdiskCreator 製成一個指向 BOOTCAMP 硬碟分割的 vmdk 檔案 
  2. /Applications/VMware\ Fusion.app/Contents/Library/vmware-rawdiskCreator create /dev/disk0 1 "/Users/howang/Desktop/bootcamp" ide
    
  3. 修改我原有的 Windows XP VM(虛擬機) 的 VMware 設定檔 (vmx 檔),為 VM 加入 BOOTCAMP 硬碟
  4. ide0:0.present = "TRUE"
    ide0:0.fileName = "/Users/howang/Desktop/bootcamp.vmdk"
    
  5. 啟動 Windows XP VM,在 VMware 中掛載 Window 7 的 ISO 檔
  6. 在 XP 中格式化 BOOTCAMP 硬碟分割
  7. 根據 How to Install Windows 7 FAST without a DVD or USB Device 的方法,使用 ImageX 工具把 Windows 7 的 install.wim 套用到 BOOTCAMP 碟碟分割中
  8. imagex /apply d:\sources\install.wim 5 e:\
    
  9. 把 Windows XP VM 關機,修改 vmx 檔,刪去原有 Windows XP 的虛擬硬碟
  10. 重新啟動 Windows XP VM,這次使用 Windows 7 的 ISO 檔 boot 機,選擇 "Repair my computer" 並開啟 Command Prompt (命令提示字元)
  11. 輸入:
  12. c:\windows\system32\bcdboot c:\windows
    d:\boot\bootsect /nt60 c: 
  13. 把 Windows XP VM 關機(重要:千萬不要在 VM 中用 BOOTCAMP 碟碟分割開機,會令安裝失敗的)
  14. 重新啟動電腦,使用 BOOTCAMP 開機,Windows 7 會自動完成安裝 ^.^