0

I'm trying to record a jpeg image sent by an Ethernet camera in a mjpg stream. The image I obtain with my Borland C++ application (VSPCIP) looks identical in Notepad++ to the tcp stream saved from the application Wireshark (except for the number of characters : 15540 in my file, and 15342 in the wireshark file, whereas the jpeg content-length is announced to be 15342). That is to say that I have 198 non-displayable characters more than expected but both files have 247 lines.

Here are the two files : http://demo.ovh.com/fr/a61295d39f963998ba1244da2f55a27d/

Which tool could I use (in Notepad++ (I tried to display in UTF8 or ANSI : files still match whereas they don't have the same number of characters) or another editor) to view the non-displayable characters ?

Arnaud
  • 109
  • 3
  • 15
  • In your program, do you open the file in binary or text mode? – Some programmer dude Jan 13 '12 at 14:11
  • In my program, I store the byte from the TCP stream to a : BYTE * ImageFrame = new BYTE [ContentLength]; and to create a file (just to view the data of the BYTE*) I use : std::ofstream * mpofs; mpofs = new std::ofstream("out.jpg"); for(int i=0;i – Arnaud Jan 13 '12 at 14:29

1 Answers1

1

std::ofstream by default opens the file in text mode, which means it might translate newline characters ('\n' binary 0x0a) into a carriage-return/newline sequence ("\r\n", binary 0x0d and 0x0a).

Open the output file in binary mode and it will most likely solve your problem:

std::ofstream os("filename", ios_base::out | ios_base::binary);
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • ok tak, std::ios_base helped : I have a good jpg image, my problem is perhaps somewhere else : I have sometimes incomplete frames (though I used a mutex to avoid reading the byte * while I fill it, my problem so must be in the way I decode the tcp stream, I search this way and tell further). Thanks – Arnaud Jan 13 '12 at 14:48
  • Ok I found an "incomplete jpeg frame" : it has 21690 characters (for a 640x480 jpeg image) and among them there is a string of 5045 following characters which have the value "NUL" (displayed as NUL in Notepad++). Two things : - I would first like to remove these corrupted frame - it would be good to understand in the TCP "readbyte" why it adds this string – Arnaud Jan 13 '12 at 15:52
  • I will move this to another question in fact. – Arnaud Jan 13 '12 at 15:55
  • Moved here : http://stackoverflow.com/questions/8853460/unwanted-nul-characters-string-after-reading-bytes-of-a-mjpg-tcp-stream – Arnaud Jan 13 '12 at 16:23