0

I'm Making a script to get DAR information out of video file. to do that, I'm using this script with success

DAR=$(ffmpeg -i "$DOSSIER/$OLD_NAME.$EXTENSION" -hide_banner 2>&1 | grep -i -oP "DAR [0-9]+:[0-9]+")
# if DAR not exist set it to 1
if [ -z "$DAR" ];
    then 
        DAR="DAR 1:1"
fi
X_DAR=$(echo "${DAR:4}" | cut -d: -f1)
Y_DAR=$(echo "${DAR:4}" | cut -d: -f2)

My main problem is that sometimes, videos have multiple DAR so my output looks like

echo $DAR
DAR 16:9 DAR 5:4 DAR 234:211

from there, I would need the biggest number of all operations available behind the DAR. and there could be 2 DAR available or 10.

any ideas? thanks

Nexius2
  • 11
  • 4
  • 1
    Which number has to be the biggest? The one left from the ``:`` or right? – Kokogino Apr 27 '18 at 12:27
  • the biggest one could be any of the DAR. the ":" means divided (/). so 16:9=1,77777777 5:4=1,25 and 234:211=1,10900474 here, the biggest numbre is 16:9 – Nexius2 Apr 27 '18 at 18:16

1 Answers1

0

If you want to sort it by the number left to : then do this:

for((n=1;n<$(echo $DAR | wc -w)+1;n+=2)); do echo $DAR | cut -d' ' -f$n,$(($n + 1)); done | sort -k2 --numeric-sort -r | head -n1

Or if you want to sort it by the number right to : then do this:

for((n=1;n<$(echo $DAR | wc -w)+1;n+=2)); do echo $DAR | cut -d' ' -f$n,$(($n + 1)); done | sort -t: -k2 --numeric-sort -r | head -n1

Output:

DAR 234:211

EDIT:

Now this first divides the two numbers and then sorts them by the result.

for((n=1;n<$(echo $DAR | sed "s/ /\n/g" | wc -l)+1;n+=2)); do echo $DAR | cut -d' ' -f$n,$(($n + 1)); done | awk -F'[ :]' '{printf "%s %s:%s;%s\n",$1,$2,$3,$2/$3}' | sort -t';' -k2 --numeric-sort | tail -n1 | cut -d';' -f1
Kokogino
  • 984
  • 1
  • 5
  • 17
  • don't you think that leaving `$DAR` unquoted is a mistake? `echo "$DAR" | sort -t" " -k2n| tail -n1` should be enough ;-)? – shellter Apr 27 '18 at 15:11
  • the idea is not bad, I could make the division then numeric-sort. I'll see what I can find about that – Nexius2 Apr 27 '18 at 18:19
  • @Nexius2 I extended the answer by a possible way to do the division before sorting. – Kokogino Apr 30 '18 at 06:39