Skip to content

Instantly share code, notes, and snippets.

@seanghay
Last active July 12, 2023 08:23
Show Gist options
  • Save seanghay/c04cf5f661dfa21114fb284e1a1c548c to your computer and use it in GitHub Desktop.
Save seanghay/c04cf5f661dfa21114fb284e1a1c548c to your computer and use it in GitHub Desktop.
Download & Trim Video using yt-dlp and ffmpeg
#!/usr/bin/env bash
# Download & Trim Video
# ./run.sh video_id out.mp4 00:00 1:00
OUTPUT_FILE=$2
VIDEO_ID=$1
yt-dlp --quiet --force-overwrites \
-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" \
--output $OUTPUT_FILE $VIDEO_ID
ffmpeg -hide_banner \
-loglevel error \
-y -ss 00:$3 -to 00:$4 \
-i $OUTPUT_FILE \
-c copy "${OUTPUT_FILE%.*}.trim.mp4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment