Ask Ubuntu Asked by user209405 on December 20, 2020
Trying my first script, not going smoothly. Maybe someone knows of a program or can help point in the right direction. I want to sequentially find a large archive of video files resolutions – height only (I know 2 ways to accomplish this, using ffprobe and mediainfo); if 720 or 1080 append as a suffix, previous to the extension. If the file is not 720 or 1080 separate into 2 directories (650+ & 649-). I know how to find the resolution, create directories, move and rename files. I am having trouble specifically with the multiple files in sequential order, if/and/or use and how to pipe for the renaming with either ffprobe or mediainfo. Thanks.
This simplistic example should get you started:
#!/bin/bash
if [ ! -d "650+" ] && [ ! -d "649-" ]; then
mkdir "650+" "649-"
fi
for f in *.mp4
do
height=$(ffprobe -v error -show_entries stream=height -of csv=p=0 "$f")
if [ "$height" -eq 1080 ] || [ "$height" -eq 720 ]; then
mv "$f" "${f%.*}_$height.${f##*.}"
fi
if [ "$height" -lt 650 ]; then
mv "$f" "649-"
else
mv "$f" "650+"
fi
done
As you can see the logic isn't perfect because it only moves videos with a height less than 720 px into the appropriate directories, but it shows the basics. (Ran out of time to make it better due to a pending meeting.) Also, it's not recursive. Wasn't sure if that was a requirement.
Also see:
ffprobe
Answered by llogan on December 20, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP