Last active
April 29, 2021 10:01
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
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:
Run it: