Last modified: Jun 01, 2025 By Alexander Williams

Install PyAV for Audio/Video Processing in Python

PyAV is a Python binding for FFmpeg. It helps process audio and video files. This guide shows how to install PyAV easily.

Prerequisites for PyAV

Before installing PyAV, ensure you have Python 3.6+. Also, install FFmpeg on your system. FFmpeg is required for PyAV to work.

Check Python version using python --version. For FFmpeg, run ffmpeg -version in your terminal.


python --version
ffmpeg -version

Install PyAV Using pip

The easiest way to install PyAV is via pip. Run the following command in your terminal.


pip install av

This installs the latest stable version of PyAV. For specific versions, use pip install av==version_number.

Verify PyAV Installation

After installation, verify PyAV works. Open a Python shell and import the library.


import av
print(av.__version__)

This should print the installed PyAV version. If no errors appear, PyAV is ready.

Common Installation Issues

Some users face issues during installation. Here are common problems and fixes.

FFmpeg not found: Ensure FFmpeg is installed. Add it to your system PATH if needed.

Permission errors: Use pip install --user av for user-level installation.

Build errors: Install required build tools. On Linux, use sudo apt-get install build-essential.

Basic PyAV Usage Example

Here’s a simple example to extract audio from a video file using PyAV.


import av

# Open video file
container = av.open('input.mp4')

# Extract audio stream
audio_stream = next(s for s in container.streams if s.type == 'audio')

# Save audio to file
for frame in container.decode(audio_stream):
    frame.export('output.mp3', format='mp3')

This code reads an MP4 file and saves its audio as MP3. PyAV makes such tasks simple.

Advanced PyAV Features

PyAV supports many advanced features. These include video resizing, frame manipulation, and more.

For example, you can resize a video frame using PyAV’s reformat method.


import av

container = av.open('input.mp4')
video_stream = next(s for s in container.streams if s.type == 'video')

for frame in container.decode(video_stream):
    resized_frame = frame.reformat(width=640, height=480)
    resized_frame.to_image().save('output.jpg')

This resizes each frame to 640x480 and saves it as an image.

PyAV vs Other Libraries

PyAV is faster than many Python video libraries. It directly binds to FFmpeg. This gives it a performance edge.

For JavaScript in Python, check Install PyMiniRacer for V8 JavaScript in Python.

For serial communication, see Install pySerialTransfer in Python Easily.

Conclusion

PyAV is powerful for audio/video processing. It’s easy to install with pip. Ensure FFmpeg is available.

For more Python guides, explore our tutorials. Try Install PyTables with HDF5 Support in Python next.