[Bf-blender-cvs] [0ea0ccc4ffd] master: FFmpeg: Fix H264 lossless render not lossless
Richard Antalik
noreply at git.blender.org
Wed Jun 2 21:43:13 CEST 2021
Commit: 0ea0ccc4ffd573739aeb9e67e83dbfb3604887c7
Author: Richard Antalik
Date: Wed Jun 2 21:24:09 2021 +0200
Branches: master
https://developer.blender.org/rB0ea0ccc4ffd573739aeb9e67e83dbfb3604887c7
FFmpeg: Fix H264 lossless render not lossless
While encoder parameters for lossless encoding are set correctly,
output is not lossless due to pixel format being set to
`AV_PIX_FMT_YUV420P` which is inherently lossy due to chroma subsampling.
This was reported in T61569 and was merged to T57397, but there were
2 bugs - one for encoding and one for decoding.
Set pixel format to `AV_PIX_FMT_YUV444P` when rendering lossless H264
files. This format isn't available in `codec->pix_fmts[0]` and it looks,
that it has to be hard-coded.
Reviewed By: sergey
Differential Revision: D11458
===================================================================
M source/blender/blenkernel/intern/writeffmpeg.c
===================================================================
diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c
index 60c216a8401..218552b0e74 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -729,6 +729,12 @@ static AVStream *alloc_video_stream(FFMpegContext *context,
}
}
+ /* Use 4:4:4 instead of 4:2:0 pixel format for lossless rendering. */
+ if ((codec_id == AV_CODEC_ID_H264 || codec_id == AV_CODEC_ID_VP9) &&
+ context->ffmpeg_crf == 0) {
+ c->pix_fmt = AV_PIX_FMT_YUV444P;
+ }
+
if (codec_id == AV_CODEC_ID_PNG) {
if (rd->im_format.planes == R_IMF_PLANES_RGBA) {
c->pix_fmt = AV_PIX_FMT_RGBA;
More information about the Bf-blender-cvs
mailing list