This is an old revision of the document!
Table of Contents
FFmpeg-based Interval Timer for Sport and Exercise
I am the one of the cycling captain of UEA Triathlon Club for the academic year of 2017-2018. I always find it hard to keep track of the set in a turbo session for some reason.
I used to use a Matlab-based countdown timer 1). However it always freezes after 558 seconds had elapsed - if you set a 10-minute countdown timer, it will freeze at 42 seconds. I can't be bothered to fix the Matlab code.
After digging through FFmpeg documentation 2) and the Internet, I figured out how to generate a text-based video.
Here I present the program listing, and an example output. The script works fine on Debian Stretch.
I have to say FFmpeg is one of my most abused software. Last time I used FFmpeg to upload arbitrary file to Youtube 3).
Program listing
#!/bin/bash # The file number counter let counter=0 function cleanup { rm seg-*.mp4 filelist.txt } # Calling convention: duration, font size, text function introduction { ffmpeg -f lavfi -i color=c=white:size=1280x720:rate=30 \ -vf "drawtext=text='${3}': fontsize=${2}: \ r=30: x=(w-tw)/2: y=h-h*0.9: fontcolor=black:" \ -t ${1} -preset slow -tune stillimage -y \ seg-${counter}.mp4 echo "file seg-${counter}.mp4" >> filelist.txt let counter++ } # Calling convention: duration, text function segment { let min=$1/60 let sec=$1-${min}*60 ffmpeg -f lavfi -i color=c=white:size=1280x720:rate=30 \ -vf "drawtext=text='${2}': fontsize=80: \ r=30: x=(w-tw)/2: y=h-h*0.75: fontcolor=black:,\ drawtext=text='Duration: ${min} min ${sec} sec': fontsize=80: \ r=30: x=(w-tw)/2: y=h-h*0.5: fontcolor=black:, drawtext=timecode='00\:00\:00\:00': fontsize=80: \ r=30: x=(w-tw)/2: y=h-h*0.25: fontcolor=black:" \ -t ${1} -preset slow -tune stillimage -y \ seg-${counter}.mp4 echo "file seg-${counter}.mp4" >> filelist.txt let counter++ } function output { ffmpeg -f concat -i filelist.txt -c copy -y ${1} cleanup } cleanup ############################################################################ # -- Insert your session introduction here -- # # Make sure the font is big enough! You might want to test out the # # introduction generation first by commenting out the main set # # Calling convention: # # introduction $DURATION $FONTSIZE $TEXT # ############################################################################ introduction 10 40 " Threshold session: W/U - 5 minutes easy, gradually build up 10 mins at 10 mile TT effort 15 seconds sprint 10 mins easy 10 mins at 10 mile TT effort 20 seconds sprint 10 mins easy 10 mins 10 mile TT effort 25 seconds sprint Warm down for 5 mins, easy spinning " ############################################################################ # -- Insert your main set here. -- # # You might want to test out the introduction generation before generating # # these video. # # Calling convention: # # segment $DURATION $TEXT # ############################################################################ segment 300 "Easy, gradually build up" segment 600 "10 mile TT effort" segment 15 "Sprint" segment 600 "Easy" segment 600 "10 mile TT effort" segment 20 "Sprint" segment 600 "Easy" segment 600 "10 mile TT effort" segment 25 "Sprint" segment 300 "Cool down" output UEA-Triathlon-2018-02-07.mp4