I am using the timestamps that FFmpeg outputs to get information about the video integrity. So far I have tested this on about 50 videos and only had one "Unusual time skip" false positive.
Is this method of checking a valid way to do this, could there be legitimate reasons why the time skip would significantly increase and is there a more accurate way to determine an invalid time skip than $dif*2
?
ffmpegIntegrityCheck() {
local frame=0
local prevFrame=0
local duration=0
local timestamp=0
local seconds=0
local prevSeconds=0
local dif=0
local line=""
ffmpeg -v debug -progress - -nostats -i "$1" -f null - 2>&1 \
| while read -r line; do
# Get the video duration
if [[ "$duration" = 0 && "$line" =~ "Duration: " ]]; then
duration=${line#* }
duration=${duration%, start*}
duration=${duration%.*}
echo "Duration $duration"
# Check if the frame number stops increasing
elif [[ "$line" =~ "frame=" ]]; then
frame=${line#*=}
if [ "$frame" = "$prevFrame" ]; then
echo "No frame change at $timestamp frame $frame"
fi
prevFrame="$frame"
# Check the increase in seconds between each timestamp,
elif [[ "$line" =~ "out_time=" ]]; then
timestamp=${line#*=}
timestamp=${timestamp%.*}
seconds=$(echo "$timestamp" \
| awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
if [ "$dif" != 0 ] && (( $seconds-$prevSeconds > $dif*2 )); then
echo "Unusual time skip at $timestamp"
else
dif=$(($seconds-$prevSeconds))
fi
prevSeconds="$seconds"
# Check if the last timestamp matches the duration
elif [[ "$line" = "progress=end" ]]; then
if [ "$duration" != "$timestamp" ]; then
duration=$(echo "$duration" \
| awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
if (( $seconds < $duration-1 || $seconds > $duration+1 )); then
echo "End time mismatch at $timestamp"
fi
fi
fi
done
}
The reason I am trying to check with more than just ffmpeg -v error
is because I have found corrupted files where ffmpeg has reported no errors. I have also found files where FFmpeg reports errors but when I watch the video there are no problems so I would like to try and check whether there are any playback problems without watching it.
The logic behind looking at the timestamp jumps was that if the file all of a sudden starts processing significantly faster, I assume it is having errors and skipping some processing. This assumption does seem to match my results with files where ffmpeg -v error
is reporting errors but it does produce some false positives
The log from a file producing errors in FFmpeg:
Duration 01:36:32
No frame change at 00:48:29 frame 69673
Unusual time skip at 00:49:42
No frame change at 00:49:42 frame 69673
Unusual time skip at 00:50:58
No frame change at 00:50:58 frame 69673
Unusual time skip at 00:51:44
No frame change at 00:51:44 frame 69673
Unusual time skip at 00:53:09
No frame change at 00:53:09 frame 69673
Unusual time skip at 00:54:04
No frame change at 00:54:04 frame 69673
Unusual time skip at 00:55:25
No frame change at 00:55:25 frame 69673
Unusual time skip at 00:56:32
No frame change at 00:56:32 frame 69673
Unusual time skip at 00:57:30
No frame change at 00:57:30 frame 69673
Unusual time skip at 00:58:08
No frame change at 00:58:08 frame 69673
Unusual time skip at 00:59:37
No frame change at 00:59:37 frame 69673
No frame change at 01:00:02 frame 69673
Unusual time skip at 01:01:19
No frame change at 01:01:19 frame 69673
Unusual time skip at 01:02:33
No frame change at 01:02:33 frame 69673
Unusual time skip at 01:03:39
No frame change at 01:03:39 frame 69673
No frame change at 01:03:39 frame 69673
No frame change at 01:06:02 frame 69673
No frame change at 01:06:25 frame 69673
Unusual time skip at 01:08:18
No frame change at 01:08:18 frame 69673
Unusual time skip at 01:09:19
No frame change at 01:09:19 frame 69673
Unusual time skip at 01:10:19
No frame change at 01:10:19 frame 69673
Unusual time skip at 01:11:26
No frame change at 01:11:26 frame 69673
Unusual time skip at 01:12:39
No frame change at 01:12:39 frame 69673
Unusual time skip at 01:13:53
No frame change at 01:13:53 frame 69673
Unusual time skip at 01:14:55
No frame change at 01:14:55 frame 69673
No frame change at 01:14:59 frame 69673
Unusual time skip at 01:17:04
No frame change at 01:17:04 frame 69673
No frame change at 01:17:04 frame 69673
No frame change at 01:19:01 frame 69673
No frame change at 01:19:25 frame 69673
Unusual time skip at 01:21:07
No frame change at 01:21:07 frame 69673
No frame change at 01:21:40 frame 69673
Unusual time skip at 01:23:34
No frame change at 01:23:34 frame 69673
No frame change at 01:24:18 frame 69673
No frame change at 01:25:34 frame 69673
No frame change at 01:26:41 frame 69673
No frame change at 01:27:48 frame 69673
No frame change at 01:28:06 frame 69673
Unusual time skip at 01:29:01
No frame change at 01:29:01 frame 69673
Unusual time skip at 01:30:38
No frame change at 01:30:38 frame 69673
No frame change at 01:30:38 frame 69673
No frame change at 01:33:15 frame 69673
No frame change at 01:33:51 frame 69673
Unusual time skip at 01:35:24
No frame change at 01:35:24 frame 69673
End time mismatch at 01:36:16