bepaald / signalbackup-tools

Tool to work with Signal Backup files.
GNU General Public License v3.0
790 stars 38 forks source link

Compressing media files #68

Closed cycneuramus closed 2 years ago

cycneuramus commented 2 years ago

Hi, and thank you very much for your work on this useful tool.

Would it be in any way possible to, say, reassemble a functioning backup with attachments taken from a previous media dump?

Use case: backup files are ballooning in size over time due to media attachments, and it would be nice to process these attachments somehow in order to compress (but not replace or delete) them.

I hacked together a simple Python script that I ran on a media dump taken from a recent backup file, and was able to reduce the total size by 75% or so by resizing and compressing jpegs, gifs, and videos. No way to reassemble these media files into a functioning backup again, though—right?

bepaald commented 2 years ago

Thanks for your kind words.

Use case: backup files are ballooning in size over time due to media attachments, and it would be nice to process these attachments somehow in order to compress (but not replace or delete) them.

I think what you want is actually replacing the attachments (that is, replacing images with smaller versions of the same image). For this purpose there are the options to replace attachments, in your case especially 'option 2'. I always imagined that to be used in a script, as it would be a lot of work to do by hand, but you'll probably manage that just fine. Let me know if the description isn't clear and you need some help.

Do note the limitations of this function: first of all, I have not been made aware of it ever being used (apart from my own testing), and the backup format has changed since I wrote those functions. So, there may be bugs. If bugs arise, the more detailed the description of what you were doing exactly as possible would help. This includes the programs output.

Second, at the moment it is only possible to replace attachments (any attachments) with images. So, you could replace video with a single frame or a videosheet (as generated by a program like vcsi for example), but not by another (smaller) video. I might be able to easily lift this limitation, but I would need to inspect the database to see if the program needs to make more changes than the filesize. Let me know if you need this and maybe I'll find some time this weekend.

cycneuramus commented 2 years ago

Ah, I was intimidated by the .bin extensions of the raw decoded backup and didn't realize these could be read as ordinary media files. In any case, I adapted my script to suit your recommendations and tested it out. It seems to have worked perfectly, with no issues restoring the processed backup.

I made a repo with my script and general instructions in case someone hits upon this issue in the future.

Thank you for your help!