Ñò
•µSJc           @   sÈ  d  d k  Z  d  d k l Z d Z d d „ Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e d j oí d  d k Z d  d k Z e e i ƒ d j  o! d e i d GHe i d ƒ n x› e i d D]ˆ Z e i e ƒ Z e d j o] d e e d e d f GHe e e ƒ x< e e d ƒ D] Z  e e e d e  e  ƒ qŽWq4d e GHq4Wn d S(    iÿÿÿÿN(   t	   randrangei    i   c         C   s=   d  } t |  d ƒ } | o | i | ƒ } | i ƒ  n | S(   Nt   rb(   t   Nonet   opent   readt   close(   t   filenamet   sizet   ht   f(    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt   read_headers   s    c         C   s   t  |  d ƒ } | o | Sd  S(   NR   (   R   R   (   R   R	   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt	   open_atom   s    c         C   s   |  i  ƒ  d  S(   N(   R   (   R	   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt
   close_atom   s    c         C   s“   |  i  d ƒ } t | ƒ d j  o d  Sh  } t i d | d d !ƒ } | d d j  o d  S| d d | d <| d d !| d <|  i ƒ  | d <| S(   Ni   s   >Li    i   R   t   typet   offset(   R   t   lenR   t   structt   unpackt   tell(   R	   R   t   atomt   s(    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt	   read_atom   s    c         C   s=   d | d GH|  i  | d ƒ | d <|  i | d d ƒ d S(   Ns   PICT size:%d R   t   datai   (   R   t   seek(   R	   R   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt
   parse_PICT-   s    c         C   s  |  i  ƒ  } d } xî | | d j  oÜ t |  ƒ } | d  j o Pn | | d d 7} | d d j o t |  | | ƒ q | d d j o t |  | | ƒ q | d d j o t |  | | ƒ q | d d j o t |  | | ƒ q |  i | d d	 ƒ q W|  i | d ƒ d  S(
   Ni    R   i   R   t   stsdt   stszt   stcot   stsci   (   R   R   R   t
   parse_stsdt
   parse_stszt
   parse_stcot
   parse_stscR   (   R	   t   nodet   infot   begint   currentR   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt
   parse_stbl3   s$     c         C   sí   |  i  | d ƒ } t i d | d d !ƒ \ } } } } } d }	 x¥ | o t i d | |	 |	 d !ƒ \ }
 } } | i d ƒ o
 d GHd  S| | d <t i d	 | |	 d
 |	 d !ƒ \ } } | | d <| | d <|	 |
 7}	 | d 8} qD Wd  S(   NR   s   >B3BLi    i   s   >LL6xHi   t   formats^   Warning i found severall different format, is it correct. Please send your video to the authors   >HHi    i$   t   widtht   heighti   (   R   R   R   t   has_key(   R	   R   R"   R   t   versiont   flags0t   flags1t   flags2t   entriest   iR   R&   t   refindexR'   R(   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyR   G   s    ( &
'


c   
      C   sã   |  i  | d ƒ } t i d | d d !ƒ \ } } t d j o d | GHn d } xŠ | o‚ t i d | | | d !ƒ \ } } }	 t d j o d	 | | |	 f GHn | d 8} | d
 i | | f ƒ | d 7} | d 8} qU Wd  S(   NR   s   >B3xLi    i   s   stsc entries: %ds   >LLLi   i   s+   firstchunk=%d sampleperchunk=%d sampleid=%dt
   chunk_info(   R   R   R   t   quicktime_verboset   append(
   R	   R   R"   R   R*   R.   R/   t
   firstchunkt   sampleperchunkt   sampleid(    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyR    X   s     &

c         C   s{   |  i  | d ƒ } t i d | d d !ƒ \ } } } t d j o d | GHn | | d <t i d | | d ƒ | d <d  S(	   NR   s   >B3xLLi    i   s   stsz frames: %dt   framess   >%dLt   sample_size(   R   R   R   R2   (   R	   R   R"   R   R*   t   defsizeR.   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyR   h   s    "
c         C   sx   |  i  | d ƒ } t i d | d d !ƒ \ } } t d j o d | GHn | | d <t i d | | d ƒ | d <d  S(	   NR   s   >B3xLi    i   s   stco entries: %dt   chunkss   >%dLt   chunk_offset(   R   R   R   R2   (   R	   R   R"   R   R*   R.   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyR   p   s    
c         C   s0  |  i  ƒ  } d } x| | d j  oõ t |  ƒ } | d  j o Pn t d j o d | d GHn | d d j o | | d <n | d d  j o: | d | j o) | d d j o t |  | | ƒ qÌ n | d d j o t |  | | ƒ n | | d d 7} |  i | d d ƒ q W|  i | d ƒ d  S(   Ni    R   s   + %sR   t   vmhdt   video_chunkt   stblt   mdiat   mvhdt   trakt   minft   mdhdt   hdlri   i   (   R?   R@   RA   RB   RC   RD   R>   (   R   R   R   R2   R%   t
   parse_moovR   (   R	   t   parentR"   R#   R$   R   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyRE   ~   s&     "c         C   sÆ   |  i  ƒ  } d } x | | d j  o‹ t |  ƒ } | d  j o Pn d | | d | d f GH| d d j o t |  | | d ƒ n | | d d 7} |  i | d d ƒ q W|  i | d ƒ d  S(   Ni    R   s   %s "%s" (size=%d)R   R?   R@   RA   RB   RC   RD   R>   t   +i   i   (   s   mdias   mvhds   traks   minfs   mdhds   hdlrs   stbl(   R   R   R   t
   parse_atomR   (   R	   RF   t   prefixR#   R$   R   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyRH   “   s     s   /tmp/photon%8.8d.jpgc      	   C   sN  t  |  ƒ } d } x5t | d ƒ D]#} t d j o d | | d | f GHn | i | d | d ƒ d } x1 | d D]% } | d | j o | d } qz qz Wx  t | ƒ D]’ } | d | }	 t | | d	 ƒ }
 | i d
 ƒ } | d d
 !d j o+ |
 i | ƒ |
 i | i |	 d
 ƒ ƒ n
 d | GH|
 i ƒ  | d 7} q° Wq# Wd  S(   Ni    R:   i   s   chunks: %d   => offset: %dR;   iÿÿÿÿR1   R8   t   wbi   s   ÿØs*   Warning this is not a jpeg file (frame=%d)(   R   t   rangeR2   R   R   R   t   writeR   (   t	   moviefileR"   t   basenameR	   t   framet   chunkt   samplesbychunkR1   t   jjjR   t   outR   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt   extract_jpeg_files¡   s0       	
c      	   C   sÎ  t  |  ƒ } d } d } d } d } x† | d D]z }	 | d j o |	 d } |	 d } q/ | |	 d | | } | | j o | | j  o Pn | } |	 d } |	 d } q/ Wt | | | ƒ \ }
 } |
 | 7}
 t d j o d | |
 | f GHn | d |
 } x. t | ƒ D]  } | | d | | d 7} qW| i | d ƒ | d | } t | d ƒ } | i d ƒ } | d d !d	 j o+ | i | ƒ | i | i | d ƒ ƒ n
 d
 | GH| i ƒ  t	 | ƒ d  S(   Ni    R1   i   s   %4.4d |  chunk=%d /// offimg=%dR;   R8   RJ   i   s   ÿØs+   Warning: this is not a jpeg file (frame=%d)(
   R   t   divmodR2   t   xrangeR   R   R   RL   R   R   (   RM   R"   t   outfileRO   R	   t   chunk_groupt   chunk_frame_startt   chunk_frame_endt   chunk_framesR1   RP   t   offimgR   t   jR   RS   R   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt   extract_jpeg_file¾   sD     


 	
c         C   s³  t  i d ƒ d j o
 d GHd  St |  d ƒ } | d  j o d  S| d d !d j o d  St |  ƒ } d
 } } h  } t ƒ  | d <xá t oÙ t | ƒ } | d  j o Pn | d d j o n | d d j o d } | i ƒ  | d <nd | d d j oE d } d  | d <t	 | | | ƒ t
 d
 j o t | | d ƒ qNn d | d GH| i | d d ƒ q† Wt | ƒ | o | p d  S| i d ƒ p d  S| d d j o | Sd  S(   Ns   >Li   sF   A long is not equal to 4 bytes with your python installation. Abordingi   i   t   pnott   moovt   mdatt   skipi    R1   R   t   PICTi   t   mdat_offsetR=   RG   s   Abording unknow Atom type %sR   R&   igepjiapjm(   R_   R`   Ra   s   skip(   R_   Rc   s   skip(   igepjiapjm(   R   t   calcsizeR   R
   R   t   listt   TrueR   R   RE   R2   RH   R   R   R)   (   R   R   R	   t
   found_mdatt
   found_moovR"   R   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt
   __identifyè   sL    
 

c         C   s
   t  |  ƒ S(   N(   Rj   (   R   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt   identify  s    c         C   sH   t  |  ƒ } | d  j o d  St d | d ƒ } t |  | | | ƒ t S(   Ni    R7   (   Rj   R   R    R^   Rg   (   RM   t   pictfilet   videot   r(    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt   extract_random_picture!  s    c         C   s5   t  |  ƒ } | d  j o d  St |  | | | ƒ t S(   N(   Rj   R   R^   Rg   (   RM   Rl   RO   Rm   (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt   extract_picture)  s
    t   __main__i   s   Usage: %s files...
i   s   %s (format='%x', frames='%d')R&   R7   s    %s is not a Quicktime movie file(!   R   t   randomR    R2   R
   R   R   R   R   R%   R   R    R   R   RE   RH   RT   R^   Rj   Rk   Ro   Rp   t   __name__t   syst	   QuickTimeR   t   argvt   exitR   R"   R   RV   RO   (    (    (    s[   /mnt/luc/web/www.saillard.org/www/programs_and_patches/photon/photon.hg/Photon/QuickTime.pyt   <module>   sH   													*	6				  
