19

I am trying to find the most suitable lossless video format for 1280x720 25fps video. The video has 4 minutes. Sound will be 320 kbps mp3, that is not a big deal. Ideal conditions:

  • Lossless (can be perceptionaly lossless)
  • Container + codec can be played on most platforms
  • Container + codec can be played on modern DVD players (supporting other formats than DVD)
  • Size is less than 700 MB

Is that even possible? Have been struggling three days already, without any satisfying results, even getting 12 GB files (seems a lot - 3 GB/minute).

Indrek
  • 24,874
mrkva
  • 291

3 Answers3

34

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.

evilsoup
  • 14,056
5

These days I like webm:

ffmpeg -i input.avi -c:v libvpx-vp9 -lossless 1 output.webm

To convert faster, with multi-core processors, I've read it is recommended to use one less thread than you have of real cores. So, with an 8 core you could specify 7 threads like this:

ffmpeg -i input.avi -c:v libvpx-vp9 -threads 7 -lossless 1 output.webm
LonnieBest
  • 1,816
0

CONTAINER

to have full compatibility with DVD-players, you'll need to use MPEG-2 format, container, restrictions, codecs. I guess, "modern players" means "mp4" compatibility, which is basically and mostly a mp4-file player - H.264, MPEG-4, AVC => libx264
read more: https://de.wikipedia.org/wiki/H.264

VIDEO

Have a look at https://trac.ffmpeg.org/wiki/Encode/H.264, especially the part where it is about "profile" and "level", for compatibility
Using -profile:v high -level 4.0 should do it

AUDIO

Avoid re-encoding audio-tracks with lossy codecs - any mp3 format is lossy, even 320kbps.
Use -c:a copy instead.

So far, it did a pretty good job for me. no sync problems.
Audio streams are not bound to keyframes. Accurate cuts are possible.
If your audio-track is recorded at 44kHz sampling-rate, use max. 256kbps

Use lossy codecs only for the final encode of your video, if you need to fit certain prerequisites.

I've heard of some audio-sync issues, but it looks like the main issue there was, it was protected material(!).

Finally

I'd prefer something like this:
ffmpeg -i input -c:v libx264 -crf 5 -preset faster -profile:v high -level 4.0 -c:a copy output.mp4

d'oh
  • 11