ó
V¾÷Xc           @` s"  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 d d	 l	 m Z d d
 l	 m Z d d l m Z d d l m Z d d d d „ Z e j d ƒ d d d „ Z e j d ƒ d d „ Z e j d k re d d d g ƒ n  d S(   s)   Encoding and decoding audio using FFmpeg.i    (   t   absolute_import(   t   division(   t   print_functionN(   t   gen_decode_audio_op_py(   t   gen_encode_audio_op_py(   t   errors(   t   load_library(   t   ops(   t   resource_loader(   t
   tf_loggingc         C` s   t  j |  d | d | d | ƒS(   st  Create an op that decodes the contents of an audio file.

  Note that ffmpeg is free to select the "best" audio track from an mp4.
  https://trac.ffmpeg.org/wiki/Map

  Args:
    contents: The binary contents of the audio file to decode. This is a
        scalar.
    file_format: A string specifying which format the contents will conform
        to. This can be mp3, mp4, ogg, or wav.
    samples_per_second: The number of samples per second that is assumed.
        In some cases, resampling will occur to generate the correct sample
        rate.
    channel_count: The number of channels that should be created from the
        audio contents. If the contents have more than this number, then
        some channels will be merged or dropped. If contents has fewer than
        this, then additional channels will be created from the existing ones.

  Returns:
    A rank 2 tensor that has time along dimension 0 and channels along
    dimension 1. Dimension 0 will be `samples_per_second * length` wide, and
    dimension 1 will be `channel_count` wide. If ffmpeg fails to decode the
    audio then an empty tensor will be returned.
  t   file_formatt   samples_per_secondt   channel_count(   R   t   decode_audio(   t   contentsR
   R   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/ffmpeg/ffmpeg_ops.pyR       s    t   DecodeAudioc         C` s   t  j |  d | d | ƒS(   s  Creates an op that encodes an audio file using sampled audio from a tensor.

  Args:
    audio: A rank 2 tensor that has time along dimension 0 and channels along
        dimension 1. Dimension 0 is `samples_per_second * length` long in
        seconds.
    file_format: The type of file to encode. "wav" is the only supported format.
    samples_per_second: The number of samples in the audio tensor per second of
        audio.

  Returns:
    A scalar tensor that contains the encoded audio in the specified file
    format.
  R
   R   (   R   t   encode_audio(   t   audioR
   R   (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/ffmpeg/ffmpeg_ops.pyR   B   s    t   EncodeAudioc         C` s¤   yy t  j |  ƒ } t j | ƒ } xT | p- g  D]F } x= | j j D] } | j | k rA PqA qA Wt d | |  f ƒ ‚ q. WWn$ t j	 k
 rŸ t
 j d |  ƒ n Xd S(   s7  Loads a .so file containing the specified operators.

  Args:
    name: The name of the .so file to load.
    op_list: A list of names of operators that the library should have. If None
        then the .so file's contents will not be verified.

  Raises:
    NameError if one of the required ops is missing.
  s0   Could not find operator %s in dynamic library %ss   %s file could not be loaded.N(   R   t   get_path_to_datafileR   t   load_op_libraryt   OP_LISTt   opt   namet	   NameErrorR   t   NotFoundErrort   loggingt   warning(   R   t   op_listt   filenamet   libraryt   expected_opt   lib_op(    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/ffmpeg/ffmpeg_ops.pyt   _load_libraryX   s    t   nts	   ffmpeg.so(   t   __doc__t
   __future__R    R   R   t   ost   tensorflow.contrib.ffmpeg.opsR   R   t   tensorflow.python.frameworkR   R   R   t   tensorflow.python.platformR   R	   R   t   NoneR   t   NotDifferentiableR   R!   R   (    (    (    sf   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/contrib/ffmpeg/ffmpeg_ops.pyt   <module>   s&   