Skip to content

Instantly share code, notes, and snippets.

@soukron
Last active April 29, 2021 10:01
Show Gist options
  • Save soukron/fbdb4bb77f5597cde82ac4092da2df35 to your computer and use it in GitHub Desktop.
Save soukron/fbdb4bb77f5597cde82ac4092da2df35 to your computer and use it in GitHub Desktop.
Bash script to convert the DJI Googles SRT file to a CSV which can be used in spreadsheets.
#!/bin/bash
outputFile=${1/.srt/.csv}
# initialize statistics
totalLines=$( cat ${1} |wc -l | sed 's/ //g;' )
# loop over the whole file
echo "timestamp;latency;bitrate;voltage;avg. voltage" > "${outputFile}"
currentLine=0
while read line; do
((currentLine++))
echo -ne "Processing ${1}... (${currentLine}/${totalLines} lines)\r"
if [[ "${line}" =~ ^0.:.* ]]; then
timestamp=${line:0:12}
fi
if [[ "${line}" =~ ^signal:.* ]]; then
echo ${line} |\
sed 's/ /:/g;s/ms//g;s/Mbps//g;s/V//g' |\
awk -F: -v timestamp="${timestamp}" '{ print timestamp";"$16";"$18";"$8";"$8/$12 }' |\
sed 's/,/\./g' \
>> ${outputFile}
fi
done < ${1}
echo -e "\n${outputFile} generated.\n"
# statistics summary
awk -F\; '
BEGIN{
maxLatency=0
lowerLatency=999
maxBitrate=0
lowerBitrate=999
}
(NR>1){
sumLatency += $2
if ($2 <= lowerLatency) lowerLatency=$2
if ($2 >= maxLatency) maxLatency=$2
sumBitrate += $3
if ($3 <= lowerBitrate) lowerBitrate=$3
if ($3 >= maxBitrate) maxBitrate=$3
}
END {
print "Statistics:"
print " Input data:"
print " - Total meassures: " NR - 1
print " - Flight time: " $1
print "\n Latency:"
print " - Lower Latency: " lowerLatency "ms"
print " - Max Latency: " maxLatency "ms"
print " - Average Latency: " sumLatency/NR "Mbps"
print "\n Bitrate:"
print " - Lower Bitrate: " lowerBitrate "Mbps"
print " - Max Bitrate: " maxBitrate "Mbps"
print " - Average Bitrate: " sumBitrate/NR "Mbps"
}' ${outputFile}
@soukron
Copy link
Author

soukron commented Apr 29, 2021

Description
It produces a CSV file including the timestamp, latency, bitrate, total voltage and average voltage per cell in the UAV.

Has been tested in the next environment:

  • macOS BigSur
  • the SRT files created by the DJI Googles V1 with v01.00.06.00 firmware

Newer versions might generate different SRT files which may include other fields and make this parser fail. Contact me if that happens to you so I can help and fix the parser.

How to use it
Download it:

$ wget -q https://bit.ly/str2csv_sh -O str2csv.sh 
$ chmod +x str2csv.sh

Run it:

$ ./srt2csv.sh DJIG0000.srt
Processing DJIG0000.srt... (7080/7080 lines)
DJIG0000.csv generated.

Statistics:
  Input data:
  - Total meassures: 1771
  - Flight time: 00:04:41.950

  Latency:
  - Lower Latency: 20ms
  - Max Latency: 50ms
  - Average Latency: 25,6358Mbps

  Bitrate:
  - Lower Bitrate: 1.3Mbps
  - Max Bitrate: 9.3Mbps
  - Average Bitrate: 42,9684Mbps

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