fixed mjpeg encoder so that libjpeg-based decoder does not complain on extra bytes in the end of stream

This commit is contained in:
Vadim Pisarevsky 2015-04-23 14:40:44 +03:00
parent dcf177e372
commit d825b7ee9a
2 changed files with 22 additions and 3 deletions

View File

@ -552,11 +552,11 @@ static Ptr<IVideoCapture> IVideoCapture_create(int index)
}
static Ptr<IVideoCapture> IVideoCapture_create(const String&)
static Ptr<IVideoCapture> IVideoCapture_create(const String& filename)
{
Ptr<IVideoCapture> capture;
//capture = createMotionJpegCapture(filename);
capture = createMotionJpegCapture(filename);
if (capture && capture->isOpened())
{
return capture;

View File

@ -248,6 +248,25 @@ public:
writeBlock();
}
void jflush(unsigned currval, int bitIdx)
{
uchar v;
uchar* ptr = m_current;
currval |= (1 << bitIdx)-1;
while( bitIdx < 32 )
{
v = (uchar)(currval >> 24);
*ptr++ = v;
if( v == 255 )
*ptr++ = 0;
currval <<= 8;
bitIdx += 8;
}
m_current = ptr;
if( m_current >= m_end )
writeBlock();
}
static bool createEncodeHuffmanTable( const int* src, unsigned* table, int max_size )
{
int i, k;
@ -1440,7 +1459,7 @@ void MotionJpegWriter::writeFrameData( const uchar* data, int step, int colorspa
}
// Flush
JPUT_BITS((unsigned)-1, bit_idx & 31);
strm.jflush(currval, bit_idx);
strm.jputShort( 0xFFD9 ); // EOI marker
/*printf("total dct = %.1fms, total cvt = %.1fms\n",
total_dct*1000./cv::getTickFrequency(),