Reputation: 351
Is it possible, using ffmpeg or ffprobe, to detect if an image is blank? Only containing a single color, e.g. White.
I have done some digging and have come up with nothing at all, I don't even know if this is possible. I intend to execute via a batch file.
Thanks for any pointers.
Upvotes: 0
Views: 1001
Reputation: 26406
An implementation in Python based on John Doe's solution.
This counts the number of blank frames in the first 10 seconds of a video.
import json
import shlex
import subprocess
def identify_initial_blank_frames(video_absolute_path):
# analyse first 10 seconds only
ffprobe_command = f'''ffprobe -read_intervals %+10 -f lavfi -i "movie={video_absolute_path},signalstats" -show_frames -print_format json'''
ffprobe_command_single_line = shlex.split(ffprobe_command)
find_blank_frames_result = subprocess.run(ffprobe_command_single_line, stdout=subprocess.PIPE)
find_blank_frames_result_json = find_blank_frames_result.stdout.decode('utf-8')
data = json.loads(find_blank_frames_result_json)
count = 0
for index, frame in enumerate(data['frames']):
# all these color values are the same if the frame is blank
UMIN = frame['tags']['lavfi.signalstats.UMIN']
ULOW = frame['tags']['lavfi.signalstats.ULOW']
UAVG = frame['tags']['lavfi.signalstats.UAVG']
UHIGH = frame['tags']['lavfi.signalstats.UHIGH']
UMAX = frame['tags']['lavfi.signalstats.UMAX']
VMIN = frame['tags']['lavfi.signalstats.VMIN']
VLOW = frame['tags']['lavfi.signalstats.VLOW']
VAVG = frame['tags']['lavfi.signalstats.VAVG']
VHIGH = frame['tags']['lavfi.signalstats.VHIGH']
VMAX = frame['tags']['lavfi.signalstats.VMAX']
if UMIN == ULOW == UAVG == UHIGH == UMAX == VMIN == VLOW == VAVG == VHIGH == VMAX:
print(index)
count += 1
else:
# we have come to the end of the initial contiguous sequence of frames
break
print(f'found {count} contiguous blank frames at start of video')
Upvotes: 0
Reputation: 351
for /f "tokens=* USEBACKQ" %%f in (`ffprobe -f lavfi -i "movie=test.png,signalstats" -show_frames`) do (
set /a line=!line!+1
if !line! EQU 33 set ave=%%f
)
if "!ave:~27,3!"=="235" echo WHITE
Upvotes: 1