1
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

I want to make a script to check all .mp4 files (that are in me.txt) for duration. It actually works but i dont know why it doesnt show duration, it just prints empty lines

1 Answers1

1

0 - I've done something pretty close to what you want.
See : https://askubuntu.com/a/1163082/77093

1 - Get rid of spaces in filenames

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

2 - you'd better use the mediainfo program as it outputs the video file duration in miliseconds.

sudo apt install mediainfo

Then

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}"

cmak.fr
  • 8,976