Skip to content

Instantly share code, notes, and snippets.

@colbyn
Created June 24, 2025 17:19
Show Gist options
  • Save colbyn/c9fad72c03e64fef94532f7b5af29a7d to your computer and use it in GitHub Desktop.
Save colbyn/c9fad72c03e64fef94532f7b5af29a7d to your computer and use it in GitHub Desktop.
My Automated FFMPEG hardware recoding setup (desktop screen capture + camera + multiple audio sources for redundancy) all muxed into a single master copy

πŸŽ₯ Clean Multi-Input Capture on macOS

A set of dead-simple FFmpeg helper scripts for recording high-quality, synchronized video + audio streams directly into a clean, editable .mkv master file on macOS. Designed for screen walkthroughs, project documentation, and clean archival capture using built-in or external hardware.

πŸŽ™οΈ Why Record and Mux Multiple Raw Streams?

This project is built around a "clean master capture" philosophy:

πŸ“¦ 1. Everything in One File (Synchronized)

All video and audio sources are recorded simultaneously and muxed into a single .mkv container. This guarantees perfect sync and makes file management easierβ€”no need to juggle loose video and audio files later.


🎯 2. Full Post-Production Flexibility

Recording each input (screen, webcam, mics) as independent streams gives you full control during editing:

  • Switch feeds dynamically (e.g., show webcam only when you're speaking).
  • Mix audio streams later, or discard noisy ones.
  • Choose which mic sounds best after the fact.
  • Apply effects, compression, and cuts per stream, not globally.

You’re not locked into decisions made during the recordingβ€”everything can be reprocessed non-destructively.


🎧 3. Multiple Audio Inputs = Creative + Practical Options

Different mics capture different characteristics:

  • A USB mic may sound richer, but pick up more room noise.
  • A headset mic might be clearer, but have occasional artifacts.
  • Your MacBook mic may be the fallbackβ€”good enough to recover a segment if others fail.

By recording them all, you get:

  • Redundancy against failure or interference.
  • Options for voice blending, denoising, or segment replacement.
  • A way to analyze or compare mic performance over time.

🧼 4. β€œUnadulterated” Master: No Filters, No Overlays

The master .mkv is raw in layout but clean in compression:

  • No overlays (e.g., webcam-in-corner)
  • No burned-in effects or crops
  • No baked audio mixing

This ensures:

  • Maximum editing flexibility
  • Re-usable base for different publishing formats (e.g., full walkthrough vs short clip)

πŸ—‚οΈ TL;DR:

The master recording is your source of truth: a compact, hardware-encoded, timestamp-aligned archive of everything you captured. You can cut, convert, compress, remix, or reframe as neededβ€”without re-recording or losing fidelity.


πŸ› οΈ Scripts Overview

βœ… check-hardware.sh

Checks whether your FFmpeg installation supports hardware acceleration for:

  • hevc_videotoolbox (GPU-accelerated H.265)
  • aac_at (hardware-accelerated AAC audio)

Run this once to confirm support:

./check-hardware.sh

πŸŽ›οΈ list-capture-devices.sh

Lists all available video and audio input devices recognized by FFmpeg via AVFoundation (macOS only).

./list-capture-devices.sh

You'll see output like:

AVFoundation video devices:
[0] FaceTime HD Camera
[1] iPhone Camera
[2] Capture screen 0

AVFoundation audio devices:
[0] Corsair Wireless Headset
[1] USB Mic
[2] MacBook Pro Microphone

Use these indices to configure your recording script.


🎬 record-video.sh

Records:

  • βœ… Full desktop screen capture
  • βœ… Webcam (FaceTime or external)
  • βœ… Multiple audio sources (up to 3 mics shown, easily extensible)
  • βœ… Cursor + mouse click highlights
  • βœ… Timestamped filename for archival
  • βœ… Per-stream metadata (for easier inspection/editing later)
./record-video.sh

This script muxes all video + audio inputs into a single .mkv master file, with semi-lossless quality (HEVC video + high bitrate AAC). You'll see something like:

master_2025-06-24_15-32-12.mkv

You can later process this into overlays, cropped exports, etc.


πŸŽ₯ Output File Details

The .mkv file will contain multiple labeled streams:

Track Description
v:0 Screen capture
v:1 Webcam (FaceTime HD)
a:0 Corsair wireless mic
a:1 USB mic (device 100009002)
a:2 MacBook Pro microphone

Inspect the result with:

ffprobe -show_streams -pretty master_*.mkv

Or view in VLC > ⌘I > Codec Details.


🧱 Requirements

  • macOS (tested on 2019 MacBook Pro)
  • FFmpeg with --enable-videotoolbox --enable-audiotoolbox
  • Install via Homebrew:
brew install ffmpeg

πŸ”’ Why MKV?

  • Supports multiple streams cleanly (more than MP4)
  • Doesn’t finalize the file until recording ends (safe on crash)
  • Easy to remux to MP4 later:
ffmpeg -i master.mkv -c copy output.mp4

πŸ’‘ Tips

  • You can toggle -capture_cursor or -capture_mouse_clicks if you want a clean screen.
  • Add more audio streams with more -map lines and -metadata titles.
  • Sync is guaranteed as long as streams are captured live and muxed together.
#!/usr/bin/env bash
set -euo pipefail
ffmpeg -encoders | grep -E 'hevc_videotoolbox|aac_at'
#!/usr/bin/env bash
set -euo pipefail
ffmpeg -f avfoundation -list_devices true -i ""
#!/usr/bin/env bash
set -euo pipefail
# record-video.sh β€” Capture screen + webcam + multiple audio inputs (macOS, FFmpeg)
#
# Records screen (with cursor & click highlights), webcam, and 3 audio streams into a
# synchronized .mkv master using hardware-accelerated H.265 video and high-quality AAC audio.
# Perfect for project walkthroughs, voiceover recordings, or archival self-demos.
#
# See README.md for device setup and stream labels.
# ── Device indices ───────────────────────────────────────────────
SCREEN_IDX="2:none" # Screen capture
WEBCAM_IDX="0" # FaceTime HD Camera
CORSAIR_IDX=":0" # Corsair wireless headset mic
USB_IDX=":1" # Mystery mic (100009002)
INT_MIC_IDX=":2" # MacBook Pro Mic
OUT="master_$(date +%Y-%m-%d_%H-%M-%S).mkv"
ffmpeg \
-capture_cursor 1 -capture_mouse_clicks 1 \
-f avfoundation -framerate 30 -video_size 1920x1080 -i "$SCREEN_IDX" \
-f avfoundation -framerate 30 -i "$WEBCAM_IDX" \
-f avfoundation -i "$CORSAIR_IDX" \
-f avfoundation -i "$USB_IDX" \
-f avfoundation -i "$INT_MIC_IDX" \
\
# ── Video streams ──────────────────────────────────────────────
-map 0:v -c:v:0 hevc_videotoolbox -pix_fmt yuv420p10le -b:v:0 20M \
-metadata:s:v:0 title="Screen Capture" \
-map 1:v -c:v:1 hevc_videotoolbox -pix_fmt yuv420p10le -b:v:1 8M \
-metadata:s:v:1 title="Webcam (FaceTime HD)" \
\
# ── Audio streams ──────────────────────────────────────────────
-map 2:a -c:a:0 aac_at -b:a:0 256k \
-metadata:s:a:0 title="Corsair Wireless Mic" \
-map 3:a -c:a:1 aac_at -b:a:1 256k \
-metadata:s:a:1 title="USB Mic (100009002)" \
-map 4:a -c:a:2 aac_at -b:a:2 256k \
-metadata:s:a:2 title="MacBook Pro Mic" \
\
-metadata title="Pilot Recording $(date +%Y-%m-%d)" \
-f matroska "$OUT"
@colbyn
Copy link
Author

colbyn commented Jun 25, 2025

They say real men only use TUIs …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment