A
A
Alexander Rybakov2019-09-30 22:46:56
linux
Alexander Rybakov, 2019-09-30 22:46:56

How to display the duration of an audio/video file?

Good afternoon. There is a task - to write a script that goes through all the files in the directory and displays the duration of the name, size and duration, if it is an audio or video file.
Everything except duration

local file1=$1;

  for file in $file1/*
  do
  if [ -f "$file" ]
  then
  for (( i=1; i <= $count; i++ ))
  do
  printf "║ "
  done
  local filesize=$(stat -c%s "$file")
  filesize=$(echo "scale=4; $filesize / 1024 / 1024" | bc)
  local dateModify=$(date +"%d.%m.%Y в %H:%M" --reference="$file")
  local time=$(ffmpeg -t -i $file)
  
  printf "╠═ ${file##*/}, ${filesize} MB, изменено ${dateModify}, \t${time}\n"
  
  fi
  done

The time variable should store the length of the media file. I'm using the ffmpeg library and obviously doing something wrong with the options.
Thank you in advance:)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-09-30
@turkish777

ffprobe is more convenient for this. In one project, I define the duration in a bash script into a variable like this:

local MUSIC_LENGTH=$(ffprobe \
    -v quiet  \
    -print_format ini  \
    -show_format  \
    "$MUSIC_PCM" | grep duration | sed s/duration=//)

$MUSIC_PCM– path to the media file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question