References

Shell

chezmoi

# install
sh -c "$(curl -fsLS get.chezmoi.io)"
sudo mv bin/chezmoi /usr/local/bin

# init
chezmoi init

# add dotfile
chezmoi add {dotfile}

# goto git dir
chezmoi cd

# init chezmoi and pull repo
chezmoi init {git_url}

# apply changes
chezmoi apply -v

# pull and apply
chezmoi update -v

tmux

可以通过修改配置 .tmux.conf 修改 prefix

# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

Sessions

  • Start New Session: tmux
  • New Session with Name: tmux new -s {{session_name}} -n {{window_name}}
  • List sessions: tmux ls
  • Detach: prefix + D
  • Attach: tmux a -t {{name}}

Windows

  • New Window: prefix + C
  • Close Window: Ctrl-D
  • List Windows: prefix + W
  • Go to Nth Window: prefix + {{N}}
  • Go to Previous Window: prefix + P
  • Go to Next Window: prefix + N
  • Rename Current Window: prefix + ,

Panes

  • Split Horizontally: prefix + "
  • Split Vertically: prefix + %
  • Move to Pane: prefix + Up/Down/Left/Right
  • Zoom In/Out: prefix + Z
  • Pane Arrangement: prefix + Space
  • Close Pane: prefix + X
  • Break a Pane to a New Window: prefix + !

Misc

  • Show All Bind Keys: prefix + ?

Image

magick(convert)

# resize
convert input.jpg -resize 800x600 output.jpg

# convert format
convert image.jpg image.png

# crop
convert input.jpg -crop 200x200+100+100 output.jpg

# add text
convert input.jpg -pointsize 36 -draw "text 100,100 'Hello, World!'" output.jpg

gnuplot

gnuplot入门

# linux
apt-get install gnuplot

# macOS
brew install gnuplot

lsix

安装

sudo apt install imagemagick

Github - lsix项目中下载程序,放入目录/usr/local/bin

查看图片

lsix pic.png

screencapture

Usage:

# capture the entire screen
screencapture screenshot.png

# capture a specific window
screencapture -W screenshot.png

# x, y: top-left coordinates, w, h: width and height
screencapture -R<x,y,w,h> screenshot.png

cliclick

Install:

brew install cliclick

Usage:

# Get the current mouse position
cliclick p

Music

cmus

Views:

  1. Library
  2. Sorted library
  3. Playlist
  4. Play queue
  5. Browser
  6. Filters
  7. Settings

Commands:

  • 添加音乐库::add ~/Music
  • 清除::clear

Player:

Key Key Key Key
z previous left seek -5s C continue +/= volume +10%
x play right seek +5s s shuffle - volume -10%
c pause , seek -1m r repeat
v stop . seek +1m ^R repeat current
b next

文档:

cmus - Doc

MPV

Installation

# MacOS
brew install mpv

# Ubuntu
sudo apt install mpv

Usage

mpv *.mp3

# shuffle playlist
mpv --shuffle dir/

# plays streams
mpv --no-video 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'

# list devices
mpv --audio-device=help

IINA

Alias

alias iina="/Applications/IINA.app/Contents/MacOS/iina-cli"

Usage

# 播放文件
iina *.mp3

Video

视频处理相关知识

帧率:FPS(Frames Per Second),一秒钟的帧数,一般大于25,也就是每帧间隔40ms以内。人眼看起来比较流畅

I帧:关键帧,可单独解码出图片

P帧:与前一帧的变化量,需要前一帧解码

B帧:与其他帧相关,无法单独解码

码率:单位时间数据流量,如果每一帧的数据一样大,那么码率是固定的。但是实际上帧分为不同类型压缩后数据大小也不同,因此发送关键帧时码率会大于平均码率

VBR(Variable Bit Rate):变比特率,比特率可以变动优先保证视频质量,在网络中容易造成流量拥塞而丢包

CBR(Constant Bit Rate):定比特率,优先保证码率的均匀性,但是当场景变化剧烈时会牺牲图像质量

ffprobe

# show info
 -i <input>

# show format
ffprobe -show_format -i <input>

# show streams
ffprobe -show_streams -i <input>

# show frames
ffprobe -show_streams -show_frames -i <input>

ffmpeg

params

  • -r: framerate
  • -b: bitrate
  • -c: codec
  • -f: format
  • -g: GOP(关键帧间距)
ffmpeg \
    -f mjpeg \ # 格式
    -i $stream_url \ # 视频流地址
    -reconnect 1 \
    -loglevel 16 \
    -c:v mjpeg \
    -r $rate \ # framerate
    -an \ # disable audio
    -y \ # overwrite output files
    -t 10 \ # record 10 seconds
    -copyts \ # copy source timestamp
    "out.mp4" # output filename

# truncate
ffmpeg -i input.mp3 sss 00:00:41 -to 00:01:12 -c copy  output.mp3

# fade-in/fade-out
ffmpeg -i input.mp3 -af "afade=t=in:st=0:d=5" output.mp3    # fade-in for 5 seconds since 0 sec
ffmpeg -i input.mp3 -af "afade=t=out:st=30:d=3" output.mp3  # fade-in for 3 seconds since 30 sec

# segment
ffmpeg \
    -f mjpeg \ # 格式
    -i $stream_url \ # 视频流地址
    -c:v mjpeg \
    -f segment \ 
    -segment_time 60 \ # segment every 60 seconds
    -segment_format mp4 "out%03d.mp4"

# stream with http
ffmpeg \
    -f mjpeg \ # 格式
    -re \ # remain source framerate
    -i $stream_url \  # 视频流地址
    -c copy \ # avoid reencoding
    -listen 1 \ # act as an HTTP server
    -f mp4 -movflags frag_keyframe+empty_moov \ # get a fragmented MP4
    http://localhost:8080
    
# 推流
# http://trac.ffmpeg.org/wiki/StreamingGuide
ffmpeg \
    -re \
    -i <input> \
    -c:v libx264 \
    -a:v aac \
    -f flv \
    rtmp://localhost:port/live/livestream

Download

yt-dlp

yt-dlp - README

yt-dlp - format selection examples

A youtube-dl fork with additional features and fixes

# download metadata
yt-dlp --dump-json <URL>  | > meta.json

# simulate and print title
yt-dlp --print title --simulate <URL>
# or
yt-dlp --quiet --no-warnings  --dump-json <URL> | jq .title

# list formats
yt-dlp --list-formats <URL>

# write subtitles
yt-dlp --write-subs --sub-langs "en,zh-Hans" <URL>

# embed subtitles
yt-dlp --embed-sub <URL>

# embed auto-generated subtitles
yt-dlp --write-auto-sub --embed-sub <URL>

# output
yt-dlp --output "%(playlist_index)s-%(title)s.%(ext)s" <URL>

# format selection
yt-dlp --format "(mp4)[height<=1080]" <URL>

# download best quality audio
yt-dlp --extract-audio --audio-format best <URL>
# download audio as mp3
yt-dlp --extract-audio --audio-format mp3 <URL>
yt-dlp --extract-audio --audio-format mp3 -f 'ba' <URL>

Plugin-oauth2

Youtube OAuth2 for yt-dlp

Install

python3 -m pip install -U https://github.com/coletdjnz/yt-dlp-youtube-oauth2/archive/refs/heads/master.zip

Usage

yt-dlp --username oauth2 --password '' <URL>

youtube-dl

youtube-dl http://youtube.com/video

# 下载不高于720p的视频
youtube-dl -f 'bestvideo[height<=720]+bestaudio/best[height<=720]'

# 获取播放列表
youtube-dl --get-id --get-title 'https://www.youtube.com/playlist?list=PLt4soTeWYz1W2AacyFzdIOiOSK5GNdxuC'

配置文件:~/.config/youtube-dl/config

文档:

Github - youtube-dl

you-get

you-get http://youtube.com/video

aria2

安装

sudo apt install aria2
# or
sudo yum install aria2

下载aria2界面——AriaNG

Github - mayswind/AriaNg

配置文件

#文件保存路径设置,请手动更改
dir=/home/data

disk-cache=32M
file-allocation=none
continue=true
max-concurrent-downloads=10
max-connection-per-server=5
min-split-size=10M
split=20
disable-ipv6=true
input-file=/root/.aria2/aria2.session
save-session=/root/.aria2/aria2.session

## RPC相关设置 ##
# 启用RPC, 默认:false
enable-rpc=true
# 允许所有来源, 默认:false
rpc-allow-origin-all=true
# 允许非外部访问, 默认:false
rpc-listen-all=true
# 事件轮询方式, 取值:[epoll, kqueue, port, poll, select], 不同系统默认值不同
#event-poll=select
# RPC监听端口, 端口被占用时可以修改, 默认:6800
rpc-listen-port=6800
# 设置的RPC授权令牌,在设置AriaNg时需要用到,请手动更改
rpc-secret=<TOKEN>

follow-torrent=true
listen-port=6881-6999
enable-dht=true
enable-peer-exchange=true
peer-id-prefix=-TR2770-
user-agent=Transmission/2.77
seed-ratio=0.1
bt-seed-unverified=true
bt-save-metadata=false

启动

aria2c link/torrent/magnet
#
aria2c --conf-path=/root/.aria2/aria2.conf -D

无速度时解决方法

  1. 添加trackers
  2. 更换"dht.dat"文件
  3. 下载热门种子,如Ubuntu

trackers

参考

Browser

w3m

Install

sudo apt install w3m

打开网页

w3m www.google.com

常用操作

|Key|Operation| |-|-|-| |c|查看当前页URL| |=|查看页面信息| |v|查看源码| |Ctrl+v|下一页| |b|上一页| |Tab|下一个连接| |Shift+Tab|上一个连接| |u|查看链接URL| |I|下载图片| |B|后退| |q|退出|

w3m mannual

Tools

tldr

tldr: too long didn’t read

安装:

# macOS
brew install tldr

# CentOS
yum install tldr

fuzzy find

模糊搜索

Installation

# install
brew install fzf
/usr/local/opt/fzf/install

Usage:

  • 查询命令行历史:ctrl +R
  • 查询文件:ctrl+T
  • 动态预览文本:fzf --preview 'cat {}'

jq

json formatter

# install
brew install jq

Web APP

File Share

file.io

curl -F "file=@yourfile.txt" https://file.io

gofile

gofile