Another potential advantage to using keyframes other than processing time is that they are a full image capture and don't include compression artifacts that could fool the AI.
INPUT_FILE=front-door-camera-3.mp4
OUTPUT_DIR=keyframes
# extract keyframes only
time ffmpeg -i $INPUT_FILE -vf "select=eq(pict_type\,I)" -vsync vfr $OUTPUT_DIR/kframe%04d.jpg -hide_banner
# extract a frame every 2 seconds
time ffmpeg -i $INPUT_FILE -vf fps=1/2 $OUTPUT_DIR/half_fps%04d.jpg -hide_banner
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'front-door-camera-3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
title : RTSP/RTP stream from anjvision ipcamera
encoder : Lavf58.20.100
Duration: 00:00:59.93, start: 0.000000, bitrate: 5041 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 2592x1944, 5000 kb/s, 15.02 fps, 15 tbr, 90k tbn, 180k tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 39 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'keyframes/kframe%04d.jpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
title : RTSP/RTP stream from anjvision ipcamera
encoder : Lavf58.20.100
Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 2592x1944, q=2-31, 200 kb/s, 15 fps, 15 tbn, 15 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.35.100 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
[h264 @ 0xa404a0] error while decoding MB 104 42, bytestream -5A speed=0.133x
[h264 @ 0xa404a0] concealing 12905 DC, 12905 AC, 12905 MV errors in P frame
frame= 30 fps=1.0 q=24.8 Lsize=N/A time=00:00:58.06 bitrate=N/A speed=2.02x
video:12512kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
real 0m29.299s
user 1m16.481s
sys 0m1.419s
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'front-door-camera-3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
title : RTSP/RTP stream from anjvision ipcamera
encoder : Lavf58.20.100
Duration: 00:00:59.93, start: 0.000000, bitrate: 5041 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc), 2592x1944, 5000 kb/s, 15.02 fps, 15 tbr, 90k tbn, 180k tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 39 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'keyframes/half_fps%04d.jpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
title : RTSP/RTP stream from anjvision ipcamera
encoder : Lavf58.20.100
Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 2592x1944, q=2-31, 200 kb/s, 0.50 fps, 0.50 tbn, 0.50 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.35.100 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
[h264 @ 0x14c4480] error while decoding MB 104 42, bytestream -5
[h264 @ 0x14c4480] concealing 12905 DC, 12905 AC, 12905 MV errors in P frame
frame= 30 fps=0.8 q=24.8 Lsize=N/A time=00:01:00.00 bitrate=N/A speed=1.64x
video:12942kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
real 0m37.326s
user 1m36.217s
sys 0m1.850s