hello everyone!
I have been using Kdenlive for sometime now and i absolutely love it! especially the auto subtitle feature. unfortunately the subtitles themselves lack a bit of customization, unlike title clips. so i needed a way to turn subtitles into titles, like “the upgrade captions to graphics” feature in premiere.
I know upgrades to the subtitle editor are in the works but in the meantime i hope someone finds this helpful.
It’s a simple bash script to convert SRT files into kdenlive Title files, you just need a title clip template (.kdenlivetitle) and the SRT file itself in the same directory as the script.
the title clip template must meet 2 criteria in order to work:
- duration is 30 frames
- text is %s
the output is a folder called “Kden_Titles” :
- drag and drop it to kdenlive bin.
- drag and drop the clips to an empty video track.
make sure the bin is sorted by name so that the clips are in the correct order.
some clip files will have “_” in the name, those are blanks used for padding so that the real clips are correctly positioned in the timeline. if you wish to remove them you can sort by date and all blanks will be at the bottom.
#!/bin/bash
read -p "frame rate:"$'\n' frate
[ "$frate" = "" ] && frate=60
echo "..."
[ -d ./Kden_Titles/ ] && rm -r ./Kden_Titles
mkdir -p Kden_Titles
readarray -t frm < <( (sed -n '2~4p' ./*.srt) )
readarray -t sub < <( (sed -n '3~4p' ./*.srt) )
n=1
w=$(bc<<<"length(${#sub[@]}*2)")
for i in "${!frm[@]}"; do
b=$(date -d "${frm[i]:0:12}" "+%S.%3N")
e=$(date -d "${frm[i]:17:12}" "+%S.%3N")
ee=$(date -d "${frm[i-1]:17:12}" "+%S.%3N")
if [ "$i" -eq 0 ]; then ee=0; fi
if [ "$(bc<<<"$b<$ee && $i!=0")" -eq 1 ]; then b="$(bc<<<"$b+60")"; fi
if [ "$(bc<<<"$e<$b")" -eq 1 ]; then e="$(bc<<<"$e+60")"; fi
blank="$(bc <<< "($b*$frate+0.5)/1-($ee*$frate+0.5)/1")"
duration="$(bc <<< "($e*$frate+0.5)/1-($b*$frate+0.5)/1")"
if [ "$blank" -gt 0 ]; then
sed -e "s/30/$blank/" -e "s/%s//" ./*.kdenlivetitle* > ./Kden_Titles/"$(printf "%0*d" "$w" "$n")"_.kdenlivetitle
((n++))
fi
sed -e "s/30/$duration/" -e "s/%s/${sub[i]}/" ./*.kdenlivetitle* > ./Kden_Titles/"$(printf "%0*d" "$w" "$n")".kdenlivetitle
((n++))
done
sleep 1
echo "Titles in $PWD/Kden_Titles"$'\n'
touch ./Kden_Titles/*_*
$SHELL