Kes
Kes

Reputation: 333

Create directory list where each line in list consists of mp3 file name and mp3 duration

I wish to produce a list from the directory of the mp3 file names in the directory and the playing duration of each file.

The below command produces a list of mp3 files in the directory

for name in *.mp3; do ffmpeg -i "$name" 2>&1 |  grep -o -P "(?<=Input #0, mp3, from ').*(?=.mp3':)"  ; done; 

The below command produces a list of the duration of each of the MP3 files

for name in *.mp3; do ffmpeg -i "$name" 2>&1 | grep -o -P '(?<=Duration: 00:).*(?=.[0-9]{2}, start)'  ; done;

I need to combine the output of both these commands into one output showing

Upvotes: 1

Views: 89

Answers (1)

Hastur
Hastur

Reputation: 2818

Time 0 idea. Something like this...(taking your code).

for name in *.mp3; 
do 
  a=$(ffmpeg -i "$name" 2>&1|grep -o -P "(?<=Input #0, mp3, from').*)(?=.mp3':)"
  b=$(ffmpeg -i "$name" 2>&1|grep -o -P '(?<=Duration: 00:).*(?=.[0-9]{2}, start)')
  echo "$b $a"
done; 

Feel you free to use printf instead of echo and a formatted output.

Upvotes: 3

Related Questions