A Telegram bot that automatically detects and removes black bars (letterboxing/pillarboxing) from videos using FFmpeg. It features an asynchronous worker queue to handle processing-heavy tasks efficiently.
- Automatic black bar detection using FFmpeg's cropdetect filter.
- Support for custom padding: Top, Bottom, Both, or None.
- Queue-based processing with a configurable number of workers.
- Per-user concurrency limits to prevent resource exhaustion.
- Built-in health check server for compatibility with hosting platforms like Render.
- Handles videos sent directly or via the /crop reply command.
- Send a video or document directly to the bot.
- Alternatively, reply to an existing video with the /crop command.
- The bot will present an inline keyboard asking for the padding position:
- No Text: Strict crop to detected content.
- Top: Adds 30px padding to the top (useful for UI).
- Bottom: Adds 30px padding to the bottom (useful for subtitles).
- Both: Adds 30px padding to both top and bottom.
| Command | Description |
|---|---|
| /start | Display welcome message |
| /crop | Reply to a video with this command to initiate cropping |
The bot is configured via environment variables.
| Variable | Description | Default |
|---|---|---|
| BOT_TOKEN | Your Telegram bot token from @BotFather | Required |
- Python 3.x
- FFmpeg installed and accessible in the system PATH.
- A public-facing port (if using health checks for monitoring).
pip install -r requirements.txtexport BOT_TOKEN="your_bot_token_here"
python main.pyThe bot runs in polling mode but also starts a web server on 0.0.0.0:7860 for health checks.
- Create a new Web Service on Render.
- Connect your repository.
- Set Runtime to Python.
- Set the Start Command to:
python main.py- Add
BOT_TOKENto the Environment Variables. - Render will automatically detect the server on port 7860 to verify the service is live.
- aiogram 3.x for asynchronous Telegram interaction.
- FFmpeg
- The bot downloads the video to a temporary directory.
- It runs a cropdetect pass to determine the bounding box of the content.
- It applies user-selected padding adjustments to the crop parameters.
- It re-encodes the video using libx264 (
fastpreset) while copying the audio stream to preserve quality. - The processed file is uploaded back to the user, and temporary files are cleaned up.
- aiogram — Telegram Bot framework
- aiohttp — Asynchronous HTTP server and client
- FFmpeg — Video processing and analysis tool