Bad video files

My roommate has a ton of videos that are not complete but still show a thumbnail for the file making it next to impossible to sort the good files from the bad. Since I know the bad files typically will error out when attempting to play any of them I was wonder if there is a way to scan the files in a directory and be informed which are incomplete or damaged. Thanks

1 Like

Test if ffprobe is able to detect the broken video files.

ffprobe -v error -i /path/to/video.mp4

If a bad video file returns an error and a good one returns nothing, you could use that to write a script to go through the files and write a log of all the broken videos.

This hasn’t been tested or anything, just an example from a chat bot you can use as a starting point:

#!/bin/bash

# Directory containing the video files
VIDEO_DIR="/path/to/videos"

# Log file to store the results
LOG_FILE="busted_videos.log"

# Clear previous log file before you begin.
> "$LOG_FILE"

# Check each video file in the directory
find "$VIDEO_DIR" -type f -exec sh -c '
  for file; do
    # Use ffprobe to check for errors in the file
    if ! ffprobe -v error -i "$file" -f null - 2>/dev/null; then
      echo "Incomplete or damaged file: $file" >> "$LOG_FILE"
    fi
  done
' sh {} +

# Print results
if [ -s "$LOG_FILE" ]; then
  echo "Incomplete or damaged files found:"
  cat "$LOG_FILE"
else
  echo "No incomplete or damaged files found."
fi
3 Likes

I know nothing about writing scrips so I’m making ab assumption here. Save as Whatever.sh then execute that from konsole?

That’s right. Also make the script executable.

chmod +x whatever.sh

Also this variable needs to be defined with the actual path to the videos:

# Directory containing the video files
VIDEO_DIR="/path/to/videos"

Before you run it, I would just test to make sure it is actually going to work first.

When you are ready, you can run the script from Konsole like you mentioned.

./whatever.sh
1 Like

Yea I plan to create a temp folder on his desktop and copy 50 files into it. Not so many as not to be able to quickly manually check the results in the created log file, then if I’m satisfied I’ll run the script on the actual folder.

Never thought that I’d actually be grateful that he dumps ALL his moves into one main folder instead of a Movies folder and a Movie Series folder with subfolders in it.

The real “fun” is going to be going through what’s left and naming them correctly.

Thanks for the info and help with this cause both of us have been dreading finally doing this.

I’m assuming this is correct for a good file?

   ~/Desktop  ffprobe -v error -i "/home/cccp/Desktop/Maniac Cop 3: Badge Of Silence (1992).mkv"
   ~/Desktop                                                              ✔  06:15:39 AM 
1 Like

Yes, that looks good. My understanding is the -v error option only has output if there are errors in the file.

Be sure to test a known bad file as well, to confirm you get error output.

1 Like

OK just ran the test on his system with the single file command and seems to have worked perfectly. I just ran the script on his movies folder and get, which I find odd cause I know Brazil was bad when I used it for a test. Granted I had deleted the copy from his main files yesterday and hadn’t deleted the copy from his master backup. I can’t believe that was the only bad video file with a thumbnail besides the ones with no icons that we attempted to play some of yesterday and got errors as expected and went ahead and deleted those. The log itself is empty as expected from the terminal message.

sh: line 5: : No such file or directory
No incomplete or damaged files found.
 #!/bin/bash

# Directory containing the video files
VIDEO_DIR="/mnt/My Files/Movies/Movies/"

# Log file to store the results
LOG_FILE="busted_videos.log"

# Clear previous log file before you begin.
> "$LOG_FILE"

# Check each video file in the directory
find "$VIDEO_DIR" -type f -exec sh -c '
  for file; do
    # Use ffprobe to check for errors in the file
    if ! ffprobe -v error -i "$file" -f null - 2>/dev/null; then
      echo "Incomplete or damaged file: $file" >> "$LOG_FILE"
    fi
  done
' sh {} +

# Print results
if [ -s "$LOG_FILE" ]; then
  echo "Incomplete or damaged files found:"
  cat "$LOG_FILE"
else
  echo "No incomplete or damaged files found."
fi

Could be one of two things:

  1. The situation is not as dire as you thought, and the bad files have already been removed;
  2. The script is not working correctly. This is very possible because it is an untested script a bot wrote for us in like five seconds.

To test the second possibility, find a known bad video file, add it to the video directory, and run the script again to confirm it is able to pick it up.

LOL DAMN I just ran his FreeFileSync on this files to mirror his main files with his master backup so even Brazil would be gone.

You could use truncate to make a bad video file (on purpose), then test if the script works.

Copy some video and use truncate against the copy:

cp some_video.mp4 bad_version.mp4
truncate -s 1M bad_version.mp4

Open the video to confirm it’s bad, then run the script again. :crossed_fingers:

That’s easier than what I was planing. I was going to find a decent sized movie file to download and stop the download partway through. Thanks

Looks like I found a cheat. I simply created a new empty file called test.mp4 and ran the one command on it. Should of thought of this sooner. Thanks for the help with this.

   ~/Desktop  ffprobe -v error -i "/home/cccp/Desktop/test.mp4"           ✔  02:14:02 PM 
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5d853cb03980] moov atom not found
/home/cccp/Desktop/test.mp4: Invalid data found when processing input

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.