import sys import zlib import gst def main(path): pipeline = gst.parse_launch(''' filesrc location="%s" ! decodebin ! audio/x-raw-int ! appsink name=sink sync=False''' % path) sink = pipeline.get_by_name('sink') pipeline.set_state(gst.STATE_PLAYING) crc = 0 while True: try: buf = sink.emit('pull-buffer') except SystemError, e: # it's probably a bug that emits triggers a SystemError print 'SystemError', e break # should be coming from a CD assert len(buf) % 4 == 0, "buffer is not a multiple of 4 bytes" crc = zlib.crc32(buf, crc) crc = crc % 2 ** 32 print "CRC: %08X" % crc path = 'test.flac' try: path = sys.argv[1] except IndexError: pass main(path)