How to get a lossless encoding with ffmpeg - libx265
Asked Answered
R

1

8

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.

Redwood answered 20/5, 2016 at 11:0 Comment(0)
S
6

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.

Note that ffmpeg parameters only use one dash. I can reproduce your exact error by trying to add --lossless (with two dashes) as a parameter to ffmpeg:

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

Unrecognized option '-lossless'.

Error splitting the argument list: Option not found

Sultana answered 2/2, 2019 at 21:47 Comment(3)
The command formatted like this works fine for me, thank you! Note however that qp=0 and crf=0 can be omitted, since according to x265 docs, lossless implies qp=4 ("In HEVC, only QP=4 is truly lossless quantization, and thus when encoding losslesly x265 uses QP=4 internally in its RDO decisions."), and rate control is disabled as well.Peal
This is not the same qp. Also for libx264 wrapper of ffmpeg -qp 0 is really lossless not crf 0.Melesa
Why are all of those extra parameters needed? Here's how I typically do a lossless-encode to H265: ``` ffmpeg -i Nexigo-Iris-Mode-Change.mp4 -c:v libx265 -x265-params lossless=1 Nexigo-Iris-Mode-Change-H265.mp4 ``` The only parameter I pass is lossless=1. This is exactly what the documentation says to do: trac.ffmpeg.org/wiki/Encode/H.265Embrue

© 2022 - 2024 — McMap. All rights reserved.