ffmpeg – Muxing a JPEG bitstream inside a TIFF container?

On my Linux system (Debian) I can decode and then re-encode JPEG to TIFF using:

% ffmpeg -i input.jpeg -pix_fmt rgba output.tiff

The above is a lossy process (JPEG compression is done over an existing JPEG bitstream).

Or even using libtiff-tools:

% convert -size 256x256 -depth 8 xc:white white.ppm
% ppm2tiff white.ppm white.tiff
% tiffcp -c jpeg white.tiff white.jpg.tiff

Again a JPEG compression is done internally during tiffcp operation.

But instead I want to do lossless muxing from JPEG into a TIFF container/format (and the opposite: extract JPEG bitstream from input TIFF/JPEG file). Can I do that using ffmpeg or other UNIX command line tool ? For example I can mux JPEG to M-JPEG losslessly:

% ffmpeg -framerate 30 -i input%03d.jpg -codec copy output.mjpeg

For reference, here is a typical TIFF/JPEG, how can I extract the raw JPEG bistream from it ?

% tiffinfo white.jpg.tiff
TIFF Directory at offset 0x430 (1072)
  Image Width: 256 Image Length: 256
  Bits/Sample: 8
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Rows/Strip: 256
  Planar Configuration: single image plane
  Reference Black/White:
     0:     0   255
     1:   128   255
     2:   128   255
  JPEG Tables: (574 bytes)

Read more here: Source link