Examples of nvJPEG

This package contains the library header and a set of libraries—static and shared. Shared libraries (the libnvjpeg.so and the respective versioned libraries) have all of the CUDA toolkit dependencies statically linked. However, if you want to link against the static library (libnvjpeg_static.a) you also need to link the other dependencies—for example dl, rt and thread libraries.

Example of linking shared library:

g++ -Icuda-linux64-nvjpeg/include -lnvjpeg -Lcuda-linux64-nvjpeg/lib64 my_example.cpp -o my_example

Example of linking static library:

g++ -Icuda-linux64-nvjpeg/include -lnvjpeg_static -ldl -lrt -pthread -Lcuda-linux64-nvjpeg/lib64 my_example.cpp -o my_example

Example

Below example shows how to use the various nvJPEG APIs.

Compile with the following command from the examples folder, assuming CUDA 9.0 is installed at the path /usr/local/cuda-9.0:

g++ -O3 -m64 nvjpeg_example.cpp -I../include -lnvjpeg -L../lib64 -I/usr/local/cuda-9.0/include -ldl -lrt -pthread -lcudart -L/usr/local/cuda-9.0/lib64 -Wl,-rpath=../lib64 -Wl,-rpath=/usr/local/cuda-9.0/lib64 -o nvjpeg_example

The below examples show how to decode the JPEG files using either single or batched API, and write the decoded files as BMP images.

To decode a single image:

./nvjpeg_example -i /tmp/my_image.jpg -fmt rgb -o /tmp

To decode multiple images in the folder using the batched API in separate phases:

./nvjpeg_example -i /tmp/my_images/ -fmt rgb -b 32 -pipelined -batched -o /tmp

Run the command ./nvjpeg_example -h for the description of the parameters.