AnswerBun.com

Batch rename of video files after finding its resolution height

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.

One Answer

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:

Answered by llogan on December 20, 2020

Add your own answers!

Related Questions

systemctl –state=failed

0  Asked on December 5, 2021 by tomasz-groch

 

Systemctl failure using –global setting

1  Asked on December 5, 2021 by mark-knittel

   

Ubuntu 20.04 – Failed to start GNOME Shell on X11

0  Asked on December 4, 2021 by facundo-flores

       

Google (maybe the browser?) not recognizing USB webcam

0  Asked on December 4, 2021 by tkbegemot

         

How to do a clean reinstall of ubuntu?

2  Asked on December 3, 2021 by mahiro

 

Cannot delete print job on Ubuntu 18.04

1  Asked on December 3, 2021 by manfred-steiner

 

Postfix is not logging anything to journal

1  Asked on December 3, 2021 by r4ptor

     

systemctl enable fprintd.service fails

1  Asked on December 3, 2021 by randy-broman

   

Recovering a lost user group

1  Asked on December 3, 2021

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP