Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert scrolling article videos into long images and extract text with OCR.

Notifications You must be signed in to change notification settings

comoysha/scrollunroll

Repository files navigation

ScrollUnroll - 视频滚动文章提取工具

一个强大的Python工具,能够从滚动视频中自动提取和识别文章内容,将视频转换为可读的文本文档。

✨ 特性

  • 🎥 智能帧提取: 使用FFmpeg从视频中提取关键帧
  • 🧩 自动拼接: 智能识别重叠区域,将滚动帧拼接成完整长图
  • 🔍 OCR识别: 基于Tesseract的高精度中文文本识别
  • 📝 文本处理: 自动清理和格式化识别结果
  • 🚀 一键运行: 简单命令即可完成整个流程

🛠️ 技术栈

  • Python 3.8+
  • FFmpeg - 视频帧提取
  • OpenCV - 图像处理
  • PIL/Pillow - 图像操作
  • Tesseract OCR - 文本识别
  • pytesseract - Python OCR接口

📋 系统要求

macOS

# 安装FFmpeg
brew install ffmpeg
# 安装Tesseract及中文语言包
brew install tesseract
brew install tesseract-lang

Ubuntu/Debian

# 安装FFmpeg
sudo apt update
sudo apt install ffmpeg
# 安装Tesseract及中文语言包
sudo apt install tesseract-ocr
sudo apt install tesseract-ocr-chi-sim
sudo apt install tesseract-ocr-chi-tra

Windows

  1. 下载并安装 FFmpeg
  2. 下载并安装 Tesseract OCR
  3. 确保将FFmpeg和Tesseract添加到系统PATH

🚀 快速开始

1. 克隆项目

git clone https://github.com/yourusername/ScrollUnroll.git
cd ScrollUnroll

2. 安装依赖

pip3 install -r requirements.txt

3. 运行工具

python3 main.py your_video.mp4

📖 使用方法

基本用法

# 处理视频文件
python3 main.py video.mov
# 指定输出目录
python3 main.py video.mp4 --output custom_output
# 调整帧提取频率(每秒提取帧数)
python3 main.py video.mp4 --fps 2

高级用法

# 仅提取帧,不进行拼接和OCR
python3 main.py video.mp4 --extract-only
# 使用现有帧进行拼接和OCR
python3 main.py video.mp4 --use-existing-frames
# 保留中间文件用于调试
python3 main.py video.mp4 --keep-frames

📁 项目结构

ScrollUnroll/
├── main.py # 主程序入口
├── frame_extractor.py # 视频帧提取模块
├── frame_stitcher.py # 帧拼接模块
├── ocr_processor.py # OCR文本识别模块
├── tesseract_ocr.py # Tesseract独立处理脚本
├── requirements.txt # Python依赖
├── output/ # 输出目录
│ ├── frames/ # 提取的视频帧
│ ├── long_article.png # 拼接后的长图
│ └── article.txt # 识别的文本内容
└── README.md # 项目文档

🔧 配置选项

OCR配置

ocr_processor.py 中可以调整以下参数:

# 图像分割配置
CHUNK_HEIGHT = 3000 # 每块高度(像素)
OVERLAP = 100 # 重叠区域(像素)
# Tesseract配置
TESSERACT_CONFIGS = [
 '--psm 6 -c preserve_interword_spaces=1', # 单列文本
 '--psm 4 -c preserve_interword_spaces=1', # 单列可变文本
 '--psm 3 -c preserve_interword_spaces=1' # 全自动分割
]

拼接配置

frame_stitcher.py 中可以调整:

# 相似度阈值
threshold = 0.8 # 重叠检测阈值
identical_threshold = 0.98 # 相同帧检测阈值

📊 处理流程

  1. 视频帧提取 📹

    • 使用FFmpeg按指定FPS提取视频帧
    • 自动创建frames目录存储帧文件
  2. 智能拼接 🧩

    • 分析相邻帧的重叠区域
    • 使用模板匹配算法找到最佳拼接点
    • 生成完整的长图文件
  3. 文本识别 🔍

    • 将长图分割为适合OCR的块
    • 使用多种Tesseract配置提高识别率
    • 自动去重和文本清理
  4. 结果输出 📝

    • 保存清理后的文本到article.txt
    • 保留原始长图用于验证

🎯 使用场景

  • 📱 手机录屏文章: 提取微信文章、网页长文等
  • 📺 视频字幕: 从滚动字幕视频中提取文本
  • 📄 文档数字化: 将滚动浏览的PDF转为文本
  • 📚 学习笔记: 从教学视频中提取文字内容

⚠️ 注意事项

  1. 视频质量: 确保视频清晰度足够,文字可读
  2. 滚动速度: 滚动不宜过快,建议匀速滚动
  3. 文字对比度: 黑白对比度高的文字识别效果更好
  4. 语言支持: 目前主要支持中文和英文识别

🐛 故障排除

常见问题

Q: FFmpeg命令失败

# 检查FFmpeg是否正确安装
ffmpeg -version
# 重新安装FFmpeg
brew reinstall ffmpeg # macOS

Q: Tesseract识别率低

# 检查中文语言包
tesseract --list-langs
# 重新安装语言包
brew reinstall tesseract-lang # macOS

Q: OpenCV导入错误

# 重新安装OpenCV
pip3 install opencv-python --upgrade

🤝 贡献

欢迎提交Issue和Pull Request!

  1. Fork本项目
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启Pull Request

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情

🙏 致谢


如果这个项目对你有帮助,请给个 ⭐ Star!

About

Convert scrolling article videos into long images and extract text with OCR.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /