Hallo,
zunächst einmal folgendes Script (für alle *.flac-Dateien sollen gruppiert nach Album die Dynamik-Werte ausgegeben werden):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #!/bin/bash dirs=0; flacdirs=0; while read -r -d '' dir; do ((dirs++)) files=0; while read -r -d '' file; do # echo "$dir"; ((flacdirs++)); ((files++)); echo $file; vol_detect=`ffmpeg -hide_banner -i "${file}" -af volumedetect -f null /dev/null 2>&1 >/dev/null \ | grep "Parsed_volumedetect_0"`; # echo $vol_detect; mean_=${vol_detect#*mean_volume: }; mean_=${mean_%% *}; max_=${vol_detect#*max_volume: }; max_=${max_%% *}; echo mean_volume: $mean_ dB max_volume: $max_ dB; done < <(find "$dir" -maxdepth 1 -iname "*.flac" -print0 | sort -z); if [[ $files > 0 ]]; then echo files: $files; echo; fi; done < <(find Ablage -mindepth 1 -type d -print0 | sort -z) echo Number of dirs total: $dirs; echo Number of dirs with flac files: $flacdirs; |
Auf eine solche Dateistruktur angewandt erhalte ich:
Ablage/Al Di Meola & John McLaughlin & Paco De Lucía - Friday Night In San Francisco (1981)/01. Mediterranean Sundance Rio Ancho.flac mean_volume: -21.1 dB max_volume: -0.0 dB Al Di Meola & John McLaughlin & Paco De Lucía - Friday Night In San Francisco (1981)/02. Short Tales Of The Black Forest.flac mean_volume: dB max_volume: dB Ablage/Al Di Meola & John McLaughlin & Paco De Lucía - Friday Night In San Francisco (1981)/03. Frevo Rasgado.flac mean_volume: -27.4 dB max_volume: -1.1 dB e/Al Di Meola & John McLaughlin & Paco De Lucía - Friday Night In San Francisco (1981)/04. Fantasia Suite.flac mean_volume: dB max_volume: dB Ablage/Al Di Meola & John McLaughlin & Paco De Lucía - Friday Night In San Francisco (1981)/05. Guardian Angel.flac mean_volume: -22.5 dB max_volume: -3.1 dB files: 5
Es fällt auf, dass nur für jede 2. Datei ein Ergebnis ausgegeben wird. Woran könnte das liegen?
Auch jeder 2. Dateipfad wird am Anfang merkwürdig abgeschnitten.
Das auskommentierte echo $vol_detect; liefert:
[Parsed_volumedetect_0 @ 0x62fac5a6b080] n_samples: 0 [Parsed_volumedetect_0 @ 0x62fac5a63500] n_samples: 122609732 [Parsed_volumedetect_0 @ 0x62fac5a63500] mean_volume: -21.1 dB [Parsed_volumedetect_0 @ 0x62fac5a63500] max_volume: -0.0 dB [Parsed_volumedetect_0 @ 0x62fac5a63500] histogram_0db: 82 [Parsed_volumedetect_0 @ 0x62fac5a63500] histogram_1db: 1059 [Parsed_volumedetect_0 @ 0x62fac5a63500] histogram_2db: 5229 [Parsed_volumedetect_0 @ 0x62fac5a63500] histogram_3db: 15947 [Parsed_volumedetect_0 @ 0x62fac5a63500] histogram_4db: 36406 [Parsed_volumedetect_0 @ 0x62fac5a63500] histogram_5db: 69766
... allerdings auch nur für jede 2. Datei. Also da schon "liegt der Hase im Pfeffer".
Außerdem würde mich interessieren, ob und wie man die beiden Zeilen 15,16 bzw. 17,18 jeweils in einen Ausdruck verwandeln kann.
Da müsste doch mit folgendem Regex was zu machen sein:
.*mean_volume: (\S*?) db.*
Ich weiß aber leider nicht, wie man aus einem Ergebnis mittels grep nur den Inhalt zwischen den Klammern auslesen kann.
Wenn diese Probleme gelöst sind, geht es dann weiter mit Berechnungen aus diesen Werten mittels bc.
Moderiert von shiro:
Dieser Thread ist von "Bash-Skript: Rechnen mit bc" umbenannt worden in "Bash-Skript: jeder 2. Dateipfad wird am Anfang merkwürdig abgeschnitten".