[FFmpeg-devel] [PATCH 1/3] lavu/pixfmt: Add Y216, Y410, and Y416 formats

Philip Langdale philipl at overt.org
Mon Aug 15 20:42:11 EEST 2022


On Mon, 15 Aug 2022 06:12:20 +0000
"Xiang, Haihao" <haihao.xiang-at-intel.com at ffmpeg.org> wrote:

> 
> Hi Philip,
> 
> May we add new formats P012, Y212 and Y412 for 12bit contents ? I
> agree with Mark's comment in 
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200619015248.21873-1-fei.w.wang@intel.com/
>  
> 
> "
> Tracking it separately does not seem fun - it looks to me like it
> would require adding a new bit depth field to AVFrame.
> 
> FFmpeg has always used pixfmt as defining both the memory layout and
> which bits are used in that (so, for example, ARGB and 0RGB are not
> the same thing), unlike most of the graphics APIs which tend to 
> define those two separately.
> "

I went through this same conversation a few years ago around the
behaviour of nvdec, which uses p016 and yuv444p16 for 12bit content.
All the same arguments were made about not introducing new pixel
formats to just indicate stream depth and how we could add a new
attribute but it would be a bunch of work, and to avoid bogging down
and doing nothing, I just had nvdec/nvenc work with P016 (and honestly,
nvidia don't even use P010 internally, it's P016 for >= 10bit) and it
was fine. On the decoder side, there's no real problem, and on the
encoder side, I think the key insight is that the encoder doesn't
encoder to the frame's pixel format depth, it encodes to the depth
_specified by the profile_. So even if you give it real 16bit frames in
P016, if you are encoding Main12, you are going to get 12bit. Same for
any future Main14. I'd argue this is the most correct way to handle it
anyway. If the default profile we guess based on format isn't right,
specify the one you actually want.

> The bit depth is known if using p012 for 12bit contents in the
> command below:
> 
> $ ffmpeg -init_hw_device vaapi=vaapi:/dev/dri/renderD128 -f lavfi -i
> yuvtestsrc -vf "format=p012,hwupload" -c:v hevc_vaapi -f null -
> 
> If using p016 for 12bit contents, how do we know the bit depth is 12
> when converting yuv444 to p016 in the command below ? 
> 
> $ ffmpeg -init_hw_device vaapi=vaapi:/dev/dri/renderD128 -f lavfi -i
> yuvtestsrc -vf "format=p016,hwupload" -c:v hevc_vaapi -f null -

That's also my answer to your command lines: Specify the profile if the
default that we guess from the format isn't what you want.

It's not the say that I don't think a bit depth field on AVFrames is a
terrible idea, but it's a huge project and not one that I'm interested
in blocking on. We'd get nothing done otherwise. I'm very comfortable
with the heuristics I've added in this patch set vs the heuristics we
had before. It'll be a while before we get 14bit and profile selection
actually becomes ambiguous.

I don't know if QSV has different constraints that make this approach
impossible but it works fine for VAAPI, and I would imagine that when
implementing Microsoft's directx interfaces you have to do something
similar as they fix the set of usable formats for you.

--phil

 


More information about the ffmpeg-devel mailing list