How to get a lossless encoding with ffmpeg - libx265

teamblast picture teamblast · May 20, 2016 · Viewed 8.5k times · Source

I would like to convert 16 bits grayscale images in an HEVC/mkv video with the x265 encoder without loss, using ffmpeg. I use the monochrome12 profile. My first step is to convert images into yuv format:

ffmpeg -f image2 -i "C:\DATA FOLDER\images%d.png" video.yuv

And I try to convert it as a .mkv file, losslessly:

ffmpeg video.yuv video.mkv -c:v libx265 -x265-params "profile=monochrome12:crf=0:lossless=1:preset=veryslow:qp=0" 

But I get

Unrecognized option '-lossless' 
Error splitting the argument list : Option not found

When I don't write lossless=1 everything's right, but I don't manage to have a lossless video by this way.

thank you for your help.

Answer

mwfearnley picture mwfearnley · Feb 2, 2019

It works for me if I make a few changes:

ffmpeg -i video.avi -c:v libx265 \
    -x265-params "profile=monochrome12:crf=0:lossless=1:preset=veryslow:qp=0" \
    video.mkv

This is like the command you've provided, except I'm using a different input format, and prepend -i to mark it as an input file.

I also put the output filename at the end, after the output options, otherwise they are not applied, and I get this warning among the output:

Trailing options were found on the commandline.

I don't think the command you gave would cause the error you get though.

libx265 will not give an error on params it doesn't recognise, but show a warning like:

[libx265 @ 0x563e4520e740] Unknown option: lessloss.

I can reproduce your exact error by trying to add --lossless as a parameter to ffmpeg:

ffmpeg --lossless -i video.avi video.mkv

Unrecognized option '-lossless'.

Error splitting the argument list: Option not found