Skip to content

Instantly share code, notes, and snippets.

@dardo82
Last active May 10, 2022 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dardo82/f6f47270039703d265e9ba32f2bc848d to your computer and use it in GitHub Desktop.
Save dardo82/f6f47270039703d265e9ba32f2bc848d to your computer and use it in GitHub Desktop.
Split videos at silence
BEGIN{ printf( "%s\n\n", ";FFMETADATA1"); t=0}
/duration/{ printf( "%s\n%s%d\n%s%.0f\n%s%.0f\n\n", "[CHAPTER]", "TIMEBASE=1/", 10^6, "START=", t*10^6, "END=", $5*10^6); t=$5}
END{ printf( "%s\n%s%d\n%s%.0f\n%s%.0f\n\n", "[CHAPTER]", "TIMEBASE=1/", 10^6, "START=", t*10^6, "END=", d*10^6)}
BEGIN { printf( "%s\n\n", ";FFMETADATA1"); t=0}
{ printf( "%s\n%s%d\n%s%.0f\n%s%.0f\n\n", "[CHAPTER]", "TIMEBASE=1/", 1, "START=", t, "END=", $1); getline; t=$1}
END { printf( "%s\n%s%d\n%s%.0f\n%s%.0f\n\n", "[CHAPTER]", "TIMEBASE=1/", 1, "START=", t, "END=", s)}
#!/bin/sh
# DownLoad and Split YouTube videos at silence.
SHOW="$1"; DATE="$2"; D="$3"; N="$4"
ID=$(yt-dlp --get-id "ytsearch: $SHOW $DATE")
MP4="$ID.mp4"; FFMD="$ID.ffmd"
L="${LANG%.*}"; SRT="$ID.${L%_*}.srt"
AWK="${0%/*}/ffprobe2ffmd.awk"
yt-dlp --id -f "135+140" "$ID"
S=$(ffprobe -of "default=nw=1:nk=1" \
-show_entries "format=duration" "$MP4")
ffprobe -of "default=nw=1:nk=1" -f lavfi \
-i "amovie=$MP4, silencedetect=d=$D:n=-${N}dB" \
-show_entries "tags=lavfi.silence_end" \
| awk -v s="$S" -f "$AWK"> "$FFMD"
mpv --chapters-file="$FFMD" "$MP4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment