📚 我的文章

FFmpeg自动检测裁剪黑边

#!/bin/bash

# 用法提示
if [ "$#" -ne 1 ]; then
  echo "用法: $0 <输入文件路径>"
  exit 1
fi

INPUT="$1"
OUTPUT="${1%.*}"
OUTPUT_EXT="${1##*.}"

# 自动检测 crop 参数
CROP=$(ffmpeg -i "$INPUT" -vf cropdetect=24:16:0 -t 30 -f null - 2>&1 |
  grep -o 'crop=[^ ]*' | sort | uniq -c | sort -nr | head -n1 | awk '{print $2}')

if [ -z "$CROP" ]; then
  echo "未能检测到有效的 crop 参数"
  exit 1
fi

echo "检测到裁剪参数: $CROP"

# 执行裁剪
ffmpeg -i "$INPUT" -vf "$CROP" -c:v libx264 -crf 10 -c:a copy "${OUTPUT}_crop.${OUTPUT_EXT}"

Linux硬盘故障相关的查询命令

查看硬盘及对应的UUID信息 #

# 查看硬盘及对应的UUID信息 或者是所有硬盘的UUID信息
blkid [/dev/sda1]  # lsblk -o NAME,UUID -p

查看UUID对应的硬盘路径 #

blkid -U 383bc776-fc1a-4040-ad8f-45f4f5d96fcf

查看硬盘信息 #

lshw -class disk

检测磁盘是否损坏 #

badblocks -b 4096 -v /dev/sda # 也有坏快的屏蔽方式这个里就不列举了

点亮硬盘LED #

dd if=/dev/sda of=/dev/null bs=1M count=100 # 点亮硬盘LED

查看服务器序列号 #

dmidecode -t 1  # 查看对应的'Serial Number'字段

使用FFmpeg生成测试视频

生成23.976fps的测试视频 #

ffmpeg -f lavfi -i testsrc=size=1280x720:rate=30 -vf "drawtext=text='%{pts\:hms} %{n}':x=(w-text_w)/2:y=100:fontsize=48:fontcolor=white:boxcolor=black@0.5:borderw=2" -r 23.976 -t 10 -y output.mp4

Mamba替代Conda

mamba是一个conda的替代品,可以加速conda的包管理,提升包管理的效率。

安装 #

brew install micromamba

配置 #

# 根据命令提示,修改~/.zshrc文件
micromamba shell init -s zsh -p ~/.micromamba
# 添加配置文件
$ cat ~/.mambarc
channels:
  - conda-forge
always_yes: false

使用 #

micromamba create -n python310 python=3.10
# 激活环境
micromamba activate python310
# 然后可以用 micromamba 或者 pip 装东西
micromamba install package_1 package_2=version
## 具体请参考 https://mamba.readthedocs.io/en/latest/
micromamba --help

Hugo网站建设

安装 Hugo #

下载地址:https://github.com/gohugoio/hugo/releases

创建网站 #

hugo new site book
cd book
git init
git submodule add https://github.com/alex-shpak/hugo-book themes/hugo-book

本地调试 #

hugo server --disableFastRender --minify --ignoreCache

github actions #

mkdir -p .github/workflows
touch .github/workflows/build.yml
name: Build
on:
  push:
    branches:
      - main # Set a branch to deploy
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-20.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.123.7'
          # 是否启用 hugo extend
          extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: ${{ github.ref == 'refs/heads/main' }}
        with:
          github_token: ${{ secrets.GH_PAGE_ACTION_TOKEN }}
          publish_dir: ./public

github pages #

可以在项目的 Settings 中开启 Pages 服务,然后选择 Branch 为gh-pages即可。
如果想要定制域名,可以参考官方文档 About custom domains and GitHub Pages

...

FFmpeg检测透明通道

检测透明通道 #

FFmpeg命令 #

$ ffmpeg -v error -i 123.mp4 -vf "select='eq(n,0)', alphaextract" -f null /dev/null

[Parsed_alphaextract_1 @ 0x7fe8f5208100] Requested planes not available.
[Parsed_alphaextract_1 @ 0x7fe8f5208100] Failed to configure input pad on Parsed_alphaextract_1
[vf#0:0 @ 0x7fe8f5005f40] Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while filtering: Invalid argument
[out#0/null @ 0x7fe8f5004900] Nothing was written into output file, because at least one of its streams received no packets.

判断条件 #

如果出现以上报错信息,则说明视频中没有透明通道。

...

ssh客户端于服务端保持连接

linux ssh 默认没有开启心跳,所以很容易导致连接断开。

服务端设置 #

sudo vim /etc/ssh/sshd_config

TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 3

客户端设置 #

一般还是建议在客户端设置。

sudo vim /etc/ssh/ssh_config

TCPKeepAlive yes
ServerAliveInterval 60
ServerAliveCountMax 3

Centos7系统升级内核版本

使用ELRepo仓库升级系统内核

查看内核版本 #

uname -r

uname -a

cat /etc/redhat-release

安装ELRepo yum源 #

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

查看可用的内核版本 #

yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

...
kernel-lt.x86_64              4.4.155-1.el7.elrepo
kernel-lt-devel.x86_64        4.4.155-1.el7.elrepo
...

安装稳定版本内核 #

yum --enablerepo=elrepo-kernel install kernel-lt

设置引导(grub2) #

查看所有内核版本 #

sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg

0 : CentOS Linux (4.4.241-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-651e1b90bb3149809cdeb8cc80e72c43) 7 (Core)

设置新的默认引导的内核版本 #

方法1

...

dnsmasq安装与配置

dnsmasq是一个小巧且方便地用于配置DNS和DHCP的工具,适用于小型网络,它提供了DNS功能和可选择的DHCP功能。

安装服务 #

sudo yum install dnsmasq

常用配置 #

cat /etc/dnsmasq.conf

#######这里表示 严格按照 resolv-file 文件中的顺序从上到下进行 DNS 解析, 直到第一个成功解析成功为止
#strict-order

###同时发送所有的查询到所有的dns服务器,谁快就用谁
all-servers

listen-address=127.0.0.1

###不让dnsmasq去读/etc/hosts文件
no-hosts

## 设置缓存条目
cache-size=10240

#允许客户端缓存的时间单位为秒
local-ttl=10
max-cache-ttl=15

###开启日志
#log-queries
##配置日志文件
#log-facility=/data/logs/dnsmasq.log
cat /etc/resolv.dnsmasq.conf

nameserver 223.5.5.5
nameserver 114.114.114.114
nameserver 222.246.129.80

启动服务 #

systemctl start dnsmasq

验证方法 #

dig www.zhangwenbing.com

其他配置 #

国内指定DNS #

server=/cn/114.114.114.114
server=/taobao.com/114.114.114.114
server=/taobaocdn.com/114.114.114.114

国外指定DNS #

server=/google.com/8.8.8.8

屏蔽网页广告 #

address=/ad.youku.com/127.0.0.1
address=/ad.iqiyi.com/127.0.0.1

其他功能 #

除了DNS,还支持DHCP和TFTP,由于暂时用不到,这里就不一一例举了。

...

使用ssh配置跳板机

简单的修改/etc/ssh/ssh_config文件即可通过跳板机,直达目标服务器。

配置方法 #

cat /etc/ssh/ssh_config

Host jump-server
    User xxxx
    Hostname yyy.yyy.yyy.yyy
    Port 22

Host 10.*
    ProxyCommand ssh -q -W %h:%p jump-server

Host 支持通配符 *?

...