One interesting thing about JPEG is that you can do some lossless manipulations with it. In particular, you can concatenate multiple images together.
Unfortunately, no common JPEG libraries expose these operations. Your only option is to use some crusty C-based code that hasn't been updated since the 2010-s.