def play(file_path):
    """play a video file"""
    iv = pipeffmpeg.InputVideoStream()
    iv.open(file_path)

    # Getting the frame rate of the video
    # Got this from the source code of pipeffmpeg (Can be replaced by Popen)
    file_info = pipeffmpeg.get_info(file_path)

    try:
        f_rate = file_info["streams"][0]["r_frame_rate"]
        # Getting the number of seconds for a frame
        delay = 1.0 / int(f_rate.split("/")[0])
    except (__HOLE__, IndexError):
        # Setting a default delay if frame rate not obtained
        delay = 0.02

    stdscr = curses.initscr()
    max_h, max_w =  stdscr.getmaxyx()

    start_time = time.time()
    for i, bmp in enumerate(iv.readframe()):
        # timestap when frame start
        frame_start_time = time.time()
        # resize each frame to proper size, and covert to gray
        image = Image.open(StringIO.StringIO(bmp))\
                    .resize((max_w, max_h), Image.ANTIALIAS)\
                    .convert('L')

        stdscr.clear()
        data = ''.join(gray_scale[pix] for pix in image.getdata())
        for h in range(max_h-1):
            stdscr.addstr(h, 0, data[h*max_w:(h+1)*max_w])

        time_eclipsed = time.time() - start_time
        minutes, seconds = time_eclipsed/60, time_eclipsed % 60
        stdscr.addstr(max_h-1, 0, 'Resolution:[%d*%d] Frame:%d Time:[%d:%d]' % (max_w, max_h, i, minutes, seconds))
        stdscr.refresh()

        # Adding a delay if needed
        real_delay = delay - (time.time() - frame_start_time)
        if real_delay > 0:
            time.sleep(real_delay)

    curses.endwin()
dataset/ETHPy150Open ee0703/console_video/player.py/play