Issue
I want to list all the filenames and durations for each video in a folder. Currently I can only target files individually:
ffmpeg -i intro_vid001.mp4 2>&1 | grep Duration
Could someone suggest how I can print this out in the terminal or to a text file for every video file within a folder ?
I have tried with a shell script but am very new to shell scripts.
if [ -z $1 ];then echo Give target directory; exit 0;fi
find "$1" -depth -name ‘*’ | while read file ; do
directory=$(dirname "$file")
oldfilename=$(basename "$file")
echo oldfilename
#ffmpeg -i $directory/$oldfilename” -ab 320k “$directory/$newfilename.mp3″ </dev/null
ffmpeg -i "$directory/$oldfilename" 2>&1 | grep Duration | echo
#rm “$directory/$oldfilename”
done
Solution
- I forgot a dollar in front of one 'oldfilename'
- grep writes on its stdout, you must NOT pipe with echo that do not use its stdin.
I suggest the following script:
find "$1" -type f | while read videoPath ; do
videoFile=$(basename "$videoPath")
duration=$(ffmpeg -i "$videoPath" 2>&1 | grep Duration)
echo "$videoFile: $duration"
done
Answered By - mcoolive Answer Checked By - Dawn Plyler (WPSolving Volunteer)