Skip to content

Commit

Permalink
Fix installation steps
Browse files Browse the repository at this point in the history
  • Loading branch information
olokelo committed Jan 28, 2021
1 parent bc5c7e6 commit e6b1755
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 66 deletions.
87 changes: 60 additions & 27 deletions INSTALL.linux.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ Linux
Build Requirements
------------------

- cmake
- make
- ninja
- gcc
- g++
- nasm
- git
- sudo
- python (3.7+)
- python development (python3-dev or python3-devel)
- pip
- **libavif**:

- cmake
- make
- ninja
- gcc
- g++
- nasm
- git
- sudo

- **Python module**:

- python (3.7+)
- python development (python3-dev or python3-devel)
- pip
- patchelf
- unzip


Arch
Expand All @@ -28,7 +35,7 @@ Arch
.. code-block:: sh
sudo pacman -Sy
sudo pacman -S cmake make ninja gcc nasm git python3 python-pip
sudo pacman -S cmake make ninja gcc nasm git python3 python-pip patchelf unzip
Fedora
Expand All @@ -37,7 +44,7 @@ Fedora
.. code-block:: sh
sudo dnf update
sudo dnf install cmake make ninja-build gcc g++ nasm git python3-devel python3-pip
sudo dnf install cmake make ninja-build gcc g++ nasm git python3-devel python3-pip patchelf unzip
Ubuntu
Expand All @@ -46,17 +53,14 @@ Ubuntu
.. code-block:: sh
sudo apt-get update
sudo apt-get install cmake make ninja-build gcc g++ nasm git python3-dev python3-pip
sudo apt-get install cmake make ninja-build gcc g++ nasm git python3-dev python3-pip patchelf unzip
Build Steps
-----------

#. Install cffi module from pypi:

- ``sudo pip3 install --upgrade cffi``

This will allow to compile bindings
**Warning:**
The build steps are tested only on amd64 (x86_64) architecture.


#. Create a folder just to have everything in the same place:
Expand All @@ -79,8 +83,11 @@ Build Steps

Edit the ``libavif/ext/aom.cmd`` script:

- Add ``-DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=1`` after ``cmake -G Ninja -DCMAKE_BUILD_TYPE=Release`` and keep rest of the line as is
- Add the line that says ``sudo ninja install`` below the line with ``ninja``
- Add ``-DBUILD_SHARED_LIBS=1`` after ``cmake -G Ninja -DCMAKE_BUILD_TYPE=Release`` and keep rest of the line as is

Alternatively if you don't want to leave your terminal, you can type this to update the file from command line:

- ``sed -i 's/-DCMAKE_BUILD_TYPE=Release/& -DBUILD_SHARED_LIBS=1/' libavif/ext/aom.cmd``


#. Execute the script from the terminal:
Expand All @@ -89,27 +96,53 @@ Build Steps
- ``sh aom.cmd``
- ``cd ..``

After compilation step you will probably be prompted to type root password to install aom libraries to your system
After compilation step you will probably be prompted to type root password to install aom libraries to your system.


#. After all of this you can compile libavif with AOM support:

- Ensure that you are in the main libavif directory (``echo $PWD`` should give ``~/python-avif/libavif``)
- ``cd cmake``
- ``cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DAVIF_CODEC_AOM=ON``
- ``cmake .. -DAVIF_LOCAL_AOM=ON -DAVIF_CODEC_AOM=ON``
- ``make -j`nproc```
- ``sudo make install``

The ``-DCMAKE_INSTALL_PREFIX=/usr`` is optional, but without it you will almost certainly need to provide ``LD_LIBRARY_PATH=/usr/local/lib`` as an environment variable in order to use the library.
It will install libavif to ``/usr/local/``.

``-j`nproc``` means that the compiler will use all CPU threads to compile. If you want to change it and use for example 2 threads, you can provide `-j2` instead.


#. If build succeeded, you can finally install this module from python:
#. On the python side install ``auditwheel`` module:

- ``pip install --user auditwheel``

This is optional, but if the shell is telling you that it couldn't find ``pip`` or ``python``
(or if you have Python 2.x also installed), you should make some temporary aliases:

- ``alias pip=pip3``
- ``alias python=python3``


#. Build wheel for this package:

- ``cd ~/python-avif/avif``
- ``python setup.py build``
- ``sudo python setup.py install``
- ``pip wheel .``


#. Now you shoud see ``.whl`` file created by pip.

If it exists, you should run ``auditwheel`` on it to add ``libavif`` that you've compiled before to the wheel.

- ``export LD_LIBRARY_PATH=/usr/local/lib``
- ``python -m auditwheel repair --plat linux_x86_64 avif-*-linux_x86_64.whl``

On some distributions, you may need to set ``LD_LIBRARY_PATH`` to ``/usr/local/lib64`` instead


#. The ``auditwheel`` binary should create folder named ``wheelhouse`` and put your final wheel there.

- ``cd wheelhouse``
- ``pip install --user avif-*-linux_x86_64.whl``


#. And that should be it!
Expand Down
53 changes: 25 additions & 28 deletions INSTALL.win.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Windows
=======


Tested on Windows 8.1 and Windows 10 1809 (both amd64)
Tested on Windows 8.1, Windows 10 1809 and Windows 10 20H2 (all amd64)


Build Requirements
Expand Down Expand Up @@ -41,33 +41,30 @@ Your paths can be different but if you get ``INFO: Could not find files for the
Build Steps
-----------

1. Open the Native Tools Command Prompt for VS 2019

It will open command line window but from it you will be able to compile code.
**Warning:**
The build steps are tested only on amd64 (x86_64) architecture.


2. Install cffi module from pypi:
#. Open the Native Tools Command Prompt for VS 2019

- ``pip install --upgrade cffi``

This will allow to compile bindings
It will open command line window but from it you will be able to compile code.


3. Create a folder just to have everything in the same place:
#. Create a folder just to have everything in the same place:

- ``mkdir C:\python-avif``
- ``cd C:\python-avif``


4. Now you can clone the repositories:
#. Now you can clone the repositories:

- ``git clone https://github.com/Julian/avif.git``
- ``git clone https://github.com/AOMediaCodec/libavif.git``

The directory with python module will now appear as ``avif`` and the official avif implementation written in c will be called ``libavif``


5. You will also need to clone and compile the AOM repository.
#. You will also need to clone and compile the AOM repository.

It can be done using script included in ``libavif\ext`` directory:

Expand All @@ -76,51 +73,51 @@ Build Steps
- ``cd ..``


6. After that you can configure libavif with AOM support:
#. After that you can configure libavif with AOM support:

- Ensure that you are in the main libavif directory (``cd`` should give ``C:\python-avif\libavif``)
- ``cd cmake``
- ``cmake .. -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_AOM=ON``


7. Now open a new Native Tools Command Prompt for VS 2019 window as Administrator.
#. Now open a new Native Tools Command Prompt for VS 2019 window as Administrator.


8. Change current directory to cmake in this window too, then compile and install the project.
#. Change current directory to cmake in this window too, then compile and install the project.

- ``cd C:\python-avif\libavif\cmake``
- ``msbuild INSTALL.vcxproj /p:Configuration=Release``


9. After the installation is complete, ``C:\Program Files (x86)\libavif`` folder should be created and you will find there all necessary libavif resources. You can close the window that you opened as Administrator and continue in the first window.
#. After the installation is complete, ``C:\Program Files (x86)\libavif`` folder should be created and you will find there all necessary libavif resources. You can close the window that you opened as Administrator and continue in the first window.


10. Then you can change directory to this project and change ``INCLUDE`` variable.
#. Then you can change directory to this project and change ``INCLUDE`` variable.

- ``cd C:\python-avif\avif``
- ``set INCLUDE=%INCLUDE%;C:\Program Files (x86)\libavif\include``
- ``cd C:\python-avif\avif``
- ``set INCLUDE=%INCLUDE%;C:\Program Files (x86)\libavif\include``

You should also copy ``avif.lib`` file to project's directory:
You should also copy ``avif.lib`` file to project's directory:

- ``xcopy "C:\Program Files (x86)\libavif\lib\avif.lib" .``
- ``xcopy "C:\Program Files (x86)\libavif\lib\avif.lib" .``


11. Now you can run the ``setup.py`` script:
#. Now you can run the ``setup.py`` script:

- ``python setup.py build``
- ``python setup.py install``
- ``python setup.py build``
- ``python setup.py install``


12. In order to import the library you should copy ``avif.dll`` (that you can find in ``C:\Program Files (x86)\libavif\bin``) to the installed module directory. You can use ``pip show avif`` to know where the module is installed.
#. In order to import the library you should copy ``avif.dll`` (that you can find in ``C:\Program Files (x86)\libavif\bin``) to the installed module directory. You can use ``pip show avif`` to know where the module is installed.

In my case it says: ``... Location: c:\python39\lib\site-packages\avif-0.0.0-py3.9-win-amd64.egg ...``
In my case it says: ``... Location: c:\python39\lib\site-packages\avif-0.0.0-py3.9-win-amd64.egg ...``

Then you can copy the .dll:
Then you can copy the .dll:

- ``xcopy "C:\Program Files (x86)\libavif\bin\avif.dll" "c:\python39\lib\site-packages\avif-0.0.0-py3.9-win-amd64.egg"``
- ``xcopy "C:\Program Files (x86)\libavif\bin\avif.dll" "c:\python39\lib\site-packages\avif-0.0.0-py3.9-win-amd64.egg"``


13. You should now be able to import the library without any errors!
#. You should now be able to import the library without any errors!

.. code-block:: python
Expand Down
29 changes: 18 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,34 @@ Python bindings for `libavif <https://github.com/AOMediaCodec/libavif>`_ (via
`CFFI <https://cffi.readthedocs.io/en/latest/>`_)


Installation
------------
Installation from PyPI
----------------------

To install this module you will need to compile ``libavif`` yourself. If
you want to make use of the decoder you will also need to compile one
(decoders/encoders can be compiled with ``libavif``).
``pip install avif``


Installation from source
------------------------


To install this module from source you will need to compile ``libavif`` yourself.
If you want to make use of the decoder you will also need to compile one
(decoders/encoders can be compiled from ``libavif``).


**List of available AV1 decoders:**

- **aom** (recommended)
- dav1d
- libgav1
- rav1e
- svt
- `aom <https://aomedia.googlesource.com/aom>`_ (recommended)
- `dav1d <https://code.videolan.org/videolan/dav1d>`_
- `libgav1 <https://chromium.googlesource.com/codecs/libgav1>`_
- `rav1e <https://github.com/xiph/rav1e>`_
- `svt <https://github.com/AOMediaCodec/SVT-AV1>`_

If you compile ``avif`` without an AV1 decoder you will get
``AVIFError: No codec available`` raised when you try to get a result,
but you will still be able to import python module.

The installation steps show how to compile ``libavif`` with the ``aom``
The installation steps below show how to compile ``libavif`` with the ``aom``
decoder.


Expand Down

0 comments on commit e6b1755

Please sign in to comment.