bilibili-video-download

B站视频下载裁剪压缩工具。下载bilibili视频、裁剪去除边框、压缩到指定大小时使用。支持b23.tv短链和BV号。别名:闹钟视频下载。

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "bilibili-video-download" with this command: npx skills add mimose101/xiaomi-touchscreen-alarm-clock-video-production

闹钟视频下载

依赖

  • yt-dlp: py -m pip install yt-dlp
  • ffmpeg/ffprobe: 需在PATH中

工作流

1. 下载720P视频

固定下载720P分辨率视频(格式ID: 30064+30280),文件名使用BV号:

py -m yt_dlp -f "30064+30280" -o "PATH/%(id)s.%(ext)s" --merge-output-format mp4 URL

说明: 30064为720P视频流,30280为音频流。使用 %(id)s 自动提取BV号作为文件名,避免多个视频下载时文件名冲突。

2. 裁剪边框(可选)

使用 --crop 参数指定裁剪区域,默认裁剪参数 792:600:432:56(去除B站边框):

ffmpeg -y -i IN -vf "crop=792:600:432:56" -c:v libx264 -crf 18 -c:a copy OUT

720P固定裁剪参数: crop=792:600:432:56 如无需裁剪,传入 --no-crop

3. 剪切视频(可选,默认去除前后各10秒)

步骤1: 去除前10秒

ffmpeg -y -i IN -ss 00:00:10 -c:v libx264 -crf 18 -c:a copy TEMP

步骤2: 获取剩余视频时长

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 TEMP

步骤3: 去除后10秒(总时长-10)

ffmpeg -y -i TEMP -t (duration-10) -c:v libx264 -crf 18 -c:a copy OUT

说明: 固定去除片头10秒和片尾10秒,总时长减少20秒。如无需剪切,传入 --no-trim

4. 压缩到目标大小

目标:压缩到10MB以内

步骤1: 获取视频时长

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 INPUT_VIDEO

步骤2: 计算动态码率 使用Python计算码率参数(以目标10MB为例):

target_MB = 10
duration = 217.345783  # 从步骤1获取的实际时长
vbr = max(int((target_MB * 0.9 * 8 * 1024) / duration - 64), 100)  # 视频码率
maxrate = int(vbr * 1.25)  # 最大码率
bufsize = int(vbr * 2.5)   # 缓冲大小
# 示例输出: vbr=275k, maxrate=344k, bufsize=688k

计算公式:

  • 视频码率: vbr = max(int((target_MB * 0.9 * 8 * 1024) / duration - 64), 100)
  • 最大码率: maxrate = int(vbr * 1.25)
  • 缓冲大小: bufsize = int(vbr * 2.5)

步骤3: 执行压缩

ffmpeg -y -i INPUT_VIDEO -c:v libx264 -b:v 275k -maxrate 344k -bufsize 688k -c:a aac -b:a 64k -ar 44100 OUTPUT_VIDEO

验证压缩结果:

ffprobe -v error -show_entries format=size -of default=noprint_wrappers=1:nokey=1 OUTPUT_VIDEO

实际案例参考:

  • 输入视频: 792x600, 时长217秒, 约22.4MB
  • 压缩参数: vbr=275k, maxrate=344k, bufsize=688k
  • 输出结果: 约9.0MB, 成功压缩到10MB以内

5. 一键脚本

py scripts/download_and_process.py URL [选项]

必选参数:

  • url — B站视频URL(支持BV号、b23.tv短链)

可选参数:

参数默认值说明
--format_id30064+30280下载格式ID
--crop792:600:432:56裁剪参数(宽:高:左:上)
--no-crop跳过裁剪步骤
--no-trim跳过去头尾步骤(默认去除前后各10秒)
--max_size_mb10目标文件大小(MB)
--filename自动从URL提取输出文件名(不含扩展名)
--output_dirDocuments输出目录

使用示例:

# 默认处理(下载→裁剪→去头尾→压缩)
py scripts/download_and_process.py "https://www.bilibili.com/video/BV1m24y1d7xw"

# 不裁剪,直接去头尾并压缩
py scripts/download_and_process.py "https://www.bilibili.com/video/BV1m24y1d7xw" --no-crop

# 不去头尾,只裁剪并压缩
py scripts/download_and_process.py "https://www.bilibili.com/video/BV1m24y1d7xw" --no-trim

# 完全不裁剪也不去头尾
py scripts/download_and_process.py "https://www.bilibili.com/video/BV1m24y1d7xw" --no-crop --no-trim

# 自定义裁剪区域
py scripts/download_and_process.py "https://www.bilibili.com/video/BV1m24y1d7xw" --crop "800:600:240:60"

# 压缩到20MB以内
py scripts/download_and_process.py "https://www.bilibili.com/video/BV1m24y1d7xw" --max_size_mb 20

脚本自动依次执行:下载 → [裁剪] → [去头去尾] → 压缩到目标大小(中括号为可选步骤)

文件名约定

所有视频文件必须以BV号命名,禁止使用固定文件名如 bilibili_video.mp4

  • 下载时: -o "PATH/%(id)s.%(ext)s" → 生成 BV1N14y1Y7uN.mp4
  • 中间文件: {bvid}_raw.mp4, {bvid}_cropped.mp4, {bvid}_trimmed.mp4, {bvid}_trim_start.mp4
  • 最终输出: {bvid}.mp4

这样每个视频都有独立文件名,不会相互覆盖。

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

TRMNL

Send concise text, notifications, or updates with optional Markdown and images to a TRMNL e-ink terminal display via webhook.

Registry SourceRecently Updated
General

Update Plus

Full backup, update, and restore for OpenClaw - config, workspace, and skills with auto-rollback

Registry SourceRecently Updated
2.7K2hopyky
General

gangtise-data

通过 Gangtise 金融 Open API 拉取结构化量化数据,包括 A 股日 K 行情、财务三大报表、主营构成与估值分位等。需在 scripts 目录配置授权(.authorization),证券参数须为完整代码(如 600519.SH)。当用户需要可落盘的表格化行情与基本面数据时使用。

Registry SourceRecently Updated
General

Kenya Tax Rates

Calculate Kenya payroll deductions - PAYE, SHIF, NSSF, Housing Levy with accurate 2024/2025 rates

Registry SourceRecently Updated