RomanArzumanyan / VALI

Video processing in Python
Apache License 2.0
36 stars 4 forks source link

Do you have C++ version example?please #32

Closed 140ai closed 6 months ago

140ai commented 6 months ago

Do you have C++ version example? please

RomanArzumanyan commented 6 months ago

Hi @140ai

There's no dedicated VALI C++ facet. The reasons are as follows:

  1. Lack of resources to maintain and improve both C++ and Python build experience. C++ doesn't have any out-of-the-box packaging tools. There will be a great many of similar issues about missing headers and libraries.
  2. Top level C++ code uses pybind11 project for memory exchange. It's not a big deal as long as you're OK to introduce pybind11 dependency in your project.
  3. Once C++ facet is made public, GTest unit tests are to be developed and maintained to ensure C++ API quality and stability.
  4. Different needs of Python and C++ users. It's mostly reflected in different approaches to threads and everything async.

Let's draw a conslusion: It's possible to use VALI libraries in your C++ application. For that you can link it against _PyNvCodec target and use high-level classes declared in PyNvCodec.hpp.

Your code will look something like this:

#include "PyNvCodec.hpp"
#include "pybind11.h"

int main() {
  PyNvDecoder nvdec("/path/to/input.mp4", {});
  py::array_t<uint8_t> frame;
  PacketData out_pkt_data;
  TaskExecDetails details;
  DecodeContext ctx(nullptr, nullptr, nullptr, &out_pkt_data, nullptr, false);

  // Your decoded frame and status are in tuple; 
  auto ret = std::make_tuple(self->DecodeFrame(ctx, details, frame), details.info);
}

Note that it's ugly. C++ API is pretty much designed to serve Python land needs.

140ai commented 6 months ago

Hi @140ai

There's no dedicated VALI C++ facet. The reasons are as follows:

  1. Lack of resources to maintain and improve both C++ and Python build experience. C++ doesn't have any out-of-the-box packaging tools. There will be a great many of similar issues about missing headers and libraries.
  2. Top level C++ code uses pybind11 project for memory exchange. It's not a big deal as long as you're OK to introduce pybind11 dependency in your project.
  3. Once C++ facet is made public, GTest unit tests are to be developed and maintained to ensure C++ API quality and stability.
  4. Different needs of Python and C++ users. It's mostly reflected in different approaches to threads and everything async.

Let's draw a conslusion: It's possible to use VALI libraries in your C++ application. For that you can link it against _PyNvCodec target and use high-level classes declared in PyNvCodec.hpp.

Your code will look something like this:

#include "PyNvCodec.hpp"
#include "pybind11.h"

int main() {
  PyNvDecoder nvdec("/path/to/input.mp4", {});
  py::array_t<uint8_t> frame;
  PacketData out_pkt_data;
  TaskExecDetails details;
  DecodeContext ctx(nullptr, nullptr, nullptr, &out_pkt_data, nullptr, false);

  // Your decoded frame and status are in tuple; 
  auto ret = std::make_tuple(self->DecodeFrame(ctx, details, frame), details.info);
}

Note that it's ugly. C++ API is pretty much designed to serve Python land needs.

Thank you very mush.