# Play Motion JPEG 2000 .mj2 lossless video

Matlab can create lossless videos from image stacks or figure series by either:

- Save PNG image stack, then convert PNG stack to lossless video. This method also works for GNU Octave.
- Save from Matlab directly as lossless JPEG2000 .jp2 video (as described below)–VideoWriter not available for GNU Octave.

This example saves lossless MJPEG2000 .mj2 video plots directly from Matlab VideoWriter.

```
v = VideoWriter('test.mj2', 'Motion JPEG 2000');
v.LosslessCompression = true;
v.FrameRate = 5; % arbitrary
open(v)
f=figure;
pause(0.2) % let plot wake up
for i=1:.05:3;
line(0:.01:1,(0:.01:1).^i) % just an example
im = getframe(f);
writeVideo(v,im)
end
close(v)
```

Play Motion JPEG 2000 .mj2 with FFmpeg from the command line (outside of Matlab):

`ffplay movie.mj2`

## Notes

- Motion JPEG 2000 is the only lossless compressed format available from Matlab.
- mmread.m file enables more Matlab video I/O by using FFmpeg and AVbin via the included compiled
`FFGrab.mex`

file.