#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2012-2013 Hector Martin "marcan" # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 or version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import sys, numpy, ffms, math N = 32 # image size M = 8 # number of DCT coefficients k = math.sqrt(2.0 / N) dct_k = numpy.matrix([ [k * math.cos((math.pi / 2 / N) * y * (2 * x + 1)) for x in xrange(N)] for y in xrange(1,M) ]) dct_k_t = numpy.transpose(dct_k) source_file = sys.argv[1] out_file = open(sys.argv[1] + ".txt","w") print "Loading", source_file vsource = ffms.VideoSource(source_file) vsource.set_output_format([ffms.get_pix_fmt("gray")], width=N, height=N) print "Hashing", source_file for frameno in xrange(vsource.properties.NumFrames): data = vsource.get_frame(frameno).planes[0].reshape((N,N)).astype(float) coefs = numpy.array(dct_k * data * dct_k_t).flatten() median = numpy.median(coefs) h = sum((1< median) out_file.write("#%d: %016x\n" % (frameno, h)) out_file.close()