pjkundert / ezpwd-reed-solomon

Reed-Solomon & BCH encoding and decoding, in C++, Javascript & Python
https://hardconsulting.com/products/13-reed-solomon
Other
99 stars 21 forks source link

Unable to correctly Encode Compressed video file using RS encoder #3

Closed james224 closed 8 years ago

james224 commented 8 years ago

I am trying to encode my H,264 compressed video using your awesome RS encode library. The Hello world example perfectly worked well. But when trying to read and append RS parity in file the Encoder does not apply RS encoding on the string showing on write side of hex editor. github2 As an example of first few bytes The orignal and encoded string looks as shown in image github3

My question is as follows

2)The right side of HEX editor is in IBM-ASCII format. Should i read my file as HEX apply RS Parity and then write as HEX? or I read file as string add RS parity and write as string? Here is my current code

        ezpwd::RS<255, 211> rs;
        std::string orig = test2;
        std::string copy = orig; // working copy, copy of orig
        rs.encode(copy); // 13 symbols copy + 2 symbols R-S parity added
          cout<<"Orignal String : "<<test2<<endl;
        std::cout << "Encoded:   " << std::vector<uint8_t>(copy.begin(), copy.end()) << std::endl;
        std::stringstream buf;
        std::stringstream buffer;
        buffer << std::vector<uint8_t>(copy.begin(), copy.end());
        buf << copy;

The file content is in test2 variable. But i am unable to recover the test2 after decoding because it is automatically converted to hex which i don;t want. Let me know the way out to solve my problem. Thanks in advance

pjkundert commented 8 years ago

In C++, a std::string contains char data, which is typically signed 8-bit. So, as long as you read and write your data using std::string, you should remain 8-bit clean (no lost data). You should be able to use std::string.

I don't really follow your code -- I don't understand what you say it is or is not doing... I would recommend that you output the "Original String:" exactly the same way you output the "Encoded: string, so you can exactly compare the before/after encode results. I think you will find that the rs.encode is correctly adding the 44 bytes of Reed-Solomon "parity" data to the std::string. You cannot simply output the raw 8-bit data in any of your std::strings; you won't see anything but characters >= 32 and <= 127; everything else will be control characters, and characters >= 128, which probably won't be printed sensibly...

james224 commented 8 years ago

Thanks for your prompt response. I have printed both original and encoded string using ezpwd::hexstr(string ) Function. Both encoded and and original strings are same. But the problem occurs when trying to write back the encoded string into file. The Calculated Hex value is written back to file as string not as HEX. Is there a way to write the encoded hex back to file as hex but not as string? What i want to achieve is 1) Read my compressed video file as HEX 2) Add RS code at the end of each 128 byte size block 3) Write the Encoded file back with Parity added. Any help would be highly appreciated.

pjkundert commented 8 years ago

I'm pretty sure your problems are with your reading/writing code. I suspect that you don't understand what "HEX" means... ;)

If you are reading/writing a binary file, you need to properly designate this on Windows machines (on Unix, everything is read/written in binary-clean form).

I've written an example program that R-S encodes (and decodes) an arbitrary file (or stdin/stdout): https://github.com/pjkundert/ezpwd-reed-solomon/blob/feature-hex/rsencode.C

You can clone https://github.com/pjkundert/ezpwd-reed-solomon.git, and 'git checkout feature-hex' to get this code. Then, run 'make rsencode rsdecode'

By default, this example reads 128-byte chunks, and adds 32 bytes of R-S parity. Change the example code to different values, if you wish. See the documentation in the rsencode.C file for details of how to use it...

Cheers!

james224 commented 8 years ago

Thankyou very much sir. :)