Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

video

ffmpeg

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.

like image 324
DMT Avatar asked Dec 03 '15 22:12

DMT


2 Answers

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'" \;
like image 140
Andrea Dusza Avatar answered Oct 15 '22 00:10

Andrea Dusza


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).

like image 24
memoz Avatar answered Oct 14 '22 22:10

memoz