← 博客首页 我的项目 浏览器版 ASCII 视频引擎
上线后能否使用?
✅ 可以。本说明页是纯静态 HTML,部署到 GitHub Pages 等站点后路径形如: /scripts/ascii-generator/guide.html — 任意现代浏览器均可阅读。 ✅ 浏览器版(vid2ascii-gif)在 HTTPS 站点上可用:GitHub Pages 默认 HTTPS,满足 FFmpeg WASM 与 COI 要求;首次打开需下载 wasm(约数十 MB),请稍候。 ⚠️ 仅当你用资源管理器双击本地 HTML(file://)时,浏览器版会失败 — 请用 Hugo 预览或 run_vidascii-git.bat。
ASCII Generator(Python)· 部署与说明
▶ 上游开源项目

作者:Viet Nguyen(MIT License)

https://github.com/vietnh1009/ASCII-generator/

本目录脚本在该仓库基础上保留了图片/视频转 ASCII 能力;本站副本另修正了 MP4 VideoWriter 初始化并加入 tqdm 进度条。

▶ 本页资源
环境与依赖
▶ Python 与 pip
安装依赖(清华源)
python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python pillow numpy tqdm
▶ 常见问题
若代理导致清华源超时,可改用官方 PyPI。
Pillow 10+ 使用 getbbox 测字宽(本副本已适配)。
输出 MP4 使用 mp4v;首帧后再创建 VideoWriter
进度条(与 tqdm 行为类似)
演示
0% 0/0 帧
脚本要点(已修复旧版 try/out 写法)

完整源码见同级 video2video_color.py。核心:首帧得到尺寸后再创建写入器,并用 tqdm 更新进度。

out = None pbar = tqdm(total=total_frames, desc="转换进度", unit="帧") # total 未知时可省略 while cap.isOpened(): flag, frame = cap.read() if not flag: break # ... 生成 out_image (numpy BGR) ... if out is None: fourcc = cv2.VideoWriter_fourcc(*"mp4v") out = cv2.VideoWriter(opt.output, fourcc, fps, (out_image.shape[1], out_image.shape[0])) out.write(out_image) pbar.update(1) pbar.close() cap.release() if out is not None: out.release()
运行示例

在项目根目录(含 fonts/)执行:

python video2video_color.py --input data/input.mp4 --output data/output_color.mp4 --mode simple --background black --num_cols 120 --scale 1 --fps 0 --overlay_ratio 0.15

data/input.mp4 换成你的路径;上方 Python 路径会同步进命令。