Skip to content

Fixed bug with the last 4 bytes in MJPEG encoder#24209

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
alexlyulkov:al/fixed-mjpeg
Sep 5, 2023
Merged

Fixed bug with the last 4 bytes in MJPEG encoder#24209
asmorkalov merged 1 commit intoopencv:4.xfrom
alexlyulkov:al/fixed-mjpeg

Conversation

@alexlyulkov
Copy link
Copy Markdown
Contributor

@alexlyulkov alexlyulkov commented Aug 31, 2023

resolves #19634
resolves #24171
Enabled parallel processing, that was temporary disabled in #19812 because of the issue #19634


m_data_len = m_buffer_list[0].get_len();
m_last_bit_len = m_buffer_list[0].get_bits_free() ? 32 - m_buffer_list[0].get_bits_free() : 0;
m_last_bit_len = 32 - m_buffer_list[0].get_bits_free();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you call mjpeg_buffer::finish() than mjpeg_buffer::get_len() returns the number of occupied integers and mjpeg_buffer::get_bits_free() returns the number of free bits in the last integer (from 0 to 31)


m_data_len = m_buffer_list[0].get_len();
m_last_bit_len = m_buffer_list[0].get_bits_free() ? 32 - m_buffer_list[0].get_bits_free() : 0;
m_last_bit_len = 32 - m_buffer_list[0].get_bits_free();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you call mjpeg_buffer::finish() than mjpeg_buffer::get_len() returns the number of occupied integers and mjpeg_buffer::get_bits_free() returns the number of free bits in the last integer (from 0 to 31)

m_output_buffer[m_data_len++] = currval;

m_last_bit_len = -bits;
if (bits != 0) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If bits != 0 than currval contains some useful bits. We need to increase m_data_len and add the bits to the last item of m_output_buffer.
If bits == 0 than currval doesn't contain useful bits

@asmorkalov asmorkalov self-requested a review September 4, 2023 09:51
@asmorkalov asmorkalov added this to the 4.9.0 milestone Sep 4, 2023
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks a lot for the patch! I removed the guard by myself.

@asmorkalov asmorkalov merged commit 21fb10c into opencv:4.x Sep 5, 2023
@asmorkalov asmorkalov mentioned this pull request Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cv::VideoWriter with CAP_OPENCV_MJPEG api creates broken (or just unfinished) video file. Out of bound access in cap_mjpeg_encoder.cpp

2 participants