UHD 4K encoding to .265 with x265.exe / FFMPEG
-
- Posts: 43
- Joined: Tue May 04, 2021 9:51 pm
UHD 4K encoding to .265 with x265.exe / FFMPEG
I have noticed that there is not much reference to how to use x265.exe or FFMPEG to get the .265 video stream that DVDLogic requires as the video input as you cant just simply use a mp4 or m4v as it gets rejected.
For example i have a 4k 3840x2160 at 50Fps encoded to x264 AVC and for the life of me I'm struggling using x265.exe or FFMPEG as I just get a file of below 100Mb from a input mp4 which is 22gb I have used x264.exe with no problems.
Can you share some light on the best way to get a uhd compliant bluray video file.
The below resolutions are only supported with HEVC .
3840×2160 60p 16:9
3840×2160 59.94p 16:9
3840×2160 50p 16:9
3840×2160 25p 16:9
3840×2160 24p 16:9
3840×2160 23.976p 16:9
For example i have a 4k 3840x2160 at 50Fps encoded to x264 AVC and for the life of me I'm struggling using x265.exe or FFMPEG as I just get a file of below 100Mb from a input mp4 which is 22gb I have used x264.exe with no problems.
Can you share some light on the best way to get a uhd compliant bluray video file.
The below resolutions are only supported with HEVC .
3840×2160 60p 16:9
3840×2160 59.94p 16:9
3840×2160 50p 16:9
3840×2160 25p 16:9
3840×2160 24p 16:9
3840×2160 23.976p 16:9
-
- Posts: 472
- Joined: Fri Mar 01, 2013 1:03 pm
- Contact:
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
Best regards,
Alexey Kolesnikov
Alexey Kolesnikov
-
- Posts: 43
- Joined: Tue May 04, 2021 9:51 pm
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
Hi Thanks i did use that code but FFMPEG freeze's while it is working and I notice that about 100gb gets used up too quickly from my hardrive i guess a temp file i presume, its not till i close the cmd screen that the 100gb comes back.
So not sure if its ffmpeg or the x265.exe that is causing it, I am using the latest available.
So not sure if its ffmpeg or the x265.exe that is causing it, I am using the latest available.
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
I've had good luck using "libx265" in FFMpeg rather than the separate x265.exe, make sure you have a recent FFMpeg version and try these command lines:
For SDR
ffmpeg -y -i "Source SDR.mov" -pix_fmt yuv420p10le -vcodec libx265 -preset slow -x265-params "pass=1:keyint=24:min-keyint=1:bitrate=XXXXX:vbv-bufsize=99000:vbv-maxrate=99000:level-idc=51:no-open-gop=1:uhd-bd=1:range=limited:chromaloc=2:colorprim=bt709:transfer=bt709:colormatrix=bt709" -sn "Output SDR Pass 1.265"
ffmpeg -y -i "Source SDR.mov" -pix_fmt yuv420p10le -vcodec libx265 -preset slow -x265-params "pass=2:keyint=24:min-keyint=1:bitrate=XXXXX:vbv-bufsize=99000:vbv-maxrate=99000:level-idc=51:no-open-gop=1:uhd-bd=1:range=limited:chromaloc=2:colorprim=bt709:transfer=bt709:colormatrix=bt709" -sn "Output SDR Pass 2.265"
For HDR
ffmpeg -y -i "Source HDR.mov" -pix_fmt yuv420p10le -vcodec libx265 -preset slow -x265-params "pass=1:keyint=24:min-keyint=1:bitrate=XXXXX:vbv-bufsize=99000:vbv-maxrate=99000:level-idc=51:no-open-gop=1:uhd-bd=1:range=limited:chromaloc=2:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display='G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)'" -sn "Output HDR Pass 1.265"
ffmpeg -y -i "Source HDR.mov" -pix_fmt yuv420p10le -vcodec libx265 -preset slow -x265-params "pass=2:keyint=24:min-keyint=1:bitrate=XXXXX:vbv-bufsize=99000:vbv-maxrate=99000:level-idc=51:no-open-gop=1:uhd-bd=1:range=limited:chromaloc=2:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display='G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)'" -sn "Output HDR Pass 2.265"
Make sure to replace "XXXXX" with the bitrate that you want to use, and keep it the same for both passes. Also if you're encoding a 50 fps video make sure to use "keyint=50" instead of "keyint=24"
Hope this helps!
For SDR
ffmpeg -y -i "Source SDR.mov" -pix_fmt yuv420p10le -vcodec libx265 -preset slow -x265-params "pass=1:keyint=24:min-keyint=1:bitrate=XXXXX:vbv-bufsize=99000:vbv-maxrate=99000:level-idc=51:no-open-gop=1:uhd-bd=1:range=limited:chromaloc=2:colorprim=bt709:transfer=bt709:colormatrix=bt709" -sn "Output SDR Pass 1.265"
ffmpeg -y -i "Source SDR.mov" -pix_fmt yuv420p10le -vcodec libx265 -preset slow -x265-params "pass=2:keyint=24:min-keyint=1:bitrate=XXXXX:vbv-bufsize=99000:vbv-maxrate=99000:level-idc=51:no-open-gop=1:uhd-bd=1:range=limited:chromaloc=2:colorprim=bt709:transfer=bt709:colormatrix=bt709" -sn "Output SDR Pass 2.265"
For HDR
ffmpeg -y -i "Source HDR.mov" -pix_fmt yuv420p10le -vcodec libx265 -preset slow -x265-params "pass=1:keyint=24:min-keyint=1:bitrate=XXXXX:vbv-bufsize=99000:vbv-maxrate=99000:level-idc=51:no-open-gop=1:uhd-bd=1:range=limited:chromaloc=2:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display='G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)'" -sn "Output HDR Pass 1.265"
ffmpeg -y -i "Source HDR.mov" -pix_fmt yuv420p10le -vcodec libx265 -preset slow -x265-params "pass=2:keyint=24:min-keyint=1:bitrate=XXXXX:vbv-bufsize=99000:vbv-maxrate=99000:level-idc=51:no-open-gop=1:uhd-bd=1:range=limited:chromaloc=2:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display='G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)'" -sn "Output HDR Pass 2.265"
Make sure to replace "XXXXX" with the bitrate that you want to use, and keep it the same for both passes. Also if you're encoding a 50 fps video make sure to use "keyint=50" instead of "keyint=24"
Hope this helps!
-
- Posts: 43
- Joined: Tue May 04, 2021 9:51 pm
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
Thanks mj0012
I havnt tried the code yet but I thought I'd try and compile ffmpeg my self, does libx265 come packaged in the normal ffmpeg download or do you have to get a purpose built package.
I have a ryzen 9 cpu and one of the latest nvidia graphic cards for encoding needs.
I think you can use -hwaccel to let ffmpeg deligate coding duties.
I havnt tried the code yet but I thought I'd try and compile ffmpeg my self, does libx265 come packaged in the normal ffmpeg download or do you have to get a purpose built package.
I have a ryzen 9 cpu and one of the latest nvidia graphic cards for encoding needs.
I think you can use -hwaccel to let ffmpeg deligate coding duties.
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
I haven't tried compiling it myself, but this page should give you some more information on how to do that:
https://trac.ffmpeg.org/wiki/Encode/H.265
https://trac.ffmpeg.org/wiki/Encode/H.265
-
- Posts: 43
- Joined: Tue May 04, 2021 9:51 pm
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
I looked into using my Nvida RTX3070 to do the work as its much quicker than using the cpu as in libx265.
Ive tried the below sample not sure if its completely UHD compliant at all.
This is the mediainfo from the input.mp4.
And from a sample output.265 file
Ive tried the below sample not sure if its completely UHD compliant at all.
Code: Select all
ffmpeg.exe -hwaccel_output_format cuda -i input.mp4 -profile:v main10 -pix_fmt p010le -c:v hevc_nvenc -preset slow -b:v 20M -bufsize 25M -an -color_primaries 1 -color_trc 1 -colorspace 1 output.265
Code: Select all
Video
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main@L5.1@High
Codec ID : hvc1
Codec ID/Info : High Efficiency Video Coding
Duration : 58 min 57 s
Bit rate : 59.6 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 50.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Bits/(Pixel*Frame) : 0.144
Stream size : 24.5 GiB (100%)
Language : English
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
Codec configuration box : hvcC
Code: Select all
Video
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main 10@L5.1@High
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate : 50.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 10 bits
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
-
- Posts: 43
- Joined: Tue May 04, 2021 9:51 pm
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
I've noticed I get this output on my mp4 or mov files before encoding and after using the encoder hwaccel nvdec for my ffmpeg encoding.
BDS UHD reports the following error
UHD bd constraint : file: menu.265: width and height combination incorrect. Value: 1920 x 1088
I get the same error with 4k encoded files with height of 2176.
I'd prefer to use hardware encoding as instead of taking 8 hours to encode a 1 hour video it will only take about 2.
It does seem like BDS UHD is picking up the resolution from the stored height value of 1088, this seems the only error its giving me so far.
So is there a way to correct this with a switch that is supported with hardware encoding and if I ignored the error message would I find that 4k players won't handle the video stream correctly.
Code: Select all
ffmpeg.exe -hwaccel_output_format cuda -i input.mp4 -profile:v main10 -pix_fmt p010le -c:v hevc_nvenc -preset slow - g 50 -b:v 20M -bufsize 25M -an -color_primaries 1 -color_trc 1 -colorspace 1 output.265
Code: Select all
<Width>1920</Width>
<Height>1080</Height>
<Stored_Height>1088</Stored_Height>
<Sampled_Width>1920</Sampled_Width>
<Sampled_Height>1080</Sampled_Height>
UHD bd constraint : file: menu.265: width and height combination incorrect. Value: 1920 x 1088
I get the same error with 4k encoded files with height of 2176.
Code: Select all
"Width": "3840",
"Height": "2160",
"Stored_Height": "2176",
"Sampled_Width": "3840",
"Sampled_Height": "2160",
It does seem like BDS UHD is picking up the resolution from the stored height value of 1088, this seems the only error its giving me so far.
So is there a way to correct this with a switch that is supported with hardware encoding and if I ignored the error message would I find that 4k players won't handle the video stream correctly.
-
- Posts: 43
- Joined: Tue May 04, 2021 9:51 pm
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
So after some Internet searching I found this thread here which explains it.
https://github.com/rigaya/NVEnc/issues/303
https://github.com/rigaya/NVEnc/issues/303
Unfortunately not all players can play the files like the xboxHEVC encoders will code by 32x32 block, so when you encode fullHD(1920x1080) video, it is internally padded to meet the block size and coded as 1920x1088. The decoder or the player should crop the last 8 pixels after decoding if the resolution is 1920x1080, and I think there are nothing we can do when encoding.
Re: UHD 4K encoding to .265 with x265.exe / FFMPEG
Thank you for those command lines, running them as we speak. Do you know if there is any real world difference in the resulting encode using the "libx265" and FFMpeg vs using the x265.exe?
Thanks in advance.