Way to detect frozen video with ffmpeg?

Is there a way to detect frozen video with ffmpeg? I only need to know if there are rather large regions of frozen video, say 10 seconds or more.

I'm familar with the blackdetect filter.

Maybe you could first difference adjacent frames, then use blackdetect to tell whether the difference has not changed? I'm not sure how to perform the difference though.


Solution 1:

Use the freezedetect filter. It is newer than the 4.1 release branch so use a build from the current git master branch. See FFmpeg Download page for links to builds for Linux, macOS, and Windows.

Example

ffmpeg -i freeze.mp4 -vf "freezedetect=n=-60dB:d=2" -map 0:v:0 -f null -

Options

  • noise (or n): Set noise tolerance. Can be specified in dB (in case "dB" is appended to the specified value) or as a difference ratio between 0 and 1. Default is -60dB, or 0.001.

  • duration (or d): Set freeze duration until notification (default is 2 seconds).

Example output

Refer to the lavfi.freezedetect metadata keys in the console output.

ffmpeg version N-93663-ga42e761b96 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.0 (GCC)
  configuration: 
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 52.100 / 58. 52.100
  libavformat    58. 27.103 / 58. 27.103
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 49.100 /  7. 49.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'freeze.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:28.99, start: 0.000000, bitrate: 1324 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 115:87 DAR 1840:783], 1322 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.27.103
    Stream #0:0(und): Video: wrapped_avframe, yuv420p, 1280x720 [SAR 115:87 DAR 1840:783], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.52.100 wrapped_avframe
[freezedetect @ 0x55f7a55c9800] lavfi.freezedetect.freeze_start: 10.01
[freezedetect @ 0x55f7a55c9800] lavfi.freezedetect.freeze_duration: 13.1381x    
[freezedetect @ 0x55f7a55c9800] lavfi.freezedetect.freeze_end: 23.1481
frame=  695 fps=0.0 q=-0.0 Lsize=N/A time=00:00:28.98 bitrate=N/A speed=  40x    
video:364kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Outputting the results to a file

You can combine the metadata filter to just get the freeze info:

ffmpeg -i freeze.mp4 -vf "freezedetect=n=-60dB:d=2,metadata=mode=print:file=freeze.txt" -map 0:v:0 -f null -

Which results in freeze.txt:

frame:288  pts:288288  pts_time:12.012
lavfi.freezedetect.freeze_start=10.01
frame:555  pts:555555  pts_time:23.1481
lavfi.freezedetect.freeze_duration=13.1381
lavfi.freezedetect.freeze_end=23.1481

See the metadata filter documentation for more options.