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

fix for issue 1915 #3813

Merged
merged 1 commit into from Apr 3, 2015
Merged

fix for issue 1915 #3813

merged 1 commit into from Apr 3, 2015

Conversation

hahne
Copy link
Contributor

@hahne hahne commented Mar 9, 2015

This is a fix for the bug
http://code.opencv.org/issues/1915

The problem was that avcodec_decode_video2 outputs an AVFrame that keeps a
reference to the packet's buffer if the input is a raw video (without a codec).
That leads to the case that av_free_packet (&packet); in line 702 corrupts the AVFrame picture and a segmentation fault occurs later when the function sws_scale() gets called.

This happend only on Linux Ubuntu when inputting a raw video file.

@vpisarev vpisarev self-assigned this Mar 9, 2015
@vpisarev
Copy link
Contributor

vpisarev commented Mar 9, 2015

you said that the problem is only with RAW, but the patch modifies the logic universally, regardless of the format. I'm not sure that the patch will not break some other use cases

@hahne
Copy link
Contributor Author

hahne commented Mar 10, 2015

I can also use
if(enc->codec_id == AV_CODEC_ID_RAWVIDEO)
to change the logic only if one input stream is a raw video.
Should I do that?

@hahne
Copy link
Contributor Author

hahne commented Mar 11, 2015

For sure I do not know every use case and cannot guarantee that this fix will work for every use case.
Processing raw videos and processing videos with a codec worked fine at least for my tests.
But the logic must be changed to fix this bug (logic change is also very small, we still have a av_free_packet (&packet); before every av_read_frame(ic, &packet);. The only change is that there is no av_free_packet (&packet); anymore before leaving the while loop. We can make the change even smaller if we restrict to "no av_free_packet (&packet); anymore before leaving the while loop only if one of the input streams is a raw video".

AVPacket packet is used only in
CvCapture_FFMPEG::init()
CvCapture_FFMPEG::close()
CvCapture_FFMPEG::grabFrame()

The grabFrame function worked fine for me even if av_free_packet (&packet); is not used at all. There is also no case described in the FFMpeg API where av_free_packet (&packet); is used in conjunction with decoding. So it is hard to find out why av_free_packet (&packet); is used here and therefore in which case it can fail if it is not used.

@hahne
Copy link
Contributor Author

hahne commented Mar 27, 2015

Is there any update on this or anything I can do to push this forward?

@vpisarev
Copy link
Contributor

vpisarev commented Apr 2, 2015

@hahne, sorry for delay. let's put it in 👍

@opencv-pushbot opencv-pushbot merged commit 1af4521 into opencv:master Apr 3, 2015
vpisarev added a commit that referenced this pull request Apr 3, 2015
@hahne
Copy link
Contributor Author

hahne commented Apr 3, 2015

cool 👍

@alalek alalek mentioned this pull request Mar 16, 2016
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

Successfully merging this pull request may close these issues.

None yet

3 participants