gstreamer-1.0 use nvjpegdec element Crash in C language

I want to get pic data by using gstreamer-1.0 C interface,
but when run this code,my app crashed with “bus eeror”.

gst_element_factory_make ("nvjpegdec", "myjpegdec");

Does nvjpegdec support this way?

Hi,
We don’t observe the issue. Please refer to attachment

test2.zip (1.2 KB)

Thanks,

it works by raplacing

gst_element_factory_make ("nvjpegdec", "myjpegdec");

with

gst_parse_launch(launch_string.c_str(), &error);

But it will cost 100ms to decode a jpeg which resolution is 4096 * 2160.
Is the speed normal?
I think it will decode more fast.

It looks OK for decoding 4K jpeg. You may run jetson_clocks.sh to get better performance.

For 4Kp30 decoding, we suggest you use H264/H265.

I used gstreamer-1.0 in cmake file as below:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

project(camera_agent CXX)
find_package(PkgConfig REQUIRED)

find_package(OpenCV REQUIRED)

include_directories(
  /usr/local/include
  ${GLIB_INCLUDE_DIRS}
)
link_directories(
  ${GLIB_LIBRARY_DIRS}
)
set(GSTREAMER_MINIMUM_VERSION 1.0.5)
pkg_check_modules(GST1_TEST gstreamer-1.0)
if ( GST1_TEST_FOUND AND NOT ${GST1_TEST_VERSION} VERSION_LESS ${GSTREAMER_MINIMUM_VERSION} )
    pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
    pkg_check_modules(GSTREAMER-APP REQUIRED gstreamer-app-1.0)
    pkg_check_modules(GSTREAMER-AUDIO REQUIRED gstreamer-audio-1.0)
    pkg_check_modules(GSTREAMER-PBUTILS REQUIRED gstreamer-pbutils-1.0)
    pkg_check_modules(GSTREAMER-FFT REQUIRED gstreamer-fft-1.0)
    add_definitions(-DGST_API_VERSION_1=1)
else()
    # fallback to gstreamer-1.0
    unset(GSTREAMER_MINIMUM_VERSION)
    pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
    pkg_check_modules(GSTREAMER-APP REQUIRED gstreamer-app-1.0)
    pkg_check_modules(GSTREAMER-AUDIO REQUIRED gstreamer-audio-1.0)
    pkg_check_modules(GSTREAMER-FFT REQUIRED gstreamer-fft-1.0)
    set_source_files_properties(WebKitWebAudioSourceGStreamer.cpp PROPERTIES COMPILE_DEFINITIONS "GLIB_DISABLE_DEPRECATION_WARNINGS=1")
endif()

include_directories(
  ${GSTREAMER_INCLUDE_DIRS}
  ${GSTREAMER-APP_INCLUDE_DIRS}
  ${GSTREAMER-AUDIO_INCLUDE_DIRS}
  ${GSTREAMER-PBUTILS_INCLUDE_DIRS}
  ${GSTREAMER-FFT_INCLUDE_DIRS}
  ${CMAKE_CURRENT_SOURCE_DIR}
  include
)
link_directories(
  ${GSTREAMER_LIBRARY_DIRS}
  ${GSTREAMER-APP_LIBRARY_DIRS}
  ${GSTREAMER-AUDIO_LIBRARY_DIRS}
  ${GSTREAMER-PBUTILS_LIBRARY_DIRS}
  ${GSTREAMER-FFT_LIBRARY_DIRS}
  /usr/lib/
)

set(inputtest_LIBRARIES
  ${GSTREAMER_LIBRARIES}
  ${GSTREAMER-APP_LIBRARIES}
  ${GSTREAMER-AUDIO_LIBRARIES}
  ${GSTREAMER-PBUTILS_LIBRARIES}
  ${GSTREAMER-FFT_LIBRARIES}
    
  pthread
  ${GLIB_LIBRARIES}
  ${GLIB_GIO_LIBRARIES}
  ${GLIB_GOBJECT_LIBRARIES}
)
add_executable(
    camera_agent
    src/camera_agent.cpp
    )
target_link_libraries(
    camera_agent 
    v4l2
    uvc_camera 
    zmq_util
    agent_manager
    thread_manager
    cppzmq
    opencv_camera
    memory_manager
    config_manager
    ${OpenCV_LIBS}
    glog
    ${inputtest_LIBRARIES}
    )

# set the output directory and output file name
set_target_properties(camera_agent 
    PROPERTIES 
    OUTPUT_NAME               "camera_agent"
    RUNTIME_OUTPUT_DIRECTORY  "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/")

It will print “core dumped”,when running this code:

gst_element_factory_make ("nvjpegdec", "myjpegdec")

However,it will run normally by using Makefile as below:

TARGET=sample
CC=g++
SRC=$(wildcard *.cpp)
OBJ=$(SRC:.cpp=.o)
CXXFLAGS=-g
CXXFLAGS  += `pkg-config --cflags gstreamer-1.0 gstreamer-app-1.0 glib-2.0`
LDFLAGS += `pkg-config --libs gstreamer-1.0 gstreamer-app-1.0 glib-2.0` -lpthread
all:$(TARGET)
$(TARGET):$(OBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
clean:
	rm -f $(TARGET) $(OBJ)

I want to use in cmake file.Would you please give me your hand ?

try to use gst_parse_launch(launch_string.c_str(), &error) instead of gst_element_factory_make (“nvjpegdec”, “myjpegdec”) in your code.

Thanks a lot.
It does’t work.

I have the same problem. I get:

[gstreamer] initialized gstreamer, version 1.14.5.0
Bus error (core dumped)

when I run

std::string launchStr = "v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480, framerate=30/1 ! nvjpegdec ! video/x-raw ! nvvidconv ! 'video/x-raw(memory:NVMM), format=NV12' ! videoconvert ! appsink name=mysink";
gst_parse_launch(launchStr.c_str(), &error)

Does anyone know how to resolve this problem by any chance? nvjpegdec works perfectly when I launch the pipeline above through the command line (gst-launch-1.0).

Hi,
Please check the following post:
https://devtalk.nvidia.com/default/topic/1070087/jetson-tx2/bus-error-with-gstreamer-and-opencv-/post/5422014/#5422014
nvjpegdec is not compatible with OpenCV. Please use jpegdec plugin.

@DaneLLL I used only the C++ API for Gstreamer and didn’t actually use OpenCV (gst_parse_launch is included from <gst/gst.h>, I believe). I also added proper include paths into my CMakeLists.txt file for GStreamer.

Hi,
Have you tried the sample in #2?

@DaneLLL Please could you share the Makefile/CMakeLists.txt/g++ command that you used to compile the file and include the libraries? I am getting an error when compiling the file with my project’s CMakeLists.txt:

//usr/lib/aarch64-linux-gnu/libgobject-2.0.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Update: was able to compile and test the source file in #2 using @wangxin112’s CMakeLists.txt - it works! Looks like it’s the problem with dependencies in the first project. Will investigate further.

Hi,
For your reference:

nvidia@nvidia-desktop:~$ g++ test2.cpp -o test2 $(pkg-config --cflags --libs gstreamer-app-1.0)
nvidia@nvidia-desktop:~$ ./test2
Using launch string: filesrc location=a.jpg ! nvjpegdec ! video/x-raw ! appsink name=mysink
2976x2976, map.size = 13284864
app sink receive eos

You were absolutely right! The error was due to having cv::imread in one of the source files (even if I don’t call the function in my code). If I replace nvjpegdec with jpegdec or if I delete the cv::imread call, then the error goes away.

Do you know why would that be the case by any chance? libjpeg gets linked instead of libnvjpeg, if I define cv::imread in my source files?

Hi,

You may give it a try. Or use libjpeg while building application with OpenCV.
Currently libnvjpeg does not work with OpenCV.