FFMPEG: Transcode UHD H265 to SDR H264 without color loss

4.5k Views Asked by At

I'm testing FFMPEG on my server. I'm trying to transcode H265 10-bit to H264 8-bit to support playing the video on all major web browser.

1. This is the first command:

ffmpeg -i 4K.ts -c:a aac -c:v h264 -crf 19 -preset ultrafast out.mp4

Result: Video only playable on VLC media player. Doesn't play on any browser

2. Then I tried using this command:

ffmpeg -i 4K.ts -c:a aac -c:v h264 -crf 19 -profile:v main -preset ultrafast -vf "format=yuv420p" out.mp4

Result: Video is playable everywhere but massive color loss.

3. Then I tried another command:

ffmpeg -i 4K.ts -c:a aac -c:v h264 -crf 19 -profile:v main -preset ultrafast -vf "format=yuvj420p" out.mp4

Result: Video is playable everywhere but increased color range

I don't know if I am missing anything or If I should completely disallow users to upload video with 10-bit depth. Any help will be greatly appreciated

If anyone interested in the video which I am testing on then here is the link: https://drive.google.com/uc?export=download&id=1pGsnknkoIDRPKrW-YPFS7U31J09PeM4N

I followed through many google results to come up with these command, Some of them are:

  1. FFMPEG Transcode H265 video from 10-bit to 8-bit
  2. https://blender.stackexchange.com/questions/73743/lossless-10-bit-colorspace-yuvj420p-video-output
  3. https://askubuntu.com/questions/922563/set-bit-depth-in-ffmpeg-encoding-for-hevc
1

There are 1 best solutions below

1
On BEST ANSWER

The problem is not related to the 10bit HEVC encoding, but rather the loss of HDR metadata during conversion. It's a typical case of UHD 4K video to SDR conversion.

I'm not an FFMPEG expert, so I can't provide much further detail to this answer however if someone wants to convert HDR to SDR then you can use this command:

ffmpeg -i 4K.ts -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v h264 -crf 19 -preset ultrafast output.mp4