Skip to content

Instantly share code, notes, and snippets.

@slashinfty
Last active July 27, 2020 12:23
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 slashinfty/d5e449a8aaed4ea6f1c5488d1752ac98 to your computer and use it in GitHub Desktop.
Save slashinfty/d5e449a8aaed4ea6f1c5488d1752ac98 to your computer and use it in GitHub Desktop.
Verifying runs
# must hanve youtube-dl streamlink ffmpeg bc
# these specific commands also have the IBMPlexMono-Regular.ttf text file in the /hdd/verification/ folder
## edit all commands as necessary
alias yt-dl='yt-frames'
# must pass youtube video slug
function yt-frames() {
cd /hdd/verification/
rm -f temp_frames.mp4
youtube-dl -o 'temp.mp4' -f 298/134 --hls-prefer-ffmpeg $1
FRAMERATE=$(ffprobe -show_streams temp.mp4 2>&1 | grep fps | awk '{split($0,a,"fps")}END{print a[1]}' | awk '{print $NF}')
ffmpeg -i temp.mp4 -vf "drawtext=fontfile=IBMPlexMono-Regular.ttf: text=(${FRAMERATE}) %{n}: start_number=1: x=10: y=10: fontcolor=black: fontsize=16: box=1: boxcolor=white: boxborderw=5" -preset ultrafast -c:a copy temp_frames.mp4
rm temp.mp4
mpv temp_frames.mp4 &
}
alias t-dl='twitch-frames'
# must pass twitch video url
function twitch-frames() {
cd /hdd/verification/
rm -f temp_frames.mp4
streamlink $1 720p60,360p,best -o temp.mp4
FRAMERATE=$(ffprobe -show_streams temp.mp4 2>&1 | grep fps | awk '{split($0,a,"fps")}END{print a[1]}' | awk '{print $NF}')
ffmpeg -i temp.mp4 -vf "drawtext=fontfile=IBMPlexMono-Regular.ttf: text=(${FRAMERATE}) %{n}: start_number=1: x=10: y=10: fontcolor=black: fontsize=16: box=1: boxcolor=white: boxborderw=5" -preset ultrafast -c:a copy temp_frames.mp4
rm temp.mp4
mpv temp_frames.mp4 &
}
alias fsec='frame-seconds'
# must pass start frame, end frame, frame rate
function frame-seconds() {
TOTALSEC=$(echo "scale=3; ($2-$1)/$3" | bc)
MS=${TOTALSEC:(-3)}
SECONLY=${TOTALSEC:0:-4}
if [[ SECONLY -gt 59 ]]
then
SEC=$(echo "$SECONLY%60" | bc)
MINONLY=$(echo "$SECONLY/60" | bc)
if [[ MINONLY -gt 59 ]]
then
MIN=$(echo "$MINONLY%60" | bc)
HR=$(echo "$MINONLY/60" | bc)
printf "%s hr %s min %s sec %s ms" $HR $MIN $SEC $MS
else
printf "%s min %s sec %s ms" $MINONLY $SEC $MS
fi
else
printf "%s sec %s ms" $SECONLY $MS
fi
}
@slashinfty
Copy link
Author

slashinfty commented Jul 18, 2020

For Windows:

Download:
youtube-dl
streamlink
ffmpeg

Put youtube-dl.exe and ffmpeg.exe in home folder.

Open PowerShell.

If YouTube:

./youtube-dl -o 'temp.mp4' -f 298/134 VIDEOSLUG

If Twitch:

streamlink VIDEOURL 720p60 --hls-prefer-ffmpeg -o temp.mp4

(change 720p60 to 360p if no 720p60 source)
((change 360p to best if no 360p source))

Apply frame count:

./ffmpeg -i temp.mp4 -vf "drawtext=text=%{n}: start_number=1: x=10: y=10: fontcolor=black: fontsize=24: box=1: boxcolor=white: boxborderw=5" -preset ultrafast -c:a copy tempframes.mp4

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