[FFmpeg-devel] [PATCH 2/2] ffmpeg: Use the colour properties from the input stream when doing transcode
Xiang, Haihao
haihao.xiang at intel.com
Mon May 28 10:30:12 EEST 2018
On Sat, 2018-05-26 at 17:29 +0100, Mark Thompson wrote:
> On 25/05/18 07:57, Tobias Rapp wrote:
> > On 25.05.2018 07:58, Xiang, Haihao wrote:
> > > On Thu, 2018-05-24 at 11:15 +0100, Mark Thompson wrote:
> > > >
> > > > For example:
> > > >
> > > > ffmpeg -i bt709_input.mkv -vf colorspace=bt2020 bt2020_output.mkv
> > > >
> > > > will have the output file marked as BT.709 after this patch, where
> > > > previously
> > > > it was "unspecified". (Explicitly setting -color_primaries/-color_trc/-
> > > > colorspace on the output works in both cases.)
> > >
> > > I agree with you it's not worse than before as we don't get the expected
> > > result
> > > in both cases.
> >
> > Not quite: When a file says "I don't know this property value" you have a
> > chance to lookup the value somewhere else or use a default. When it says "I
> > know the value" and gives a wrong value, you completely loose trust.
>
> Right, that is a compelling argument. I agree with you, so I definitely won't
> apply the patch in this form.
>
According the comment in avcodec.h, the color properties in AVCodecContext
should be set by user for encoding. I think ffmpeg is the user in the case
below. Where are the color properties set if we don't set the default values in
init_output_stream_encode()?
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format
vaapi -i input-with-hdr.mkv -c:v hevc_vaapi -profile:v main10 output.h265
> > So in my opinion this patch should not be applied, as it possibly makes
> > ffmpeg generate files with wrong information where it just had no
> > information before. The correct approach would be to set the encoder
> > properties from output frame data and only write a header once the encoders
> > have been initialized completely.
>
> Passing the information through libavfilter should be equivalent, but yeah.
>
In hevc_vaapi encoder, the color properties in AVCodecContext are used to
initialize sequence parameters and extradata is written when AVCodec.init() is
called, where AVFrame is unavailable.
Actually I have another patch to use the properties in AVFrame to update
sequence parameters however it will result in mismatch in sps because extradata
is written in the initialization path.
Both AVCodecContext and AVFrame have color properties, which one should be used
for encoding?
BTW I debugged ffmpeg with args set to '-i bt709_input.mkv -vf colorspace=bt2020
bt2020_output.mkv' and found the color properties have been set correctly for
input and output AVFrames when create_filtergraph() is called w/wo this patch:
(gdb) p out->color_primaries
$16 = AVCOL_PRI_BT2020
(gdb) p in->color_primaries
$17 = AVCOL_PRI_BT709
I guess color properties in AVCodecContext are used when writing .mkv,
Thanks
Haihao
More information about the ffmpeg-devel
mailing list