How to extract code from a video tutorial
Three workflows for getting the source code out of a programming tutorial video — from manual frame capture to a full transcript-plus-screenshot pipeline.
Programming tutorials on YouTube and elsewhere are a great learning format and a terrible reference format. The code is on screen but not copy-pasteable. Three patterns get the code into your editor without retyping it.
1. Check the description first
Sounds obvious; people skip it. Maybe 60% of decent programming tutorials link a GitHub repo, a CodePen, or a Gist in the description. The rest of this post is for the other 40%.
2. Single snippet: pause + screenshot + extract
Pause on the frame with the code, screenshot, drop into ExtractFox's code extractor or any image-to-text tool that preserves indentation. Done in 60 seconds for one snippet.
Why a code-aware extractor matters: generic OCR confuses similar characters (i, l, 1, |), drops indentation on monospaced fonts, and breaks on syntax-highlighted text. A multimodal model that knows what code looks like fixes all three.
3. Whole tutorial: scripted pipeline
For a long tutorial where the code evolves across many screens, here's the pattern:
- Download the video: yt-dlp "https://youtube.com/watch?v=..."
- Extract frames every N seconds: ffmpeg -i video.mp4 -vf fps=1/5 frame_%04d.png (one frame every 5 seconds).
- Filter to frames with code: a quick model call per frame asking "does this contain source code? yes/no" prunes the talking-head shots.
- Extract code from kept frames with a code extractor.
- Deduplicate near-identical frames (consecutive frames usually show almost the same code as the author types).
Pair with the transcript (yt-dlp --write-auto-subs or Whisper) to get the explanation alongside the code.
4. From a recorded screen share or conference talk
Conference talks usually publish slides separately on the conference site. Find them — extracting code from a 1080p YouTube re-encode is much worse than extracting from the original PDF/PPTX. Same for live coding screencasts where the author later publishes the repo.
What you can't do well
- Extract code that scrolls off-screen — only what's visible at any moment is recoverable.
- Recover comments that were typed but immediately deleted — they were never on a frame long enough to capture.
- Reconstruct file structure when the tutorial flips between many files in a sidebar — possible but error-prone; better to consult the published repo if there is one.
Etiquette
If you publish anything based on extracted code, credit the original author. Most tutorial creators are fine with you using their teaching code; almost none are fine with seeing it republished as your own.