Decord Documentation

repository·master·Indexed 25 days ago

https://github.com/dmlc/decord

A high-performance video decoding library designed for deep learning. Decord provides efficient random access to video frames and audio samples via VideoReader, AudioReader, and AVReader. It supports GPU acceleration (NVDEC), automatic video rotation, and seamless integration with deep learning frameworks like PyTorch, TensorFlow, and MXNet through a bridging system. It includes tools for video loading, segmenting, and image processing such as color space conversion and resizing.

Tokens
4.2K
Snippets
10
Records
35
Agent score
82%

What's inside Decord

  1. Overview of Image Processing Functions in Decord

    master

    Decord provides image processing capabilities primarily focused on two essential tasks:

    1. Color Space Conversion: Converting video frames from the original YUV format to RGB.
    2. Resizing: Reducing the resolution of frames to decrease the memory footprint during processing.

    Implementation Details

    • CPU: These functions are implemented using the FFMPEG filter graph.
    • GPU: GPU-accelerated versions require the implementation of CUDA kernels.
  2. FFMPEG components used in Decord

    master

    Decord utilizes the following FFMPEG library components for video decoding operations:

    • Libavcodec: For encoding and decoding.
    • Libavfilter: For applying filters to the video stream.
    • Libavformat: For muxing and demuxing (handling containers and formats).
  3. Requirements for GPU accelerated decoding through nvdec

    master

    To use GPU accelerated decoding via nvdec in Decord, you must ensure your system meets the following hardware and software requirements:

    • CUDA Driver and Toolkit: Version 8.0 or higher.
    • Hardware: A supported NVIDIA graphics card.
  4. Install Decord from source (Windows)

    master

    Windows installation requires CMake and Visual Studio for C++ compilation.

    Prerequisites:

    Steps:

    1. Clone the repository recursively.
    2. Create a build directory.
    3. Run CMake with the specific Visual Studio generator and flags.
    4. Open the generated .sln file in Visual Studio to build the project.
    git clone --recursive https://github.com/decord
    cd decord
    mkdir build
    cd build
    cmake -DCMAKE_CXX_FLAGS="/DDECORD_EXPORTS" -DCMAKE_CONFIGURATION_TYPES="Release" -G "Visual Studio 15 2017 Win64" ..
    # Open decord.sln and build project in Visual Studio
  5. Install Decord via pip

    master

    The easiest way to install Decord is using pip. Note that the PyPI version only provides CPU versions. To enable GPU acceleration (NVDEC), you must build from source.

    pip install decord
  6. Install Decord from source (macOS)

    master

    macOS users should use Homebrew to install cmake and ffmpeg. Ensure you have the Xcode Command Line Tools installed via xcode-select --install.

    Steps:

    1. Clone the repository recursively.
    2. Build the shared library in the build directory.
    3. Install Python bindings via setup.py or $PYTHONPATH.
    xcode-select --install
    brew install cmake ffmpeg
    
    git clone --recursive https://github.com/dmlc/decord
    cd decord
    mkdir build && cd build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    make
    
    cd ../python
    python3 setup.py install --user
  7. Install Decord from source (Linux)

    master

    To enable GPU acceleration or use specific FFmpeg versions, build from source on Linux.

    Prerequisites:

    • CMake 3.8 or later.
    • For Ubuntu/Debian, install system packages including ffmpeg (version 4.0+ recommended) and libavcodec-dev.

    Steps:

    1. Clone the repository recursively: git clone --recursive https://github.com/dmlc/decord.
    2. Build the shared library using CMake. Use -DUSE_CUDA=ON to enable NVDEC hardware acceleration.
    3. Install Python bindings using setup.py or by adding the path to $PYTHONPATH.
    # Install dependencies (Ubuntu example)
    sudo add-apt-repository ppa:jonathonf/ffmpeg-4
    sudo apt-get update
    sudo apt-get install -y build-essential python3-dev python3-setuptools make cmake ffmpeg libavcodec-dev libavfilter-dev libavformat-dev libavutil-dev
    
    # Build
    git clone --recursive https://github.com/dmlc/decord
    cd decord
    mkdir build && cd build
    cmake .. -DUSE_CUDA=ON -DCMAKE_BUILD_TYPE=Release
    make
    
    # Install Python bindings
    cd ../python
    python3 setup.py install --user
  8. Automatic video rotation

    master
    Decord automatically handles video rotation based on metadata (e.g., for mobile phone videos). This ensures that frames are correctly oriented without manual intervention, unlike some other libraries like OpenCV where rotation might need to be handled manually.
  9. Use VideoLoader for deep learning training

    master

    The VideoLoader is optimized for training deep learning models with large datasets. It handles video shuffling efficiently to minimize the performance penalty of random access seeking.

    Parameters:

    • list_of_files: List of video file paths.
    • ctx: List of contexts (e.g., [cpu(0)]).
    • shape: Desired output shape.
    • interval: Frame interval.
    • skip: Number of frames to skip.
    • shuffle: Shuffling mode.

    Shuffling Modes (shuffle):

    • 0: Sequential (no seeking, follows filename order).
    • 1: Random filename order (no random access within videos, very efficient).
    • 2: Random order.
    • 3: Random frame access within each video.
    • -1: Smart shuffle mode (based on video properties, implementation pending).