0

UPDATE

Thank you everyone for sharing up your suggestions. I was able to make the work properly by modifying it as follows.

#!/bin/bash

ROOTPATH="/Volumes/NVME-RAID/ASSET-Processing/CORRUPT-SCAN/SCAN " # manually define root  path to your folder that has subfolders
for subdir in *; do
  cd ${ROOTPATH}${subdir} 
  mkdir 00errors
  
  for path in *.{MOV,mov,MP4,mp4}; do

    ffmpeg -i "${path}" -f null -; echo$?
    RC=$?

    if [ "${RC}" -ne "0" ]; then
        # Do something to handle the error.
        mv ${path} ./00errors
    fi

  done
  cd ../
done

The only issue i have now is that it does not appear to be traversing the subfolders. As I understand it it should create a "00errors" folder in within EACH sub folder and move the errors files within that sub folder.

trying to sift through 14TB of recovered video...

I'm trying to figure out how to properly convert this script so it will run on a bash/MacOS. I'm coming to a wall with the "ROOTPATH" call because MacOS doesn't use /mnt

#!/bin/bash

ROOTPATH="/mnt/f/00test/" # manually define root  path to your folder that has subfolders
for subdir in *; do
  cd ${ROOTPATH}${subdir} 
  mkdir 00errors
  
  for path in *.mp4; do

    ffmpeg error -i "${path}"
    RC=$?

    if [ "${RC}" -ne "0" ]; then
        # Do something to handle the error.
        mv ${path} ./00errors
    fi

  done
  cd ../
done

REF Quickly check the integrity of video files inside a directory with ffmpeg

  • 3
    Replace ROOTPATH with the location of your videos. Are they on an external drive? If so, it will be `/Volumes/EXTERNALDRIVENAME`. – Mark Setchell Feb 28 '21 at 11:23
  • 1
    You can add a test if the `ROOTPATH` variable is empty, either use Parameter Expansion to use an alternative value or ask interactively via the builtin `read`. Also try https://shellcheck.net just my two cents – Jetchisel Feb 28 '21 at 11:27
  • 1
    Your ffmpeg command is invalid and will give you an error: `Unable to find a suitable output format for 'error'. error: Invalid argument`. You forgot the `-v`, as in `-v error`. See [How can I tell if a video file is corrupted? FFmpeg?](https://stackoverflow.com/a/58825153/) for some valid commands. – llogan Feb 28 '21 at 18:23

1 Answers1

0

If your test dir was in your home directory /Users/username aka ~:

ROOTPATH="~/00test" # manually define ROOTPATH to your folder that has subfolders
for subdir in *; do
  cd ${ROOTPATH}/${subdir} 

I follow the convention to not use trailing slashes in paths; here I have moved the slash to the cd command.

Richard Barber
  • 5,257
  • 2
  • 15
  • 26