Generate bindings
=================

The following information are only here for Avpy developers. 
See Readme.txt if you only intend to use the python lib. 

Requirements
------------

python
git
h2xml
xml2py
gcc & co
python yaml lib

for ubuntu users, please run the following command:

sudo apt-get install git python-ctypeslib build-essential python-yaml yasm

Build libav from git
--------------------

cd tools
mkdir build
git clone git://github.com/libav/libav.git build/libav_git
python build.py -l libav -v 0.8.1

note: 
    * use option -r to specify build folder
    * use option -j to compile faster

Build ffmpeg from git
---------------------

cd tools
mkdir build
git clone https://github.com/FFmpeg/FFmpeg build/ffmpeg_git
python build.py -l ffmpeg -v 1.2.1

Generate bindings
-----------------

python gen.py -l libav -v 0.8.1
python fix.py -s av008.py -d av008_fix.py -c config/libav08.yml
python genClean.py -s av008_fix.py -d av8.py -c config/libav08.yml  
cp -v av8.py ../avpy/version/

note: See Generate binding config for detailed information.

Building
--------

python setup.py sdist

Testing
-------

python -c 'from avpy import formats; print formats()'

or

AVPY_AVCODEC=PATH_TO/libavcodec.so PYTHONPATH=./:$PYTHONPATH python examples/mediaInfo/mediaInfo.py -m test.avi

Please note that LD_LIBRARY_PATH (Linux or DYLD_FALLBACK_LIBRARY_PATH - Mac OS X) is not supported for python < 3.4.

The following env variables can also be used
- AVPY_AVUTIL
- AVPY_AVCODEC
- AVPY_AVFORMAT
- AVPY_AVDEVICE
- AVPY_SWSCALE

Testing in a virtualenvs
------------------------

- source ~/dev/virtualenvs/avpy/bin/activate
- pip uninstall Avpy
- python setup.py sdist
- pip install dist/Avpy-*.tar.gz
- python -c 'from avpy import formats; print formats()'

Generate binding config
=======================

genClean script use a yaml config file in order to generate 'clean' binding. It parses the script generated by gen.py (xml2py) and extracts only information found in config.

genClean require the following key:
- type # list of C type to extract 
- class # list of C structure to extract
- alias # class alias
- import # list of python import, examples: from ctypes import c_float 
- cdll # see below
- function # list of C functions to extract

Sample config
-------------

type:
    - int8_t
    - AVPictureType

alias:
    - ByteIOContext
    - AVMetadata

class:
    - AVPacket

import:
    - from ctypes import CDLL, RTLD_GLOBAL
    - from ctypes import Structure, POINTER, CFUNCTYPE
    - from ctypes import c_int, c_uint, c_char, c_void_p, c_char_p, c_ubyte
    - from ctypes import c_short
    - from ctypes import c_ulong
    - from ctypes import c_int8, c_uint8
    - from ctypes import c_int16, c_uint16
    - from ctypes import c_int32, c_uint32
    - from ctypes import c_int64, c_uint64
    - from ctypes import c_float    
    - from ctypes import c_double

cdll:
    - CDLL('libavutil.so', RTLD_GLOBAL)
    - _libraries = {}
    - _libraries['libavcodec.so'] = CDLL('libavcodec.so', mode=RTLD_GLOBAL)
    - _libraries['libavdevice.so'] = CDLL('libavdevice.so', mode=RTLD_GLOBAL)
    - _libraries['libavformat.so'] = CDLL('libavformat.so', mode=RTLD_GLOBAL)
    - _libraries['libswscale.so'] = CDLL('libswscale.so', mode=RTLD_GLOBAL)

function:
    - av_register_all
    - av_open_input_file






















