Quickly check the integrity of video files inside a directory using ffmpeg

I am desperately looking for a convenient method for checking the integrity of .mp4 files inside a specific directory with folders in it. The names of the .mp4 files and folders contain spaces, special characters, and numbers.

I already found the correct ffmpeg command to quickly identify the damaged .mp4 file taken from here : ffmpeg -v error -i filename.mp4 -map 0:1 -f null - 2>error.log

If the generated error.log file contains some entries, the file is clearly corrupt. The opposite is the empty error.log.

The next step is to apply this command for each .mp4 file in the folder and its subfolders. Some manuals, such as here and here , describe how to use the ffmpeg command recursively, but my coding skills are limited, so I cannot find a way to combine these commands to get the following:

A way to test all .mp4 files inside a folder (recursively) with the aforementioned ffmpeg command, which should create .log files only if the video file contains errors (reading has some content) and it must inherit the file name to find out which file is damaged.

Using Ubuntu Gnome 15.10.

+4
source share
3 answers

Try the following command:

 find . -name "*.mp4" -exec ffmpeg -v error -i "{}" -map 0:1 -f null - 2>error.log \; 

The find finds all files in the current directory recursively that match the given pattern: "*.mp4" . After -exec , the command appears that you want to run for all files. "{}" replaces the name of the current file, where quotation marks allow spaces in file names. The command must end with \; .

EDIT:

The above code generates only one log file. To create separate .log files for .mp4 files, each with their name, you can use the {} symbol again:

 find . -name "*.mp4" -exec sh -c "ffmpeg -v error -i {} -map 0:1 -f null - 2>{}.log" \; 
+4
source

I recently ran into the same problem, but I think there is a simple hack there to find out which files are broken:

 find -name "*.mp4" -exec sh -c "echo '{}' >> errors.log; ffmpeg -v error -i '{}' -map 0:1 -f null - 2>> errors.log" \; 

Thus, errors correspond to the file name (and path).

+3
source

The problem with other answers using ffmpeg to convert to null is that they take a lot of time. A quick way would be to create thumbnails for all the videos, as well as how the thumbnail generation fails.

 find . -iname "*.mp4" | while read -r line; do line=`echo "$line" | sed -r 's/^\W+//g'`; echo 'HERE IT IS ==>' "$line"; if ffmpeg -i "$line" -t 2 -r 0.5 %d.jpg; then echo "DONE for" "$line"; else echo "FAILED for" "$line" >>error.log; fi; done; 

This method turned out to be much faster than other methods.

However, there is CAVEAT. This method may give incorrect results, because sometimes thumbnails can be generated even for damaged files. For instance. if the video file is damaged only at the end, this method will not be executed.

0
source

Source: https://habr.com/ru/post/1237367/


All Articles