Skip to content

Instantly share code, notes, and snippets.

@todbot
Last active March 5, 2026 23:05
Show Gist options
  • Select an option

  • Save todbot/6b8576ee0d5ecf0f04916032be7bcd94 to your computer and use it in GitHub Desktop.

Select an option

Save todbot/6b8576ee0d5ecf0f04916032be7bcd94 to your computer and use it in GitHub Desktop.
Create a small video clip (for social sharing) of a larger podcast video hosted on Youtube
#!/bin/bash
#
# Create a small video clip of a podcast-like video on youtube.
# 4 March 2026 - Tod Kurt / @todbot
#
# This script does the following:
# - Download the video of the podcast
# - Download the subtitles of the podcast video
# - Create a copy of the entire video with the captions burned in
# - Snip the specified section of that video with audio waveform overlay
#
# e.g.
# URL='https://www.youtube.com/watch?v=ynzHEPQZMj0'
# TIME_START=00:20:48
# DURATION=59
# as seen here: https://mastodon.social/@todbot/116173364622937223
#
# Note: Your install of "ffmpeg" must have subtitle support.
# You can check if yours does with "ffmpeg -filters 2>&1 | grep subtitle"
URL=$1
TIME_START=$2
DURATION=$3
# Check all args are provided
if [ $# -lt 3 ]; then
echo "Usage: $0 <youtube-url> <start-time> <duration-seconds>"
exit 1
fi
if [ ! -f "podcast.webm" ] || [ -f "podcast.mp4" ] ; then
# download video and get the filename
printf "|\n|---------- Downloading video file...\n|\n"
yt-dlp --print-to-file after_move:filepath podcast_filename.txt -o "podcast.%(ext)s" "${URL}"
VIDEO_FILENAME=$(cat podcast_filename.txt)
rm podcast_filename.txt
else
VIDEO_FILENAME=$(ls podcast.{mp4,webm} 2>/dev/null | head -1)
fi
echo "Video filename is ${VIDEO_FILENAME}"
if [ ! -f "podcast.en.srt" ] ; then
# download captions / sub-titles to "podcast.en.srt
printf "|\n|---------- Downloading captions file...\n|\n"
yt-dlp --write-sub --write-auto-sub --sub-lang en --sub-format srt --skip-download -o "podcast" "${URL}"
fi
if [ ! -f "podcast_with_captions.mp4" ] ; then
# burn in captions
printf "|\n|---------- Burning in captions to video file...\n|\n"
ffmpeg -y -i ${VIDEO_FILENAME} \
-vf "subtitles=podcast.en.srt" \
-c:v libx264 -c:a copy podcast_with_captions.mp4
fi
# Clip section we want with audio visualizer
printf "|\n|---------- Clipping ${DURATION} second video starting from ${TIME_START}...\n|\n"
ffmpeg -y -ss ${TIME_START} -t ${DURATION} -i podcast_with_captions.mp4 \
-filter_complex "\
[0:a]showwaves=s=1080x300:mode=cline:colors=white:rate=30[w]; \
[0:v][w]overlay=(W-w)/2:H-h-100[v]" \
-map "[v]" -map 0:a \
-c:v libx264 -c:a aac \
podcast_clip.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment