Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange Bug ! [core dump] When compiling with cv::imencode , ".mkv" files decode would hit core dump #179

Open
ithanwu opened this issue Nov 15, 2023 · 0 comments

Comments

@ithanwu
Copy link

ithanwu commented Nov 15, 2023

I found a strange bug that when I used cv::imencode in my code , I can't decode a .mkv video file!
That' so ....weired.. and it's easy to reproduce ,
Reproduce steps:
my codes

//below is my code snipt
int main( int argc, char** argv ){
	commandLine cmdLine(argc, argv);
	videoSource* input = videoSource::Create(cmdLine, ARG_POSITION(0));
	if( !input ){
		LogError("video-viewer:  failed to create input stream\n");
		return 0;
	}
	while(true){
		uchar3* image = NULL;
		int status = 0;
		
		if( !input->Capture(&image, &status) )
		{
			if( status == videoSource::TIMEOUT )
				continue;
			
			break; // EOS
		}		
		std::vector<uchar> encoded_data;
		cv::Mat frameclone = cv::Mat(720,1280,CV_8UC3,image).clone();         
                 //this line IS THE KILLER !,if comment it ,the issue disappear !
		cv::imencode(".jpg",frameclone,encoded_data);
	}
}

compile above code , and try to use it to read a ".mkv" file ,like this

./videotest ./1722548788536541184.mkv

Then the issue occur !

[gstreamer] initialized gstreamer, version 1.16.3.0
[gstreamer] gstDecoder -- creating decoder for ./1722548788536541184.mkv
Bus error (core dumped)

BUT,guess what ?
if comment the line using cv::imencdoe ,everything would become OK !Below is the output when "cv::imencode" line commented

[gstreamer] initialized gstreamer, version 1.16.3.0
[gstreamer] gstDecoder -- creating decoder for ./1722548788536541184.mkv
NvMMLiteBlockCreate : Block : BlockType = 256 
[JPEG Decode] BeginSequence Display WidthxHeight 1280x720
[JPEG Decode] NvMMLiteJPEGDecBlockPrivateClose done
[JPEG Decode] NvMMLiteJPEGDecBlockClose done
[gstreamer] gstDecoder -- discovered video resolution: 1280x720  (framerate 25.000000 Hz)
[gstreamer] gstDecoder -- discovered video caps:  image/jpeg, framerate=(fraction)25/1, width=(int)1280, height=(int)720, interlace-mode=(string)progressive, colorimetry=(string)2:4:5:1
[gstreamer] gstDecoder -- pipeline string:
[gstreamer] filesrc location=./1722548788536541184.mkv ! matroskademux ! queue ! jpegdec name=decoder ! video/x-raw ! appsink name=mysink
[video]  created gstDecoder from file:///home/holyblade/codes/situp_jetson/situp_service/build/./1722548788536541184.mkv
------------------------------------------------
gstDecoder video options:
------------------------------------------------
  -- URI: file:///home/holyblade/codes/situp_jetson/situp_service/build/./1722548788536541184.mkv
     - protocol:  file
     - location:  ./1722548788536541184.mkv
     - extension: mkv
  -- deviceType: file
  -- ioType:     input
  -- codec:      MJPEG
  -- codecType:  cpu
  -- width:      1280
  -- height:     720
  -- frameRate:  25
  -- numBuffers: 4
  -- zeroCopy:   true
  -- flipMethod: none
  -- loop:       0
------------------------------------------------
[gstreamer] opening gstDecoder for streaming, transitioning pipeline to GST_STATE_PLAYING
[gstreamer] gstreamer changed state from NULL to READY ==> mysink
[gstreamer] gstreamer changed state from NULL to READY ==> capsfilter0
[gstreamer] gstreamer changed state from NULL to READY ==> decoder
[gstreamer] gstreamer changed state from NULL to READY ==> queue0
[gstreamer] gstreamer changed state from NULL to READY ==> matroskademux1
[gstreamer] gstreamer changed state from NULL to READY ==> filesrc0
[gstreamer] gstreamer changed state from NULL to READY ==> pipeline0
[gstreamer] gstreamer changed state from READY to PAUSED ==> capsfilter0
[gstreamer] gstreamer changed state from READY to PAUSED ==> decoder
[gstreamer] gstreamer stream status CREATE ==> src
[gstreamer] gstreamer changed state from READY to PAUSED ==> queue0
[gstreamer] gstreamer stream status ENTER ==> src
[gstreamer] gstreamer stream status CREATE ==> sink
[gstreamer] gstreamer changed state from READY to PAUSED ==> matroskademux1
[gstreamer] gstreamer changed state from READY to PAUSED ==> filesrc0
[gstreamer] gstreamer stream status ENTER ==> sink
[gstreamer] gstDecoder -- onPreroll()
[gstreamer] gstreamer message stream-start ==> pipeline0
[gstreamer] gstreamer mysink taglist, container-format=(string)Matroska;
[gstreamer] gstreamer mysink taglist, video-codec=(string)"Motion\ JPEG";
[gstreamer] gstBufferManager -- map buffer size was less than max size (1382400 vs 1382407)
[gstreamer] gstBufferManager recieve caps:  video/x-raw, format=(string)I420, width=(int)1280, height=(int)720, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)1:4:0:0, framerate=(fraction)25/1
[gstreamer] gstBufferManager -- recieved first frame, codec=MJPEG format=i420 width=1280 height=720 size=1382407
[gstreamer] gstreamer changed state from READY to PAUSED ==> mysink
[gstreamer] gstreamer changed state from READY to PAUSED ==> pipeline0
[gstreamer] gstreamer message async-done ==> pipeline0
[gstreamer] gstreamer message new-clock ==> pipeline0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> mysink
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> capsfilter0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> decoder
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> queue0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> matroskademux1
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> filesrc0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> pipeline0
[cuda]   allocated 4 ring buffers (1382407 bytes each, 5529628 bytes total)
[cuda]   allocated 4 ring buffers (8 bytes each, 32 bytes total)
[cuda]   allocated 4 ring buffers (2764800 bytes each, 11059200 bytes total)

Is there any way to solve this ?

Thank you my dude !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant