The best actual, mathematically lossless format I know of is huffyuv, but that will produce hilariously huge files, and wouldn't be compatible with much. For the record, ffmpeg can do it with:
ffmpeg -i input -c:v huffyuv -c:a libmp3lame -b:a 320k output.avi
X264, the open-source h.264 encoder, has a lossless mode. This can go inside an MP4 container, and should be compatible with most hardware made in the last few years. The first command will give a fast encode speed, but large file; the second command will take a lot longer, but the file should be about half the size of the fast-encoded one (it will still be pretty big though):
ffmpeg -i input -c:v libx264 -crf 0 -preset ultrafast -c:a libmp3lame -b:a 320k output.mp4
ffmpeg -i input -c:v libx264 -crf 0 -preset veryslow -c:a libmp3lame -b:a 320k output.mp4
If that doesn't give you a small enough file, a crf of 18 is generally considered 'visually lossless':
ffmpeg -i input -c:v libx264 -crf 18 -preset veryfast -c:a libmp3lame -b:a 320k output.mp4
I generally recommend the veryfast preset for encoding with x264, in my experience it offers the best speed/size tradeoff (there's a big dropoff in file size between superfast and veryfast, any slower than that and it's more incremental). General advice is to use the slowest preset you can handle, the presets are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow.
See here for a more in-depth guide to x264 encoding.