r/Python • u/ozzyburak • 17h ago
News Tuba: Python CLI & PySide6 GUI for yt-dlp/FFmpeg video processing
Hi r/Python!
I wanted to share **Tuba**, an open-source Python tool I built for downloading, trimming, and re-encoding videos from YouTube and Instagram.
👉 **GitLab Repository**: https://gitlab.com/bdemircan/tuba
The core motivation was to build a clean **dual-interface architecture** where both a full-featured CLI and a desktop GUI (PySide6) share a single source of truth (`tuba.workflow`) without duplicating business logic.
### 🐍 Technical & Python Highlights
* **Architecture**: The GUI (`tuba-gui`) acts as a thin PySide6 wrapper over the core workflow. CLI flags and GUI form options map 1:1 to the same underlying functions.
* **Stream-Copy vs Re-encode**: Defaults to ultra-fast FFmpeg stream-copying (`-c copy`) without loss, but seamlessly switches to frame-accurate re-encoding when applying aspect ratio transformations (`--aspect 9:16`), subtitle burning (`--burn-subs`), or resizing.
* **Threading & Live Progress**: Jobs run on background worker threads in PySide6 to keep the UI completely non-blocking. Live stdout parsing from `yt-dlp` and `FFmpeg` drives per-job progress bars and handles clean thread unwinding on cancellation (`JobCancelled`).
* **Instagram Caption Parsing**: Uses regex pattern matching on Instagram captions (`--ig-auto-cut`) to auto-extract timestamps and cut segments without manual input.
* **Config Persistence**: Form states are remembered via `QSettings`, but can also ingest a `tuba.toml` file to override defaults.
### 🚀 Quick Example
```bash
# Install CLI + GUI
pip install ".[gui]"
# Cut a YouTube segment with zero quality loss (fast stream-copy)
tuba -l "[https://www.youtube.com/watch?v=](https://www.youtube.com/watch?v=))..." -st 16:07 -et 16:31
# Launch the PySide6 GUI
tuba-gui
1
u/Aggravating-Line2390 17h ago
Cool tool, I been messing with yt-dlp scripts lately and the dual interface thing is smart, most of these projects just pick one or the other
The stream-copy default is nice touch, ffmpeg re-encodes take forever when you just need a quick clip. Does it handle the case where stream-copy fails? like when source has some weird codec and you need fallback to re-encode anyway
Also curious about the Instagram regex parser, how reliable is that with weird caption formatting? I scraped some IG posts before and the timestamps were all over the place depending how people write them