Skip to content

Instantly share code, notes, and snippets.

@turikhay
Last active April 29, 2023 20:54
Show Gist options
  • Save turikhay/1f100392d783040222372622e77f0f58 to your computer and use it in GitHub Desktop.
Save turikhay/1f100392d783040222372622e77f0f58 to your computer and use it in GitHub Desktop.
ffmpeg filter to convert PS5 HDR recording to SDR video

tl;dr

-vf zscale=t=linear,tonemap=tonemap=clip:param=0.3,zscale=t=bt709:m=bt709:p=bt709:r=tv,format=yuv420p,eq=contrast=1.1:saturation=1.1

why

  1. Copying a video from PS5 to a thumb drive
  2. Copying a video from a thumb drive to PC
  3. Encoding it with ffmpeg

... is still way faster than waiting for Sony's cloud.

comparison

PS App Capture tonemap=clip + eq (by me) tonemap=hable (by BadgerOrion)

You can download reference videos for manual comparison (for example with video-compare)

example

$ ffmpeg -i Fortnite_20230417203611.webm \
  -vf zscale=t=linear,tonemap=tonemap=clip:param=0.3,zscale=t=bt709:m=bt709:p=bt709:r=tv,format=yuv420p,eq=contrast=1.1:saturation=1.1 \
  -c:v libx264 \
  -preset slow \
  -c:a aac \
  -b:a 128k \
  -movflags +faststart \
  Fortnite_20230417203611.mp4

explanation

  • zscale=t=linear because tonemapping only works with a linear light
  • tonemap=tonemap=clip:param=0.3 removes extra light data while preserving original colors
  • zscale=t=bt709:m=bt709:p=bt709:r=tv converts color parameters to those used in SDR videos
  • eq=contrast=1.1:saturation=1.1 you can actually remove these; without them the comparison above would look slightly off

hint: for the best results try different parameters in clip:param=0.3 (affecting overall brightness) and eq=contrast=1.1:saturation=1.1.

bonus

For some reason, PS5 writes videos with weird SAR and extra vertical pixels:

Input #0, matroska,webm, from 'Fortnite_20230412230147.webm':
...
  Stream #0:0: Video: vp9 ..., 1920x1088, SAR 136:135 DAR 16:9, ...
...

It's not a problem if the video player supports non-square pixels.

If it doesn't, you can crop the video: setsar=sar=1/1,crop=y=-8:h=1080

Or rescale: scale=1920:1080

Example:

$ ffmpeg -i Fortnite_20230417203611.webm -vf zscale=t=linear,...,setsar=sar=1/1,crop=y=-8:h=1080 -c:v libx264 ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment