在 Bash 的迴圈裡面跑 FFmpeg

Bash 的迴圈裡面跑 FFmpeg 有時候會遇到奇怪的靈異現象,發現是這個問題:「execute ffmpeg command in a loop」。

原因是當你用 while + read 產生迴圈時會有對 stdin 的操作行為,而 FFmpeg 預設也會去讀 stdin (WTF),於是兩邊就打架了。

解法是用 -nostdin 叫 FFmpeg 不要手賤去讀 stdin,這樣就可以解決這個問題。

把 PEM Private Key 檔轉成 SSH Public Key 格式...

RSA 中,單獨靠 Private Key 是無法算出 Public Key 的,不過在 PEM 檔裡因為都有紀錄,所以可以取出:

openssl rsa -in aws.pem -pubout

不過取出的格式需要再轉一次讓 OpenSSH 可以吃:(參考「Convert pem key to ssh-rsa format」這篇的方法)

ssh-keygen -f aws.pub -i -m PKCS8

雖然 ssh-keygen 不接受 - 當 stdin,但可以利用 /dev/stdin 直接串起來:

openssl rsa -in aws.pem -pubout | ssh-keygen -f /dev/stdin -i -m PKCS8