Converting iPhone 12 HDR Videos to SDR with FFMpeg

In a previous post, I talked about how to view HDR (High Dynamic Range) videos from the iPhone 12 on my OLED TV. However, sometimes I like to take that HDR video and converted into SDR (Standard Dynamic Range) videos for posting or distribution.

During the course of experimenting with FFMpeg, as the primary tool for this purpose, I found out that it is not always necessary to convert the video depending on where you are going to use the video. For example, uploading the raw HDR footage from the iPhone 12 to YouTube works just fine. However posting HDR video footage to Instagram currently yields a very washed out result.

I personally prefer to store all my raw footage in its high resolution 4K HDR goodness. However, I also keep a rendered down SDR version for practical use. How does one get an SDR video from an HDR source? This is what FFMpeg is for.

All the command line instructions below have been tested on the macOS, and it is assumed that you already have brew installed.

You will need to install a version of FFMpeg that has the zscale filter. If you have a previous version installed without this filter, then you will have to uninstall it first.

brew uninstall --ignore-dependencies ffmpeg

And then we install the version with the filter from the homebrew-ffmpeg tap.

brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac --with-libbluray --with-libbs2b --with-libcaca --with-libgsm --with-libmodplug --with-librsvg --with-libsoxr --with-libssh --with-libvidstab --with-libvmaf --with-libxml2 --with-opencore-amr --with-openh264 --with-openjpeg --with-openssl --with-openssl@1.1 --with-rav1e --with-rtmpdump --with-rubberband --with-speex --with-srt --with-tesseract --with-two-lame --with-wavpack --with-webp --with-xvid --with-zeromq --with-zimg

I recorded a sample video from my iPhone 12 Pro, below is the raw footage.

The included videos in this article are all HEVC encoded. If your browser does not support this encoding, then you will not be able to play the videos. Safari has no issues. If you have Windows 10, then you can install an extension. How the videos are displayed also depend on the quality and capability of your monitor.

Raw footage from iPhone 12 (4K HDR 60fps) – 92M in size

If you just perform a simple conversion, you will get the washed up version:

ffmpeg -y -i -map v:0 -map 0:a -c:v hevc -preset veryfast -tag:v hvc1 -c:a copy sdr_washed_out.mp4
Simple conversion without filters gets a bland result – 5.8M in size

The HDR colours have to be appropriately mapped using some filter trickery with FFMpeg. I found these filter settings about two years ago when trying to convert HDR videos from YouTube in the BT2020 space to BT709. Below is the set of filters used:

ffmpeg -y -i -filter_complex "[0:v]zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p[v]" -map "[v]" -map 0:a -c:v hevc -preset veryfast -tag:v hvc1 -c:a copy sdr.mp4
SDR result with filter – 5.6M in size

As you can see the SDR version with filter is a lot closer to the original one.

These FFMpeg conversions require a lot of CPU horse power, so beware that they will take a long time. Let me know if there is a better way, as I’m always open to optimize this workflow.

Leave a Reply

Your email address will not be published. Required fields are marked *