#!/usr/bin/env python
#-*- coding: utf-8 -*-
__author__ = "suxoza <suxoza@gmail.com>"
import sys,json,time

def print_info(vs):
    return json.dumps(
              dict(
                 codec = vs.codec_name,
                 duration = date(vs.duration),
                 mode = vs.frame_mode
                 )
               )
def date(unixtime):
    format = '%H:%M:%S' if unixtime >= 3600 else '%M:%S'
    return time.strftime(format,time.localtime(unixtime))

try:
  argv_video = sys.argv[1]
  argv_image = sys.argv[2]
  second = int(sys.argv[3]) if len(sys.argv) >=4 else int(5)
  from ffvideo import VideoStream
  pil_image = VideoStream(argv_video)
  aa = pil_image.get_frame_at_sec(second).image()
  aa.save(argv_image)
  print(print_info(pil_image))
except Exception as e:
  print e.message
  #sys.exit()
