Skip to content

Instantly share code, notes, and snippets.

@itspluxstahre
itspluxstahre / synchrosubs.sh
Created November 28, 2011 23:37 — forked from anonymous/synchrosubs.sh
Subtitle Synchronizations scripts (for .srt)
#!/bin/bash
#Yannis Dassiras' 2009
if [ $# -lt 3 ];then
alf=`basename $0`;
echo -e "\nUsage:\n\n$alf [filename] [delay] [multiplier]\n\nFor delay only, set multiplier to 1.\n\n";exit 0;
fi
cat "$1"|sed 's/ --> /:/'|gawk -v delay=$2 -v multi=$3 'BEGIN {FS=":"} NF<4 {print $0} NF>4 {gsub(",",".");stime=$1*3600+$2*60+$3;etime=$4*3600+$5*60+$6;nstime=stime*multi+delay;netime=etime*multi+delay;sh=int(nstime/3600);eh=int(netime/3600);sm=int((nstime-sh*3600)/60);em=int((netime-sh*3600)/60);ss=int(1000*(nstime-sh*3600-sm*60))/1000;es=int(1000*(netime-eh*3600-em*60))/1000;if (sh<10) sh="0"sh;if (sm<10) sm="0"sm;if (ss<10) ss="0"ss;if (eh<10) eh="0"eh;if (em<10) em="0"em;if (es<10) es="0"es;if (length(es)<6) es=es"0";if (length(ss)<6) ss=ss"0";$0=sh":"sm":"ss" --> "eh":"em":"es;gsub("\\.",",");print}';exit 0;