Update
The problem was fixed by ffmpeg-developers. In addition, other improvements were made https://www.mail-archive.com/ffmpeg-devel@ffmpeg.org/msg83815.html.
When scaling a 10bit video using scale_cuda
filter (witch uses pixel format AV_PIX_FMT_P010LE
), the output video gets distorted.
I suppose it has something to do with the differences in processing between cuda_sdk and ffnvcodec with cuda_nvcc (the problem appears after this commit https://github.com/FFmpeg/FFmpeg/commit/2544c7ea67ca9521c5de36396bc9ac7058223742).
This repository is intended to prove that such problem exists and to show, how to solve it.
In order to reproduce the problem, you should have:
- Linux environment;
- Nvidia graphic card with cuvid/nvenc support and latest drivers installed (I tested on GTX 1080, GTX 1050 and 430.09/418.56 drivers);
- Docker installed (for building and running FFmpeg). Using docker is not mandatory, but recommended, as it simplifies the process of building;
- Nvidia docker runtime installed (if using docker).
Building the image:
docker build images -f images/Dockerfile -t ffmpeg-scale-10bit-test
I prepared a sample video with yuv420p10le pixel format samples/input.ts.
Let's try to scale it down to HD-ready:
docker run -it -v $(pwd)/samples:/samples --rm ffmpeg-scale-10bit-test ffmpeg -y -hwaccel cuvid -c:v hevc_cuvid -i /samples/input.ts -map 0:0 -c:v hevc_nvenc -vf scale_cuda=1280:720 /samples/problem.ts
After the ffmpeg process completes try playing the output file samples/problem.ts
.
You will immediately see that the picture is distorted.
To solve the problem we should not divide the input frame planes' linesize
s by 2 (1, 2) and leave them as they are.
I prepared a patch images/fix.patch. You can test the patch using a special docker-image:
docker build images -f images/Dockerfile.fixed -t ffmpeg-scale-10bit-test
If you run the commands again, the output video will be correct.