Skip to content

VPF debugging

Stephan Seitz edited this page Jan 30, 2023 · 13 revisions

Basic idea

VPF is a collection of C++ libraries which are exported as Python module with the help of pybind11 project.
You can debug VPF just as any another C++ application or library. There are many ways to do that both under Windows and Linux.

Prepare in advance

Please make sure you have Debug VPF build .
Build type is set with CMake at configure stage. It's defined by variable CMAKE_BUILD_TYPE. Typical values for that are: Debug, Release, RelWithDebInfo. When using pip for VPF installation, you can specify CMake variables as follows https://scikit-build.readthedocs.io/en/latest/usage.html#environment-variable-configuration

GDB / CGDB

This approach requires the least amount of tools: no IDE needed and even no GUI required. You can use this on your headless setups just as well.
For the sake of brevity, assuming you have built and installed VPF to ~/Git/VideoProcessingFramework/install/bin.

Run cgdb org gdb --tui and select your Python interpreter as target application, pass path to your script and it's arguments.
Because Python interpreter will load PyNvCodec and PytorchNvCodec modules as shared libraries, you can put a breakpoint there and debug the C++ code.

cgdb --args python3 ./SampleDemuxDecode.py 0 ~/Videos/bbb_sunflower_1080p_30fps_normal.mp4 ./out.yuv

Now within the cgdb debugger, let's put a breakpoint.
GDB will complain that function is not defined, that happens because TC shared library isn't loaded yet.
That's not an issue, the breakpoint will become active as soon as TC library is loaded by your Python interpreter.

(gdb) b FFmpegDemuxer::Demux
Function "FFmpegDemuxer::Demux" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (FFmpegDemuxer::Demux) pending.

And run our application:

(gdb) run

Soon the breakpoint will be hit and you will have a chance to debug C++ part of VPF step by step: Debugging VPF with cgdb

Visual Studio Code

VS Code relies on extensions for C++ support, so make sure you have C++ extension installed.
C++ debugging in VS code is pretty straightforward, please see the JSON debug configuration below:

{
  "name": "SampleDemuxDecodeCpp",
  "type": "cppdbg",
  "request": "launch",
  "program": "/usr/bin/python3",
  "cwd": "~/Git/VideoProcessingFramework/install/bin",
  "console": "integratedTerminal",

  "args": [
    "./SampleDemuxDecode.py",
    "0",
    "~Videos/bbb_sunflower_1080p_30fps_normal.mp4",
    "~Videos/bbb_sunflower_1080p_30fps_normal.yuv"
  ],

  "environment": [
    {
      "name": "LD_LIBRARY_PATH",
      "value": "~/Install/ffmpeg-4.3.2/build_x64_release_shared/lib"
    }
  ],
}

Now put a breakpoint in C++ code and start the SampleDemuxDecodeCpp debug configuration: Debugging VPF with Visual Studio Code

Visual Studio

You can debug C++ part by setting up Debug Visual Studio configuration: Setting up VPF debug configuration in Visual Studio The rest is same to that for Visual Studio Code - put a breakpoint int your C++ code and start debugging.