Проблемы со сценарием bash

while IFS='' read -r LINE || [ -n "${LINE}" ]; do
        me= $( ffmpeg -i ${LINE} 2>&1 | grep Duration | sed 's/Duration: \(.*\), start/\1/g' > uber.txt )
    echo "${me}"
done < me.txt

Я хочу создать сценарий для проверки продолжительности всех файлов .mp4 (которые находятся в me.txt). Он действительно работает, но я не знаю, почему он не показывает продолжительность, он просто печатает пустые строки

2
задан 5 December 2020 в 05:19

1 ответ

0 - Я сделал что-то очень близкое к тому, что вы хотите.
См.: https://askubuntu.com/a/1163082/77093

1 - Избавьтесь от пробелов в именах файлов

IFS=$'\n'
while read -r LINE || [ -n "${LINE}" ]; do
  # ...
done < me.txt

2 - лучше используйте программу mediainfo , так как она выводит продолжительность видеофайла в миллисекундах.

sudo apt install mediainfo

Затем

IFS=$'\n'
while read -r Line || [ -n "${Line}" ]; do
  # Test if file is video
  buff=$(file -N -i "${Line}" | grep -E 'video')
  if [ ! -z  "$buff" ]
    then
      MediaDuration=$(mediainfo --Output='General;%Duration%' "${Line}")
      # Want total duration of listed files?
      TotalDuration=$((TotalDuration + MediaDuration))
      # Want total number of video files?
      NbMedia=$((NbMedia + 1))
  fi
done < me.txt

# Format Duration: milliseconds to H:M:S
Seconds=$((TotalDuration / 1000))
FormattedDuration=$(printf '%02dh:%02dm:%02ds\n' $(($Seconds/3600)) $(($Seconds%3600/60)) $(($Seconds%60)))

# Build report
ReportText="${NbFiles} File"
test $NbFiles -gt 1 && ReportText="${ReportText}s"
ReportText="${ReportText} selected\n"
test $NbMedia -gt 0 && ReportText="${ReportText}${NbMedia} Media file" || ReportText="${ReportText}No media file"
test $NbMedia -gt 1 && ReportText="${ReportText}s"
test $NbMedia -gt 0 && ReportText="${ReportText}\nTotal duration: ${FormattedDuration}"
1
ответ дан 5 December 2020 в 03:15

Другие вопросы по тегам:

Похожие вопросы: