I already showed you in another answer how to iterate all files and append results. This is how you would go about calculating stuff in bash
for one file, using @LordNeckbeard's ffprobe
command.
Your homework is to modify and integrate the two answers.
#!/bin/bash
file=/path/to/file.mp4
if [ ! -f $file ]; then
echo Error: File not found
exit 1
fi
pkt_sizes=$(ffprobe -show_entries frame=pkt_size -of default=noprint_wrappers=1:nokey=1 -i $file -loglevel 0)
function print_sum {
#use `bc` for floating point operations
sum=$(echo "scale=${precision};${sum}/100" | bc -l)
echo "SUM("$start","$i")="$sum
}
i=1
start=1
sum=0
precision=3
#compute/print sum every 50 packets
for size in $pkt_sizes; do
(( sum+= size ))
if (( $i % 50 == 0 )); then
print_sum
sum=0
start=$(( i + 1 ))
fi
(( i++ ))
done;
#sum last packets (n < 50)
if (( "$start" < "$i" )); then
(( i-- ))
print_sum
fi
This is more than enough to get you started with shell arithmetic so please refer to the documentation for further questions.