Ñò
tKc           @   sĊ   d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 d d k
 l Z d Z e i   Z d Z d   Z d   Z d	   Z d
 d  Z d S(   s>   
This module implements video thumbnail creation using ffmpeg
i˙˙˙˙N(   t
   check_callid   ià   i°   c         C   s`   d } t  |  } x> t |  D]0 } | | t |  |  } | | | | 7} q Wt i |  S(   Ng        (   t   lent   ranget   floatt   matht   sqrt(   t   histt   mediant   rest   nt   jt   err(    (    s@   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/vthumb.pyt
   frame_rmse/   s     c         C   s
   |  i    S(   N(   t	   histogram(   t   im(    (    s@   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/vthumb.pyt   img_hist7   s    c         C   sQ   | o6 t  i |   } | i t t  i  | i | d  n t i |  |  d  S(   Nt   JPEG(   t   Imaget   opent	   thumbnailt
   THUMB_SIZEt	   ANTIALIASt   savet   shutilt   copyfile(   t   srct   dstt   thumbR   (    (    s@   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/vthumb.pyt
   copy_thumb:   s
    t   ffmpegc         C   s6  | o  d |  d }  d |  GHd GHn d t  t i    d } d | | |  | f } | p | d } n t i |  d j o
 d	 GHd
 S| o	 d GHn g  }	 x	t d | d  D]ô }
 | |
 } t i i |  p Pn | o d |
 GHn t i |  i	 d  } | p | i
 d  j o d |
 GHd S|	 i t |   |
 | j oZ | d t  |
  d } | o' | i t t i  | i | d  qŞt i | |  qĥ qĥ W| o	 d GHn t |	  } g  } xd t t |	 d   D]L } d } x0 t |  D]" }
 | t |	 |
 |  | } q W| i |  qçWd } d } x\ t d | d  D]G }
 t |	 |
 d |  } | d j p | | j  o |
 } | } qWqWW| o d | GHn d } y t | | | d |  Wn d GHd } n X| o	 d GHn x2 t d | d  D] }
 | |
 } t i |  qW| S(   Ns   "s   Processing %ss   Extracting framest   frames   .%d.jpgs   %s -y -vframes %d -i %s %ss    -v -1i    s   Error invoking ffmpegi
   s   Analyzing framesi   s   	Processin frame %dt   RGBs   Error reading frame %di   t   .s   .thmR   s   Calculating averagesg        i˙˙˙˙s   BEST Frame: %ds   Error copying thumb fileid   s   Removing temp files(   t   strt   timet   ost   systemR   t   patht   existsR   R   t   convertt   modet   Nonet   appendR   R   R   R   R   R   R   R   R   R   R   t   unlink(   t   infilet   outfilet   nframest   alsosavet   verboseR   t   FFMPEGt	   framemaskt   cmdR   t   it   fnameR   t
   thumbfnameR	   t   avgt   ct   act   minnt   minRMSEt   rmset   rc(    (    s@   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/vthumb.pyt
   find_thumbB   s    			 
		    
	 
(   ià   i°   (   t   __doc__R   t   sysR#   R"   R   R   t   stringt   tempfilet   getoptt
   subprocessR    t   NFRAMESt
   gettempdirt   TMPDIRR   R   R   R   R>   (    (    (    s@   /home/ken/Programs/video4fuze/0.6+/src/video4fuze-0.6+/vthumb.pyt   <module>#   s   T			