顯示具有 linux 標籤的文章。 顯示所有文章
顯示具有 linux 標籤的文章。 顯示所有文章

2014年3月16日 星期日

Use avconv to convert x264 video

我之前轉影片最常用的是 FFmpeg,不過在 Ubuntu 上面,出現了這段文字:

$ ffmpeg
ffmpeg version 0.8.10-4:0.8.10-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Feb  6 2014 20:56:59 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.

Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'
$

去查了一下,原來 ffmpeg 這個專案出現了分支叫做 avconv,然後幫 Debian 和 Ubuntu 包 ffmpeg package 的維護者們跟 avconv 的開發者是同一群人,於是 Debian 和 Ubuntu 目前都是建議使用 abconv 了。

大略用了一下,其實參數都差不多,所以大部分人應該都可以無痛轉移。


安裝

  •  sudo apt-get install libavcodec-extra-53 libav-tools x264 

使用

範例


$ avconv -i input.mkv -vcodec libx264 -crf 23 -preset slow -profile:v baseline -acodec copy -strict experimental -scodec copy output.mkv

參數

-crf (Constant Rate Factor)

可選 0-51, 0 是無損,51是最差。預設值 23。通常調教合理的範圍是 18-28。18 是人眼不太容易看出差異,但仍然是有損的。

-present

present 代表包含編碼速度以及壓縮率的一組設定。詳細對應的參數可以使用 x264 --fullhelp 查看。

可用的參數:ultrafast, superfast, veryfast, faster, fast, medium (套入預設的設定), slow, slower, veryslow, placebo

-profile (裝置的相容性)

iOS Compatability (source)
Profile Level Devices Options
Baseline 3.0 All devices -profile:v baseline -level 3.0
Baseline 3.1 iPhone 3G and later, iPod touch 2nd generation and later -profile:v baseline -level 3.1
Main 3.1 iPad (all versions), Apple TV 2 and later, iPhone 4 and later -profile:v main -level 3.1
Main 4.0 Apple TV 3 and later, iPad 2 and later, iPhone 4S and later -profile:v main -level 4.0
High 4.0 Apple TV 3 and later, iPad 2 and later, iPhone 4S and later -profile:v high -level 4.0
High 4.1 iPad 2 and later and iPhone 4S and later -profile:v high -level 4.1

求助

查看 x264 可使用的參數解釋
  • x264 --fullhelp

Reference

2014年1月4日 星期六

vsftpd on Ubuntu 12.04 LTE

最近剛好有架 FTP 的需求,希望有個網路硬碟能讓我能隨時隨地放東西。
找了一下,看到 vsftpd (very secure ftpd) 似乎蠻好架,於是就來試試看。

顧及自己動物機的安全,因此要求如下:
  • 支援虛擬帳號 (virtual account),能與作業系統帳號切開
  • 不可以隨便亂逛,把系統看光光 (chroot)
  • 不允許匿名使用者
 那接下來就讓我們開始吧。

1. 安裝

 $  sudo apt-get install vsftpd libpam-pwdfile

由於 vsftpd 是利用 pam 來與系統的驗證機制結合,這樣他就可以利用系統的帳號登入。
因此我們也可以用它來產生虛擬帳號的功能。
其中 pwdfile 是 apache web server 使用者權限管理的 library,這樣我們就可以用同樣的方法來管理虛擬帳號。

2. 設定檔 (請覆蓋或備份原本的檔案)


 /etc/vsftpd.conf

# global settings
listen=YES
listen_port=2211
anonymous_enable=NO
write_enable=YES
hide_ids=YES

# local accont
local_enable=YES
local_umask=022
virtual_use_local_privs=YES
guest_enable=YES
guest_username=ftpsecure
nopriv_user=ftpsecure

# chroot
chroot_local_user=YES
#user_sub_token=$USER
#local_root=/mnt/ftproot/$USER
local_root=/mnt/ftproot
secure_chroot_dir=/var/run/vsftpd

# pam auth setting ==> /etc/pam.d/vsftpd
pam_service_name=vsftpd

dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
#xferlog_std_format=YES

# pasv mode setting
pasv_enable=YES
pasv_max_port=65535
pasv_min_port=49152

# monitor
#  monitor command: watch ps -C vsftpd -o user,pid,stime,cmd
setproctitle_enable=YES

/etc/pam.d/vsftpd

# Customized login using htpasswd file
auth    required pam_pwdfile.so pwdfile /etc/vsftpd/passwd
account required pam_permit.so

3. 建立虛擬使用者對應的系統使用者


為了讓系統更安全,通常我們會讓伺服器用獨立的使用者執行。
在上面的設定檔中,我們使用 ftpsecure 這個帳號。

$ sudo adduser ftpsecure

然後修改 /etc/passwd 。把 shell 設定成 /bin/false。
在這邊我把他的家目錄也設定成跟 local_root 相同了。但這並不一定需要。

ftpsecure:x:9876:9876:,,,:/mnt/ftproot:/bin/false

接下來,因為 vsftpd 不允許 user 到 chroot 的根目錄有寫入權限。
因此我們來修改一下權限:

$ sudo chwon nobody:nogroup /mnt/ftproot
$ sudo chmod 755 /mnt/ftproot

然後建一個目錄讓 user 可以寫入

$ sudo mkdir /mnt/ftproot/upload
$ sudo chown ftpsecure:ftpsecure /mnt/ftproot/upload
$ sudo chmod 755 /mnt/ftproot/upload

4. 建立虛擬使用者


你必須先安裝 apache 以取得 htpasswd 這個指令。
假設我要把密碼檔存放在 /etc/vsftpd/passwd ,以及建立 ftpuser 這個帳號。

$ sudo mkdir /etc/vsftpd
$ sudo htpasswd -dc /etc/vsftpd/passwd ftpuser

5. 重啟 server


$ sudo service vsftpd restart


6. 防火牆


$ sudo ufw allow 2211
$ sudo ufw allow proto tcp to any port 49152:65535

7. 測試


$ ftp localhost 2211

8. Monitor


$ watch ps -C vsftpd -o user,pid,stime,cmd

Reference

2013年12月15日 星期日

Ubuntu remove NetworkManager


$ sudo vim /etc/network/interfaces

如果是 dhcp
auto eth0
iface eth0 inet dhcp

如果是指定 ip, 且走 1G
auto eth0
iface eth0 inet static
address 192.168.0.7
netmask 255.255.255.0
gateway 192.168.0.254
pre-up /sbin/ethtool -s eth0 speed 1000 duplex full
dns-nameservers 192.168.0.45 192.168.8.10 8.8.8.8
dns-search foo.org bar.com
$ sudo apt-get purge network-manager
$ sudo ifup eth0

Reference

Linux disk utility

今天終於下定決心,把 mac mini 第二顆硬碟也 format 起來用。

因為是 Mac, 所以首先要了解 GPT, 這是下一代的磁碟分割程式。這是介紹他的文章
這邊紀錄一下他有用到的指令:
  • blkid : 列出在目前 linux 登記有案的磁碟分割區,可以用來查 UUID (在 /etc/fstab 會用到)
  • gdisk : fdisk 只能處理 MBR 分割區格式。如果要處理 GPT 請改用 gdisk
    • gdisk -l : 列出目前分割區。
    • gdisk /dev/sdb : 不解釋
    • 進去 gdisk 後的指令
      • i 2 查看該分割狀態
      • p 同 gdisk -l
  •  lsblk : 取得詞區資訊
$ lsblk -t /dev/sdc
NAME   ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE
sdc            0   4096      0    4096     512    1 cfq       128
|--sdc1         0   4096      0    4096     512    1 cfq       128
|--sdc2         0   4096      0    4096     512    1 cfq       128
|--sdc3         0   4096      0    4096     512    1 cfq       128

這裡很有趣的是我們要看 PHY-SEC 的部分。這代表硬碟設計的時候每個 sector 是多少。新的大容量磁碟會是 4096 bytes (4K), 古早以前的硬碟會是 512 bytes。這要端看我們打算如何使用這顆硬碟。新的硬碟仍然可以把它格式化成 512 bytes,但是會進入相容模式,這樣我們就沒辦法善用這顆硬碟。