Log in

View Full Version : how to use ffmpeg to encode to mp4-avc-HDR-4k


hydra3333
10th February 2018, 05:45
OK, call me stupid.

Googled for a couple of hours, found a plethora of semi-conflicting information, and am still not much clearer on what ffmpeg commandline switches to use to convert (re-encode) a 4K HDR webm video, eg vp9.2, (and other similar samples in various formats from across the web) into

an mp4 container as avc/HDR/4k, presmably profile high10 level 5.1
an mkv container as avc/HDR/4k, presmably profile high10 level 5.1

an mp4 container as hevc/HDR/4k
an mkv container as hevc/HDR/4k
equivalent in quality to the avc

I'd prefer to use ffmpeg rather than x264 and x265 if possible.

Any example commandlines and/or link(s) would be very greatly appreciated.

So far I've seem something like this
ffmpeg_10bit.exe -i <infile.i420.bt2020nc.yuv420p10le.webm> -input-depth 10 -c:a libopus -c:v libx265 -tag:v hvc1 -crf 15 -pix_fmt yuv420p10le -x265-params "colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc" -f mp4 -y "outfile.mp4"
and this which I'm fairly sure isn't right
ffmpeg.exe -i <infile.i420.bt2020nc.yuv420p10le.webm> --input-depth 10 -c:a libopus -c:v libx264 --preset slow -crf 15 -no-open-gop -profile high10 -level:v 5.1 -level-idc 5.1 -pix_fmt yuv420p10le -colorprim bt2020 -colormatrix bt2020nc -transfer smpte-st-2084 -x264opts "" -movflags faststart -f mp4 -y "output.mp4"

Selur
10th February 2018, 10:16
at least for x265 you will have to add master-display and max-cll to the command line as parameters
"colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,10)"
and may be ':max-cll=0,0'
don't think there is an option in ffmpeg to passthrough these settings to libx265

sneaker_ger
10th February 2018, 12:04
And don't simply copy them from Selur's example. You have to read them from the source. Try MediaInfo to show the values. If that doesn't work try mkvinfo for VP9/WebM, a stream analyzer like ffprobe or Zond for HEVC.

You may need to calculate the values. They are set (stored) differently than they appear in MediaInfo:
http://x265.readthedocs.io/en/default/cli.html#cmdoption-master-display
https://matroska.org/technical/specs/index.html#Colour

an mp4 container as avc/HDR/4k, presmably profile high10 level 5.1
an mkv container as avc/HDR/4k, presmably profile high10 level 5.1
HDR in H.264, albeit possible, is uncommon. I would not use it for lack of compatibility. I think x264 does not even implement the mastering display colour volume SEI yet. (You can flag the mkv container, though.)

hydra3333
11th February 2018, 02:46
OK, thank you for the information !

I'd mistakenly thought h.264 10bit HDR was now "a thing", so I will avoid that and stick with h.265 HDR.

As you both suggest, I'll start looking into the meanings of master-display and colorprim and max-cll and read these docs

http://x265.readthedocs.io/en/defaul...master-display
https://matroska.org/technical/specs/index.html#Colour

and at the info produced by MediaInfo, mkvinfo and ffprobe.

Thank you, now I have a useful place to start, a lot better than aimless wandering :)

hydra3333
11th February 2018, 10:44
OK, ffprobe seems to show the most info.
From the ffprobe output below, these seem to be the most relevant items which can be "extracted" from an ffprobe output.
Although, I'm not sure where the 2 values for "max-cll=0,0" come from.

Further advice welcomed.

pix_fmt=yuv420p10le
color_range=tv
color_space=bt2020nc
color_transfer=smpte2084 (does this need to be transformed into "smpte-st-2084" ?)
color_primaries=bt2020
red_x=34000/50000 (discard eveything on and after the "/")
red_y=16000/50000 (discard eveything on and after the "/")
green_x=13248/50000 (discard eveything on and after the "/")
green_y=34500/50000 (discard eveything on and after the "/")
blue_x=7500/50000 (discard eveything on and after the "/")
blue_y=3000/50000 (discard eveything on and after the "/")
white_point_x=15634/50000 (discard eveything on and after the "/")
white_point_y=16450/50000 (discard eveything on and after the "/")
min_luminance=50/10000 (discard eveything on and after the "/")
max_luminance=10000000/10000 (discard eveything on and after the "/")

And then maybe plugged into ffmpeg's x265 "-x265-params" like this (not yet attempted)?
ffmpeg.exe
-input-depth 10
-pix_fmt %pix_fmt%
-i "G:\HDTV\0nvencc\vp9_2_HDR10_UHD_4K_Demo.webm"
-i input.vp9.2.webm -an
-c:v libx265 -preset slow -crf 15
-x265-params "colorprim=%color_primaries%
:transfer=%color_transfer%
:colormatrix=%color_space%
:master-display=G(%green_x%,%green_y%)B(%blue_x%,%blue_y%)R(%red_x%,%red_y%)WP(%white_point_x%,%white_point_y%)L(%max_luminance%,%min_luminance%)
:max-cll=0,0:hdr"
-profile:v main10 -level:v 5.1
-crf 18
-output-depth=10
-movflags faststart
-f mp4 -y output.mp4

Here's the ffprobe output to see if someone can point out where the "max-cll=0,0" values come from.
"C:\SOFTWARE\ffmpeg\0-homebuilt-x64\ffprobe.exe" -prefix -unit -pretty -show_streams -i "G:\HDTV\0nvencc\vp9_2_HDR10_UHD_4K_Demo.webm"

index=0
codec_name=vp9
codec_long_name=Google VP9
profile=Profile 2
codec_type=video
codec_time_base=317/19001
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=3840
height=2160
coded_width=3840
coded_height=2160
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p10le
level=-99
color_range=tv
color_space=bt2020nc
color_transfer=smpte2084
color_primaries=bt2020
chroma_location=unspecified
field_order=unknown
timecode=N/A
refs=1
id=N/A
r_frame_rate=19001/317
avg_frame_rate=19001/317
time_base=1/1000
start_pts=0
start_time=0:00:00.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng

side_data_type=Mastering display metadata
red_x=34000/50000
red_y=16000/50000
green_x=13248/50000
green_y=34500/50000
blue_x=7500/50000
blue_y=3000/50000
white_point_x=15634/50000
white_point_y=16450/50000
min_luminance=50/10000
max_luminance=10000000/10000


ffprobe version N-89991-gdd5208aaf5 Copyright (c) 2007-2018 the FFmpeg developers
built with gcc 7.3.0 (GCC)
configuration: --arch=x86_64 --target-os=mingw32
--cross-prefix=/home/u/Desktop/ffmpeg-windows-build-helpers-withOpenCL-master/sandbox/cross_compilers/mingw-w64-x86_64/bin/x86_64-w64-mingw32-
--pkg-config=pkg-config
--pkg-config-flags=--static --enable-gray --enable-version3 --disable-debug --disable-doc --disable-htmlpages
--disable-manpages --disable-podpages --disable-txtpages --disable-w32threads
--enable-nvenc --enable-cuda --enable-cuvid --enable-d3d11va --enable-libsoxr
--enable-fontconfig --enable-libass --enable-libbluray
--enable-iconv --enable-libtwolame --enable-libzvbi --enable-libcaca --enable-libmodplug
--extra-libs=-lstdc++ --extra-libs=-lpng --extra-libs=-loleaut32 --enable-libmp3lame --enable-version3
--enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enable-libspeex
--enable-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype
--enable-libopus --enable-bzlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-libvpx --enable-libilbc
--enable-libwavpack --enable-libwebp --enable-libgme --enable-dxva2 --enable-gray --enable-libopenh264 --enable-libmysofa --enable-libflite
--enable-lzma --enable-libsnappy --enable-libzimg --enable-libbs2b --enable-gmp
--enable-libfribidi --enable-cross-compile --enable-pic --extra-libs=-lpsapi
--extra-libs=-lspeexdsp --disable-schannel --extra-cflags=-DLIBTWOLAME_STATIC --extra-cflags=-DMODPLUG_STATIC --extra-cflags=-DCACA_STATIC
--enable-gpl --enable-avisynth --enable-frei0r --enable-filter=frei0r --enable-librubberband
--enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid
--enable-amf --enable-avresample --enable-libcdio --extra-cflags='-mtune=generic' --extra-cflags=-O3
--enable-static --disable-shared
--prefix=/home/u/Desktop/ffmpeg-windows-build-helpers-withOpenCL-master/sandbox/cross_compilers/mingw-w64-x86_64/x86_64-w64-mingw32
--enable-nonfree --enable-decklink --enable-libfdk-aac --enable-opencl --enable-runtime-cpudetect
--extra-libs=-lcrypt32 --extra-libs=-lshlwapi --extra-libs=-lstdc++ --extra-libs=-lass
--extra-libs=-lfontconfig --extra-libs=-lexpat --extra-libs=-lfribidi --extra-libs=-lfreetype --extra-libs=-lharfbuzz --extra-libs=-lbz2 --extra-libs=-llzma
--extra-libs=-liconv --extra-libs=-lcdio --extra-libs=-lcdio_paranoia --extra-libs=-lz
--extra-libs=-lpsapi --extra-libs=-lspeexdsp --extra-libs=-lgdi32 --extra-libs=-lwinmm
libavutil 56. 7.100 / 56. 7.100
libavcodec 58. 10.100 / 58. 10.100
libavformat 58. 9.100 / 58. 9.100
libavdevice 58. 1.100 / 58. 1.100
libavfilter 7. 11.101 / 7. 11.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
Input #0, matroska,webm, from 'G:\HDTV\0nvencc\vp9_2_HDR10_UHD_4K_Demo.webm':
Metadata:
encoder : google/video-file
Duration: 00:03:17.61, start: 0.000000, bitrate: 16593 kb/s
Stream #0:0(eng): Video: vp9 (Profile 2), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x2160, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (default)
Side data:
Mastering Display Metadata, has_primaries:1 has_luminance:1 r(0.6800,0.3200) g(0.2650,0.6900) b(0.1500 0.0600) wp(0.3127, 0.3290) min_luminance=0.005000, max_luminance=1000.000000

edit: also wondering if the profile level needs to be 5.2 given it's 4k 60fps main10 HDR, athough it looks as if 5.1 would suffice ?

Selur
11th February 2018, 10:55
Not each source has max-cll value flags set, your source probably hasn't. :)
In case it's present MediaInfo reports them as:
Maximum Content Light Level : 1000 cd/m2
Maximum Frame-Average Light Level : 400 cd/m2
not sure whether ffprobe reports these at all,...

sneaker_ger
11th February 2018, 12:58
For me it's reported directly below the other values.

side_data_type=Mastering display metadata
red_x=34000/50000
red_y=16000/50000
green_x=13250/50000
green_y=34500/50000
blue_x=7500/50000
blue_y=3000/50000
white_point_x=15635/50000
white_point_y=16450/50000
min_luminance=1/10000
max_luminance=10000000/10000


side_data_type=Content light level metadata
max_content=1000
max_average=400

Try to update to latest ffmpeg (git).

hydra3333
11th February 2018, 13:38
Try to update to latest ffmpeg (git).Thank you. ffprobe was from a build from git as of last night :)

mediainfo is the latest 17.12 and doesn't show it.
re-trying ffproble from latest git ...

edit: no, not shown anywhere
Not each source has max-cll value flags set, your source probably hasn't. :)
it must be this.

I wonder what would happen if I added ":max-cll=0,0"

sneaker_ger
11th February 2018, 13:40
Then maybe the SEI simply isn't there as Selur suspected. Try different sample.

Selur
11th February 2018, 13:52
@sneaker_get: You are right, one has to use '-show_entries side_data' wo see the max_content/average info. :)

hydra3333
11th February 2018, 14:24
it seems not to be there no matter what I try...
Ah. Another sample has it though ...

"C:\SOFTWARE\ffmpeg\0-homebuilt-x64\ffprobe.exe" -prefix -unit -show_streams -report -i "G:\HDTV\0nvencc\Shot_in_Real_HDR_Smpte_2084.webm"

index=0
codec_name=vp9
codec_long_name=Google VP9
profile=Profile 2
codec_type=video
codec_time_base=1/24
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=3840
height=2160
coded_width=3840
coded_height=2160
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p10le
level=-99
color_range=tv
color_space=bt2020nc
color_transfer=smpte2084
color_primaries=bt2020
chroma_location=unspecified
field_order=unknown
timecode=N/A
refs=1
id=N/A
r_frame_rate=24/1
avg_frame_rate=24/1
time_base=1/1000
start_pts=0
start_time=0.000000 s
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng

side_data_type=Content light level metadata
max_content=1550
max_average=520


side_data_type=Mastering display metadata
red_x=34000/50000
red_y=15998/50000
green_x=13247/50000
green_y=34498/50000
blue_x=7500/50000
blue_y=2999/50000
white_point_x=15635/50000
white_point_y=16448/50000
min_luminance=49/10000
max_luminance=15500000/10000



So ... the $64million question - what to assume and do when it's absent ?

Selur
11th February 2018, 14:40
I would probably stick with the default x265 uses (max-cll “1000,400”) or simply not set the value. ;)
--hdr can be used to ensure that max-cll and max-fall values are always signaled (even if 0,0). source: http://x265.readthedocs.io/en/default/releasenotes.html#id8

hydra3333
11th February 2018, 15:47
OK. This batch file will probably crack out the values I need and do something if I drag and drop a .webm file onto it.
@echo off
@setlocal ENABLEDELAYEDEXPANSION
@setlocal enableextensions

REM Drop a media file on this, eg a .webm file

set logfile=%~1.log
set ffprobe_inputfile=%~1.ffprobe.log
set outputmp4=%~1.h265.mp4

set nvencc_x64=C:\SOFTWARE\NVEncC\NVEncC64.exe
set ffmpeg_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\ffmpeg.exe
set ffprobe_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\ffprobe.exe
set mp4box_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\MP4Box.exe
set x264_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\x264.exe
set x265_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\x265.exe
set mediainfo_x64=c:\software\mediainfo\mediainfo.exe
set mkvinfo_x64=C:\SOFTWARE\mkvtoolnix\mkvinfo.exe
set muxer_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\muxer.exe
set remuxer_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\remuxer.exe
set rtmpdump_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\rtmpdump.exe

REM probe the file characteristics

if exist "%logfile%" del "%logfile%"
if exist "%ffprobe_inputfile%" del "%ffprobe_inputfile%"

@echo on
"%ffprobe_x64%" -prefix -unit -show_streams -report -i "%~1" > "%ffprobe_inputfile%" 2>&1
@echo off

REM get the characteristics we are interested in into DOS variables
@echo off
REM set defaults first
set vmax_average=1000"
set vmax_content=400"
set vwidth=
set vheight=
set vcoded_width=
set vcoded_height=
set vhas_b_frames=
set vsample_aspect_ratio=
set vdisplay_aspect_ratio=
set vpix_fmt=
set vlevel=
set vcolor_range=
set vcolor_space=
set vcolor_transfer=
set vcolor_primaries=
set vr_frame_rate=
set vavg_frame_rate=
set vside_data_type=
set vmax_content=
set vmax_average=
set vside_data_type=
set vred_x=
set vred_y=
set vgreen_x=
set vgreen_y=
set vblue_x=
set vblue_y=
set vwhite_point_x=
set vwhite_point_y=
set vmin_luminance=
set vmax_luminance=
@echo off
for /f "tokens=1,2 delims==" %%a in (' find "=" ^< "%ffprobe_inputfile%" ') do (
set "var="
for %%c in (%%~a) do set "var=!var!,%%~c"
set var=!var:~1!
set "val="
for %%d in (%%~b) do set "val=!val!,%%~d"
set val=!val:~1!
REM @echo on
REM echo .!var!.=.!val!.
IF "!var!" == "width" set v!var!=!val!
IF "!var!" == "height" set v!var!=!val!
IF "!var!" == "coded_width" set v!var!=!val!
IF "!var!" == "coded_height" set v!var!=!val!
IF "!var!" == "has_b_frames" set v!var!=!val!
IF "!var!" == "sample_aspect_ratio" set v!var!=!val!
IF "!var!" == "display_aspect_ratio" set v!var!=!val!
IF "!var!" == "pix_fmt" set v!var!=!val!
IF "!var!" == "level" set v!var!=!val!
IF "!var!" == "color_range" set v!var!=!val!
IF "!var!" == "color_space" set v!var!=!val!
IF "!var!" == "color_transfer" set v!var!=!val!
IF "!var!" == "color_primaries" set v!var!=!val!
IF "!var!" == "r_frame_rate" set v!var!=!val!
IF "!var!" == "avg_frame_rate" set v!var!=!val!
IF "!var!" == "max_content" set v!var!=!val!
IF "!var!" == "max_average" set v!var!=!val!
IF "!var!" == "side_data_type" set v!var!=!val!
IF "!var!" == "red_x" set v!var!=!val!
IF "!var!" == "red_y" set v!var!=!val!
IF "!var!" == "green_x" set v!var!=!val!
IF "!var!" == "green_y" set v!var!=!val!
IF "!var!" == "blue_x" set v!var!=!val!
IF "!var!" == "blue_y" set v!var!=!val!
IF "!var!" == "white_point_x" set v!var!=!val!
IF "!var!" == "white_point_y" set v!var!=!val!
IF "!var!" == "min_luminance" set v!var!=!val!
IF "!var!" == "max_luminance" set v!var!=!val!
REM @echo off
)
REM split off trailing "/" etc from some of them
for /f "tokens=1,2 delims=/" %%a in ("%vwidth%") do (set vwidth=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vheight%") do (set vheight=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcoded_width%") do (set vcoded_width=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcoded_height%") do (set vcoded_height=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vhas_b_frames%") do (set vhas_b_frames=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vsample_aspect_ratio%") do (set vsample_aspect_ratio=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vdisplay_aspect_ratio%") do (set vdisplay_aspect_ratio=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vpix_fmt%") do (set vpix_fmt=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vlevel%") do (set vlevel=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcolor_range%") do (set vcolor_range=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcolor_space%") do (set vcolor_space=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcolor_transfer%") do (set vcolor_transfer=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcolor_primaries%") do (set vcolor_primaries=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vr_frame_rate%") do (set vr_frame_rate=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vavg_frame_rate%") do (set vavg_frame_rate=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vmax_content%") do (set vmax_content=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vmax_average%") do (set vmax_average=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vside_data_type%") do (set vside_data_type=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vred_x%") do (set vred_x=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vred_y%") do (set vred_y=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vgreen_x%") do (set vgreen_x=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vgreen_y%") do (set vgreen_y=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vblue_x%") do (set vblue_x=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vblue_y%") do (set vblue_y=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vwhite_point_x%") do (set vwhite_point_x=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vwhite_point_y%") do (set vwhite_point_y=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vmin_luminance%") do (set vmin_luminance=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vmax_luminance%") do (set vmax_luminance=%%a)
REM not transforms
IF /I "%vcolor_range%" == "tv" set vcolor_range=limited
IF /I NOT "%vcolor_range%" == "limited" set vcolor_range=full
REM
echo vwidth=%vwidth%
echo vheight=%vheight%
echo vcoded_width=%vcoded_width%
echo vcoded_height=%vcoded_height%
echo vhas_b_frames=%vhas_b_frames%
echo vsample_aspect_ratio=%vsample_aspect_ratio%
echo vdisplay_aspect_ratio=%vdisplay_aspect_ratio%
echo vpix_fmt=%vpix_fmt%
echo vlevel=%vlevel%
echo vcolor_range=%vcolor_range%
echo vcolor_space=%vcolor_space%
echo vcolor_transfer=%vcolor_transfer%
echo vcolor_primaries=%vcolor_primaries%
echo vr_frame_rate=%vr_frame_rate%
echo vavg_frame_rate=%vavg_frame_rate%
echo vmax_content=%vmax_content%
echo vmax_average=%vmax_average%
echo vside_data_type=%vside_data_type%
echo vred_x=%vred_x%
echo vred_y=%vred_y%
echo vgreen_x=%vgreen_x%
echo vgreen_y=%vgreen_y%
echo vblue_x=%vblue_x%
echo vblue_y=%vblue_y%
echo vwhite_point_x=%vwhite_point_x%
echo vwhite_point_y=%vwhite_point_y%
echo vmin_luminance=%vmin_luminance%
echo vmax_luminance=%vmax_luminance%
rem

@ECHO ON

"%ffmpeg_x64%" -hide_banner -i "%~1" -an -c:v libx265 -pix_fmt "%vpix_fmt%" -preset ultrafast -x265-params "profile=main10:level-idc=5.1:crf=15:no-open-gop=1:aq-mode=1:range=%vcolor_range%:colorprim=%vcolor_primaries%:transfer=%vcolor_transfer%:colormatrix=%vcolor_space%:master-display=G(%vgreen_x%,%vgreen_y%)B(%vblue_x%,%blue_y%)R(%vred_x%,%vred_y%)WP(%vwhite_point_x%,%vwhite_point_y%)L(%vmax_luminance%,%vmin_luminance%):max-cll=%vmax_content%,%vmax_average%:hdr" -profile:v main10 -level:v 5.1 -crf 15 -movflags faststart -f mp4 -y "%outputmp4%"

"%ffprobe_x64%" -prefix -unit -show_streams -report -i "%outputmp4%" > "%outputmp4%.ffprobe.log" 2>&1

pause
exit

OK, now worth a try I guess.

PS appreciate the links.

hydra3333
13th February 2018, 14:37
Well, so much for that. ffprobe on the resulting mp4 said
pix_fmt=yuv420p10le
level=150
color_range=tv
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=unspecified
whilst the original .webm said
pix_fmt=yuv420p10le
level=-99
color_range=tv
color_space=bt2020nc
color_transfer=smpte2084
color_primaries=bt2020

I guess I'll need to look at the ffmpeg commandline to see what options go with codec libx265

sneaker_ger
13th February 2018, 18:07
Also with
-x265-params "colorprim=9:transfer=16:colormatrix=9" (etc.)
?

hydra3333
14th February 2018, 11:03
Thank you. I got a tad "brute forcey" with it and this seemed to work, transferring the input file (eg vp9.2) 4k/HDR 10-bit colour characteristics over to the output file when transcoding into h.265 ...

Its a slow as a wet whistle even with ultrafast preset :(

@echo off
@setlocal ENABLEDELAYEDEXPANSION
@setlocal enableextensions

REM Drop a media file on this, eg a .webm file

set logfile=%~1.log
set ffprobe_inputfile=%~1.ffprobe.log
set outputmp4=%~1.h265.mp4
set outputwebm=%~1.h265.webm

set nvencc_x64=C:\SOFTWARE\NVEncC\NVEncC64.exe
set ffmpeg_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\ffmpeg.exe
set ffprobe_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\ffprobe.exe
set mp4box_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\MP4Box.exe
set x264_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\x264.exe
set x265_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\x265.exe
set mediainfo_x64=c:\software\mediainfo\mediainfo.exe
set mkvinfo_x64=C:\SOFTWARE\mkvtoolnix\mkvinfo.exe
set muxer_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\muxer.exe
set remuxer_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\remuxer.exe
set rtmpdump_x64=C:\SOFTWARE\ffmpeg\0-homebuilt-x64\rtmpdump.exe

REM probe the file characteristics

if exist "%logfile%" del "%logfile%"
if exist "%ffprobe_inputfile%" del "%ffprobe_inputfile%"

@echo on
"%ffprobe_x64%" -prefix -unit -show_streams -report -i "%~1" > "%ffprobe_inputfile%" 2>&1
@echo off

REM get the characteristics we are interested in into DOS variables
@echo off
REM set defaults first
set vmax_average=1000"
set vmax_content=400"
set vwidth=
set vheight=
set vcoded_width=
set vcoded_height=
set vhas_b_frames=
set vsample_aspect_ratio=
set vdisplay_aspect_ratio=
set vpix_fmt=
set vlevel=
set vcolor_range=
set vcolor_space=
set vcolor_transfer=
set vcolor_primaries=
set vr_frame_rate=
set vavg_frame_rate=
set vside_data_type=
set vmax_content=
set vmax_average=
set vside_data_type=
set vred_x=
set vred_y=
set vgreen_x=
set vgreen_y=
set vblue_x=
set vblue_y=
set vwhite_point_x=
set vwhite_point_y=
set vmin_luminance=
set vmax_luminance=
@echo off
for /f "tokens=1,2 delims==" %%a in (' find "=" ^< "%ffprobe_inputfile%" ') do (
set "var="
for %%c in (%%~a) do set "var=!var!,%%~c"
set var=!var:~1!
set "val="
for %%d in (%%~b) do set "val=!val!,%%~d"
set val=!val:~1!
REM @echo on
REM echo .!var!.=.!val!.
IF "!var!" == "width" set v!var!=!val!
IF "!var!" == "height" set v!var!=!val!
IF "!var!" == "coded_width" set v!var!=!val!
IF "!var!" == "coded_height" set v!var!=!val!
IF "!var!" == "has_b_frames" set v!var!=!val!
IF "!var!" == "sample_aspect_ratio" set v!var!=!val!
IF "!var!" == "display_aspect_ratio" set v!var!=!val!
IF "!var!" == "pix_fmt" set v!var!=!val!
IF "!var!" == "level" set v!var!=!val!
IF "!var!" == "color_range" set v!var!=!val!
IF "!var!" == "color_space" set v!var!=!val!
IF "!var!" == "color_transfer" set v!var!=!val!
IF "!var!" == "color_primaries" set v!var!=!val!
IF "!var!" == "r_frame_rate" set v!var!=!val!
IF "!var!" == "avg_frame_rate" set v!var!=!val!
IF "!var!" == "max_content" set v!var!=!val!
IF "!var!" == "max_average" set v!var!=!val!
IF "!var!" == "side_data_type" set v!var!=!val!
IF "!var!" == "red_x" set v!var!=!val!
IF "!var!" == "red_y" set v!var!=!val!
IF "!var!" == "green_x" set v!var!=!val!
IF "!var!" == "green_y" set v!var!=!val!
IF "!var!" == "blue_x" set v!var!=!val!
IF "!var!" == "blue_y" set v!var!=!val!
IF "!var!" == "white_point_x" set v!var!=!val!
IF "!var!" == "white_point_y" set v!var!=!val!
IF "!var!" == "min_luminance" set v!var!=!val!
IF "!var!" == "max_luminance" set v!var!=!val!
REM @echo off
)
REM split off trailing "/" etc from some of them
for /f "tokens=1,2 delims=/" %%a in ("%vwidth%") do (set vwidth=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vheight%") do (set vheight=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcoded_width%") do (set vcoded_width=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcoded_height%") do (set vcoded_height=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vhas_b_frames%") do (set vhas_b_frames=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vsample_aspect_ratio%") do (set vsample_aspect_ratio=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vdisplay_aspect_ratio%") do (set vdisplay_aspect_ratio=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vpix_fmt%") do (set vpix_fmt=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vlevel%") do (set vlevel=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcolor_range%") do (set vcolor_range=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcolor_space%") do (set vcolor_space=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcolor_transfer%") do (set vcolor_transfer=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vcolor_primaries%") do (set vcolor_primaries=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vr_frame_rate%") do (set vr_frame_rate=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vavg_frame_rate%") do (set vavg_frame_rate=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vmax_content%") do (set vmax_content=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vmax_average%") do (set vmax_average=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vside_data_type%") do (set vside_data_type=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vred_x%") do (set vred_x=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vred_y%") do (set vred_y=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vgreen_x%") do (set vgreen_x=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vgreen_y%") do (set vgreen_y=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vblue_x%") do (set vblue_x=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vblue_y%") do (set vblue_y=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vwhite_point_x%") do (set vwhite_point_x=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vwhite_point_y%") do (set vwhite_point_y=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vmin_luminance%") do (set vmin_luminance=%%a)
for /f "tokens=1,2 delims=/" %%a in ("%vmax_luminance%") do (set vmax_luminance=%%a)
REM not transforms
REM IF /I "%vcolor_range%" == "tv" set vcolor_range=limited
REM IF /I NOT "%vcolor_range%" == "limited" set vcolor_range=full
REM
echo vwidth=%vwidth%
echo vheight=%vheight%
echo vcoded_width=%vcoded_width%
echo vcoded_height=%vcoded_height%
echo vhas_b_frames=%vhas_b_frames%
echo vsample_aspect_ratio=%vsample_aspect_ratio%
echo vdisplay_aspect_ratio=%vdisplay_aspect_ratio%
echo vpix_fmt=%vpix_fmt%
echo vlevel=%vlevel%
echo vcolor_range=%vcolor_range%
echo vcolor_space=%vcolor_space%
echo vcolor_transfer=%vcolor_transfer%
echo vcolor_primaries=%vcolor_primaries%
echo vr_frame_rate=%vr_frame_rate%
echo vavg_frame_rate=%vavg_frame_rate%
echo vmax_content=%vmax_content%
echo vmax_average=%vmax_average%
echo vside_data_type=%vside_data_type%
echo vred_x=%vred_x%
echo vred_y=%vred_y%
echo vgreen_x=%vgreen_x%
echo vgreen_y=%vgreen_y%
echo vblue_x=%vblue_x%
echo vblue_y=%vblue_y%
echo vwhite_point_x=%vwhite_point_x%
echo vwhite_point_y=%vwhite_point_y%
echo vmin_luminance=%vmin_luminance%
echo vmax_luminance=%vmax_luminance%
rem

@ECHO ON

set ffpreset=medium

"%ffmpeg_x64%" -hide_banner -i "%~1" -an -c:v libx265 -pix_fmt "%vpix_fmt%" -preset %ffpreset% -color_trc %vcolor_transfer% -color_primaries %vcolor_primaries% -colorspace %vcolor_space% -color_range %vcolor_range% -x265-params "profile=main10:level-idc=5.1:crf=15:no-open-gop=1:aq-mode=1:range=%vcolor_range%:colorprim=%vcolor_primaries%:transfer=%vcolor_transfer%:colormatrix=%vcolor_space%:master-display=G(%vgreen_x%,%vgreen_y%)B(%vblue_x%,%blue_y%)R(%vred_x%,%vred_y%)WP(%vwhite_point_x%,%vwhite_point_y%)L(%vmax_luminance%,%vmin_luminance%):max-cll=%vmax_content%,%vmax_average%:hdr" -profile:v main10 -level:v 5.1 -crf 15 -movflags faststart -f mp4 -y "%outputwebm%"
"%ffprobe_x64%" -prefix -unit -show_streams -report -i "%outputwebm%" > "%outputwebm%.ffprobe.log" 2>&1

"%ffmpeg_x64%" -hide_banner -i "%~1" -an -c:v libx265 -pix_fmt "%vpix_fmt%" -preset %ffpreset% -color_trc %vcolor_transfer% -color_primaries %vcolor_primaries% -colorspace %vcolor_space% -color_range %vcolor_range% -x265-params "profile=main10:level-idc=5.1:crf=15:no-open-gop=1:aq-mode=1:range=%vcolor_range%:colorprim=%vcolor_primaries%:transfer=%vcolor_transfer%:colormatrix=%vcolor_space%:master-display=G(%vgreen_x%,%vgreen_y%)B(%vblue_x%,%blue_y%)R(%vred_x%,%vred_y%)WP(%vwhite_point_x%,%vwhite_point_y%)L(%vmax_luminance%,%vmin_luminance%):max-cll=%vmax_content%,%vmax_average%:hdr" -profile:v main10 -level:v 5.1 -crf 15 -movflags faststart -f mp4 -y "%outputmp4%"
"%ffprobe_x64%" -prefix -unit -show_streams -report -i "%outputmp4%" > "%outputmp4%.ffprobe.log" 2>&1

pause
exit

hydra3333
16th February 2018, 11:40
Seeking advice about the error below piping 4k hdr from ffmpeg.exe into x265.exe (where the video characteristics are not known in advance, they are deduced from parsing output from ffprobe).

G:\HDTV\0nvencc\hdr>"C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\ffmpeg.exe" -i "G:\HDTV\0nvencc\hdr\3.Real_4K_HDR_60fps_-_Wipe_of_SDR_vs_HDR_UHD_Chromecast_Ultra.webm" -an -strict -1 -pix_fmt yuv420p10le -f yuv4mpegpipe - |
"C:\SOFTWARE\ffmpeg\0-homebuilt-x64\built_for_generic_opencl\x64_10bit\x265.exe" --input - --y4m --output "G:\HDTV\0nvencc\hdr\3.Real_4K_HDR_60fps_-_Wipe_of_SDR_vs_HDR_UHD_Chromecast_Ultra.webm.h265" --preset medium --output-depth 10 --profile main10 --level-idc 5.1 --open-gop --crf 18 --crf-min 5 --crf-max 40 --aq-mode 1 --range tv --colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --master-display "G(13247,34499)B(7500,2999)R(34000,15999)WP(15634,16449)L(40000000,99)" --max-cll="4000,300" --hdr --info --hrd 1>>"G:\HDTV\0nvencc\hdr\3.Real_4K_HDR_60fps_-_Wipe_of_SDR_vs_HDR_UHD_Chromecast_Ultra.webm.log" 2>&1
ffmpeg version N-89991-gdd5208aaf5 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (GCC)
configuration: <snip too long>
libavutil 56. 7.100 / 56. 7.100
libavcodec 58. 10.100 / 58. 10.100
libavformat 58. 9.100 / 58. 9.100
libavdevice 58. 1.100 / 58. 1.100
libavfilter 7. 11.101 / 7. 11.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
Input #0, matroska,webm, from 'G:\HDTV\0nvencc\hdr\3.Real_4K_HDR_60fps_-_Wipe_of_SDR_vs_HDR_UHD_Chromecast_Ultra.webm':
Metadata:
encoder : google
Duration: 00:02:36.06, start: 0.000000, bitrate: 16895 kb/s
Stream #0:0(eng): Video: vp9 (Profile 2), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x2160, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (default)
Side data:
Content Light Level Metadata, MaxCLL=4000, MaxFALL=300
Mastering Display Metadata, has_primaries:1 has_luminance:1 r(0.6800,0.3200) g(0.2649,0.6900) b(0.1500 0.0600) wp(0.3127, 0.3290) min_luminance=0.009900, max_luminance=4000.000000
Stream mapping:
Stream #0:0 -> #0:0 (vp9 (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
[yuv4mpegpipe @ 000001b3a4a0cf40] Warning: generating non standard YUV stream. Mjpegtools will not work.
Output #0, yuv4mpegpipe, to 'pipe:':
Metadata:
encoder : Lavf58.9.100
Stream #0:0(eng): Video: wrapped_avframe, yuv420p10le, 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 59.94 fps, 59.94 tbn, 59.94 tbc (default)
Metadata:
encoder : Lavc58.10.100 wrapped_avframe
Side data:
Content Light Level Metadata, MaxCLL=4000, MaxFALL=300
Mastering Display Metadata, has_primaries:1 has_luminance:1 r(0.6800,0.3200) g(0.2649,0.6900) b(0.1500 0.0600) wp(0.3127, 0.3290) min_luminance=0.009900, max_luminance=4000.000000
av_interleaved_write_frame(): Invalid argument
Error writing trailer of pipe:: Invalid argument
frame= 1 fps=0.0 q=-0.0 Lsize= 24300kB time=00:00:00.01 bitrate=11932275.5kbits/s speed=0.17x
video:1kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4642301.000000%
Conversion failed!

sneaker_ger
16th February 2018, 13:49
--range <full|limited> (http://x265.readthedocs.io/en/default/cli.html#cmdoption-range)

Please read the log next time.

microchip8
16th February 2018, 17:57
you have --max-cll="4000,300"

shouldn't it be --max-cll "4000,300" ? without the equal sign?

hydra3333
17th February 2018, 01:25
Yes. Thank you both. Serves me right for tinkering with 2 different tools at the same time with different commandlines :)

Grojm
27th January 2019, 15:37
The ffmpeg team admitted that not transferring the metadata is bug, they just refuse to work on this. A bug report is open for a year without any attempts to solve this:
https://trac.ffmpeg.org/ticket/7037
Sad.

nevcairiel
27th January 2019, 16:33
No one "refuses" to work on it, but most in the project donates their time for free, which means everyone works on things they are personally interested in, or have a need for in their use of ffmpeg.
Insulting the developers and demanding they work on your pet project is not going to make you any friends, or get your issue adressed any sooner.

If you want it fixed so badly, I suggest you put a bounty on it, ie. pay for someones time, instead of demanding how someone else spends their free time - after insulting them, apparently.

Or, you know, just fix it and send a patch.

Grojm
28th January 2019, 19:11
This is not a pet project - this is absolutely necessary!

"ffmpeg HDR metadata" is the among the top 4 (!) suggestions in Google if you type "ffmpeg HDR". Because everyone who wants to encode HDR will stumble across this. HDR is already in the mass market. The demand for such a bugfix is huge.

I didn't insult the developers, I just told the truth. If you think the truth is insulting, this is your problem. I only suggested that we should stop glorifying developers for just having fun. I mean you wouldn't give a skydiver credit because he had fun, and you wouldn't say he "donated" his time to skydiving. But it's still ok that people have fun, don't get me wrong. I also like to have fun. You just can't develop software with this attitude. What's necessary is that we empathize the importance of bugfixing and start to develop a culture in which fixing bugs gets you lot's of honor and fame, and people who are just dropping their cool innovative but buggy piece of code should not be given the same amount of honor.
There is even something the leadership can do about this. Look at Linus Torvalds and how he is telling people if they produce buggy code quite clearly. Every project needs someone like Linus Torvalds.
One could even build some gamification elements in this. Like every new feature submission has to be followed by one bugfix submission, otherwise you can not submit new features any more. Bugs like the present one would be fixed within weeks. The ffmpeg devs are really fast. Just look how fast cehoyos was to downplay the importance of this very serious issue. It was like one minute reaction time - on a Sunday! They have a lot of spare time but the incentives must be misaligned if this time and energy is not converted into good code. This is what I wanted to tell right from the beginning.

benwaggoner
28th January 2019, 20:45
The broader problem is that no one is using H.264 for HDR 4K. HEVC is much more efficient for that kind of encoding, and there are plenty of HDR capable devices out there that can decode 10-bit HEVC but only 8-bit H.264. The only reason I could see to encode H.264 for HDR is if targeting a specific bit of oddball hardware that requires it. But a HDR H.264 stream will not work in many places where HDR HEVC would. And even when it worked well, it would still requires >2x the bitrate for 2160p 10-bit HDR. There is no --hdr-opt for x264 like there is in x265, for example.

Grojm
28th January 2019, 21:45
H.265 ist also affected. It's independent of the codec. ffmpeg destroys any HDR related metadata. I'm interested in H.265 of course, but I just saw that H.264 users had the exact same problem.
HDR always comes with metadata telling the color profile etc. without it you can't use it effectively. To put it in other words: ffmpeg is broken for HDR. In general. That's the issue.

benwaggoner
30th January 2019, 00:14
H.265 ist also affected. It's independent of the codec. ffmpeg destroys any HDR related metadata. I'm interested in H.265 of course, but I just saw that H.264 users had the exact same problem.
HDR always comes with metadata telling the color profile etc. without it you can't use it effectively. To put it in other words: ffmpeg is broken for HDR. In general. That's the issue.
Ah. Well, THAT certainly is a bug! I presume one could re-add the metadata using x265 parameters, but a pass through would be nice.

Blue_MiSfit
31st January 2019, 02:01
also worth noting, maxcll and maxfall describe the light peak and average light levels of the mastered content.

The ST2084 metadata (i.e. master-display-parameters in x265 speak) describe the characteristics of the mastering display. For example, a 4000 nit Dolby Pulsar is sometimes used for grading content. So you would set the mastering display metadata to describe this. However, the content is most likely not graded up to 4000 nits. Content is quite frequently graded down to 1000 nits or less. THAT is what MaxCLL and MaxFALL describe.

hydra3333
27th August 2019, 05:50
Just tested and ffmpeg situation seems unchanged.
It seems even with latest nvidia 2060 Super gpu and ffmpeg build with the latest nvenc gpu encoder, nvenc based output omits the HDR metadata ... with apparently no possibility of fixing it.
Oh well.

benwaggoner
27th August 2019, 20:59
Just tested and ffmpeg situation seems unchanged.
It seems even with latest nvidia 2060 Super gpu and ffmpeg build with the latest nvenc gpu encoder, nvenc based output omits the HDR metadata ... with apparently no possibility of fixing it.
Oh well.
Piping from ffmpeg into x265 works.

hydra3333
31st August 2019, 15:15
Thank you !
However, one then loses the "massive?" benefit of gpu-speed encoding :)
I did a terrible, loose, undocumented, once-off 4k 10 bit test and thought it was near realtime in encoding fps, depending. Haven't tried x265, however suspect 4k won't be anywhere near gpu speed.

benwaggoner
3rd September 2019, 19:26
Thank you !
However, one then loses the "massive?" benefit of gpu-speed encoding :)
I did a terrible, loose, undocumented, once-off 4k 10 bit test and thought it was near realtime in encoding fps, depending. Haven't tried x265, however suspect 4k won't be anywhere near gpu speed.
x265 can itself use the intel svt libraries for rapid acceleration. But I doubt you'll get realtime 2160p in software on anything less than a monster workstation.

GPU is fast, but it has substantial quality/efficiency limitations compared to even a performance tuned software encode.

Loomes
10th September 2019, 16:50
Piping from ffmpeg into x265 works.
That's what I just tried using ffmpeg -i input.mkv -c:v libx265 -x265-params crf=20:no-sao=yes:hdr=yes -pix_fmt yuv420p10le -bsf hevc_mp4toannexb -f rawvideo output.h265 but none of the HDR metadata got taken to the transcoded videofile. Maybe I am missing something? Is there a way to extract metadata from an HDR10 file (non plus) to a json file (like hdr10plus_parser does) and import it back in while piping with ffmpeg? The HDR Info in the source file are: Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : Display P3
Mastering display luminance : min: 0.0001 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 1000 cd/m2
Maximum Frame-Average Light Level : 288 cd/m2

benwaggoner
10th September 2019, 17:19
That's what I just tried using ffmpeg -i input.mkv -c:v libx265 -x265-params crf=20:no-sao=yes:hdr=yes -pix_fmt yuv420p10le -bsf hevc_mp4toannexb -f rawvideo output.h265 but none of the HDR metadata got taken to the transcoded videofile. Maybe I am missing something? Is there a way to extract metadata from an HDR10 file (non plus) to a json file (like hdr10plus_parser does) and import it back in while piping with ffmpeg? The HDR Info in the source file are: Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : Display P3
Mastering display luminance : min: 0.0001 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 1000 cd/m2
Maximum Frame-Average Light Level : 288 cd/m2
I mean like:

ffmpeg.exe -i foo.mov -pix_fmt yuv420p10le -strict -1 -f yuv4mpegpipe - | x265.exe - --y4m --profile main10 --colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --hdr --hdr-opt --master-display "G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)" --max-cll "1005,894" -o foo.hevc

Loomes
10th September 2019, 17:25
I see, yes, I could also pass the HDR metadata like -x265-params colorprim=9:transfer=16:colormatrix=9 but thats not exactly what I meant. I am looking for a way to extract and then pass them to the transcoded file automatically, like "hdr10plus_parser.exe" does.

benwaggoner
10th September 2019, 17:49
I see, yes, I could also pass the HDR metadata like -x265-params colorprim=9:transfer=16:colormatrix=9 but thats not exactly what I meant. I am looking for a way to extract and then pass them to the transcoded file automatically, like "hdr10plus_parser.exe" does.
MediaInfo can tell you the values at least, although you might have to reformat them syntactically.

Blue_MiSfit
14th September 2019, 09:32
Just for fun it's worth mentioning that Dolby Vision has an 8 bit AVC profile with an enhancement layer :)

It's designed to be implemented on devices without a working HEVC decoder (or one that's present but just not licensed / activated).

benwaggoner
17th September 2019, 09:38
Just for fun it's worth mentioning that Dolby Vision has an 8 bit AVC profile with an enhancement layer :)

It's designed to be implemented on devices without a working HEVC decoder (or one that's present but just not licensed / activated).
Yeah, there are a bunch of legacy profiles I've not seen in real-world deployments. I played around with that one myself ~5 years ago.

Everything for current content seems to have converged on Profile 5 (non-backwards compatible 10-bit HEVC) for VOD and Profile 8.1 (HDR-10 base layer) for Live that I know of.

Krautmaster
23rd September 2019, 11:55
having the same issue for 2 years now, i can't reencode with ffmpeg as its not able to keep the HDR metadata in place.

Any how, my ffmpeg probe does not print the meta data at all, so I cant even use that massive batch posted before to do a mapping within the batch process itself.

in ffprobe i get
[STREAM]
index=0
codec_name=hevc
codec_long_name=H.265 / HEVC (High Efficiency Video Coding)
profile=Main 10
codec_type=video
codec_time_base=1001/24000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=3840
height=2160
coded_width=3840
coded_height=2160
has_b_frames=1
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p10le
level=153
color_range=tv
color_space=bt2020nc
color_transfer=smpte2084
color_primaries=bt2020
chroma_location=unspecified
field_order=unknown
timecode=N/A
refs=1
id=N/A
r_frame_rate=24000/1001
avg_frame_rate=24000/1001
time_base=1/1000
start_pts=17
start_time=0.017000 s
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A

while mediainfo tells me

Default : Yes
Forced : No
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : Display P3
Mastering display luminance : min: 0.0050 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 944 cd/m2
Maximum Frame-Average Light Level : 143 cd/m2

Edit:

Okay the -show_entries side_data switch in ffprobe does extract the data itself but it takes ages. And anyway, then a custom massive manual mapping is required to pass that data to x265. Sucks. A fix should be implemented

sneaker_ger
23rd September 2019, 13:15
You can limit the amount of frames ffprobe reads via -read_intervals.
ffprobe -read_intervals "%+#2" -show_frames -show_entries side_data "video.mkv"

Krautmaster
23rd September 2019, 13:45
thanks ! :)

Edit: Working fine now for me using ffprobe and that awesome mapping of a page before. That preserves my hdr metadata.

Loomes
8th October 2019, 00:41
I tried to get a JSON from ffprobe to get sidedata information, but it seems the generated JSON ist malformed and therefore not convenient for further processing. My command:
ffprobe -read_intervals %+#2 -select_streams v:0 -show_frames -show_entries side_data "source.mkv" -print_format json -of json > "source_sidedata.json"
The resulting JSON looks like
{
"packets_and_frames": [
{
"type": "packet",

},
{
"type": "packet",

},
{
"type": "frame",
"media_type": "audio",
"stream_index": 1,
"key_frame": 1,
"pkt_pts": 171,
"pkt_pts_time": "0.171000",
"pkt_dts": 171,
"pkt_dts_time": "0.171000",
"best_effort_timestamp": 171,
"best_effort_timestamp_time": "0.171000",
"pkt_duration": 21,
"pkt_duration_time": "0.021000",
"pkt_pos": "313258",
"pkt_size": "1522",
"sample_fmt": "fltp",
"nb_samples": 1024,
"channels": 6,
"channel_layout": "5.1"
},
[...]
Obviously the problem is the comma which is always set after the last line ""type": "packet" in the "packets_and_frames" section. ffprobe usually gives me proper JSON files but the comma problem appears when "-show_entries side_data" is used. Am I missing something or is this a bug?

Grojm
2nd March 2020, 21:57
Hi, I want you to point to this discussion: https://trac.ffmpeg.org/ticket/7037#no1
There some user called "Balling" is referencing this thread multiple times; thinks there was a fix or something for a problem posted here, he got very upset that no one mentioned this here (he is not capable to post it himself for whatever reason). Yeah, so whatever... have a look yourself: https://trac.ffmpeg.org/ticket/7037#comment:60 https://trac.ffmpeg.org/ticket/7037#comment:74

Balling
5th March 2020, 23:30
I tried to get a JSON from ffprobe to get sidedata information, but it seems the generated JSON ist malformed and therefore not convenient for further processing. My command:

This was fixed in https://trac.ffmpeg.org/ticket/8228 in https://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=2e4f86e04ca6abdf8a1829dce210ceeef46eb224
"not capable to post it himself for whatever reason" What a liar.