I'm desperately searching for a convenient method to check the integrity of .mp4 files inside a specific directory with folders in it. Both the names of the .mp4 files and the folders contain spaces, special characters and numbers.
I've already found a proper ffmpeg command to quickly identify a damaged .mp4 file, taken from here:
ffmpeg -v error -i filename.mp4 -map 0:1 -f null - 2>error.log
If the created error.log contains some entries, then the file is obviously corrupted. The opposite would be an empty error.log.
The next step would be to apply this command to every .mp4 file within the folder and its subfolders. Some guides, like here and here, do describe how to apply a ffmpeg command recursively, but my coding skills are limited, so therefore I can't 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, that should create .log files, only if a video file does contain errors (read has some content) and it should inherit the name of the broken file, to know which file is corrupted.
Using Ubuntu Gnome 15.10.
Try this command:
find . -name "*.mp4" -exec ffmpeg -v error -i "{}" -map 0:1 -f null - 2>error.log \;
The find
command finds all files in the current directory recursively which correspond to the given pattern: "*.mp4"
. After -exec
comes the command you want to run for all files. "{}"
substitutes the name of the current file, where the quotes allow spaces in file names. The command has to end with \;
.
EDIT:
The code above generates only one log file, which makes it impossible to know which file was broken. To instead create separate .log
files for each of the .mp4
files, you can use the {}
symbol one more time:
find . -name "*.mp4" -exec sh -c "ffmpeg -v error -i '{}' -map 0:1 -f null - 2>'{}.log'" \;
I recently met with the same problem, but I think there's a simple hack 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" \;
This way the errors follow the filename (and path).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With