2

I have received motion jpeg frames from a ip camera by RTP stream, and I try to convert the frames to valid jpg images. My camera model is Secubest PXN-0512P. It multicast the video of motion jpeg data by RTP stream. Now, I have decode the RTP stream and got each frames in memory, and i try to convert it to valid jpg image.

Do you know so tools to complete this function? And what are the steps to deal with m-jpeg frame? (such as add jpeg-header, huffman table). I am a new programer in this field.

I program it in C++ language.

Thank you very much.

Update 1 I try to directly write the recieved frame data to jpg, when i open it at ubuntu, it show warning "Error interpreting JPEG image file (Not a JPEG file: starts with 0x00 0x00)". Then I add a JFIF header to it, it shows warning"Error interpreting JPEG image file (Unsupported marker type 0xf0". Jpeg_header is

char jpg_header1[] = {
        0xff, 0xd8,                          // SOI
        0xff, 0xe0,                          // APP0
        0x00, 0x10,                          // APP0 Hdr size
        0x4a, 0x46, 0x49, 0x46, 0x00, // ID string
        0x01, 0x01,                          // Version
        0x00,                               // Bits per type
        0x00, 0x00,                         // X density
        0x00, 0x00,                         // Y density
        0x00,                               // X Thumbnail size
        0x00                                // Y Thumbnail size
        };

My code is

m_FileStream.write(jpg_header1, sizeof(jpg_header1)); int skip_bytes = 2; m_FileStream.write(mem_buffer.pData+skip_bytes, mem_buffer.DataSize-skip_bytes);

How could i solve it? Thank you very much!

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
user3801316
  • 23
  • 1
  • 5

2 Answers2

2

JPEG image is broken into parts according to RFC 2435 "RTP Payload Format for JPEG-compressed Video". You need to merge parts back into valid JPEG following this C# library/method: Saving JPEG file coming from Network Camera RTP Stream

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158
1

The fastest way to create JPEG from raw data or other sources is using the libjpeg C library created by the JPEG group themselves.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • The mjpeg frame is similar to jpeg image, should i decompress the frame data and then compress it to jpg image? And should i do some preprocessing to the row frame data? Thank you very much! – user3801316 Jul 03 '14 at 12:54
  • @user3801316 per [wiki page on MJPEG](http://en.wikipedia.org/wiki/Motion_JPEG), each frame is already jpg, so if write the frames as they are to a file, should have a jpg – Tony The Lion Jul 03 '14 at 13:27
  • I try to directly write the recieved frame data to jpg, when i open it at ubuntu, it show warning "Error interpreting JPEG image file (Not a JPEG file: starts with 0x00 0x00)". Then I add a JFIF header to it, it shows warning"Error interpreting JPEG image file (Unsupported marker type 0xf0". My code is 'm_FileStream.write(jpg_header1, sizeof(jpg_header1)); int skip_bytes = 2; m_FileStream.write(mem_buffer.pData+skip_bytes, mem_buffer.DataSize-skip_bytes);' – user3801316 Jul 03 '14 at 14:21
  • sounds like there's something wrong with your format. Bit hard to remotely debug. AFAIK the libjpeg has functions to write jpegs to file correctly. – Tony The Lion Jul 03 '14 at 15:30