Log in

View Full Version : Encoding audio for h264 blu ray encoding with x264


javieracdc
12th December 2024, 16:45
I'm trying to encode a video using x264 for using blu ray compliant according with these commands:

https://web.archive.org/web/20211016213149/http://www.x264bluray.com/home/1080i-p

Which it produces out.264 raw video.

Later I extract the audio source from the original video and I mux them to Blu Ray structure with tsmuxer. However when I play the video, the audio and video got out of sync.

how can i encode the audio which allow me that the audio source match with the timepstamps of h264 video?

cubicibo
13th December 2024, 12:58
You need to tell us the framerate of the video, your command line, and also what happen if you combine the video and audio in a mkv.

I suspect your encode is flawed and the framerate in the .264 container is not a standard value, which tsMuxer is obligated to adjust. Is the framerate reported by tsMuxer the one you expect?

javieracdc
13th December 2024, 13:48
You need to tell us the framerate of the video, your command line, and also what happen if you combine the video and audio in a mkv.
The original video has variable framerates, it does not have a constant framerate, that is why I ask, because extracting the audio from original video (VFR) to a video converted to CFR, out of sync.
I suspect your encode is flawed and the framerate in the .264 container is not a standard value, which tsMuxer is obligated to adjust. Is the framerate reported by tsMuxer the one you expect?

The original video has variable framerates, it does not have a constant framerate, that is why I ask, because extracting the audio from original video (VFR) to a video converted to CFR, out of sync.

I performed some command with ffmpeg to encode the video and audio at the same time allowing the video has blu ray compliant, but i dont know if this command is enough or not:

ffmpeg -i input -c:v libx264 -preset veryslow -profile:v high -x264opts bitrate=21700:level=4.2:keyint=60:min-keyint=1:bluray-compat=1:slices=4:ref=4:open-gop=1:ref=4:vbv-maxrate=40000:vbv-bufsize=30000:weightp=0:b-pyramid=strict:cabac=1 -vf "fps=30000/1001,scale=1920:1080" -c:a ac3 -b:a 223k -ar 48000 -y output.mkv

cubicibo
13th December 2024, 21:46
H.264 level 4.2 is not Blu-ray compatible. The highest supported level is 4.1. Also, if you target 29.97 progressive, keyint must be 30, not 60.

I don't know why your audio drift, but you're not off a good start with this command.

microchip8
13th December 2024, 22:30
-b:a should be 224k, not 223k.

Emulgator
14th December 2024, 19:31
https://forum.doom9.org/showthread.php?p=2011406#post2011406
If it is about the same source, then she same answers from there apply.
If you force 30000/1001 on a VFR from 59.465 to 12 000.000 fps source, then you order the result to be out of sync.

javieracdc
15th December 2024, 00:44
H.264 level 4.2 is not Blu-ray compatible. The highest supported level is 4.1. Also, if you target 29.97 progressive, keyint must be 30, not 60.

I don't know why your audio drift, but you're not off a good start with this command.

Thanks for aclaration

I was testing with framerate 59.940 and profile 4.2 and burned to a blu ray disk and in a Samsung BD-F5100 player it worked without problems. I also tested it with Cyber power DVD and PlayerFab and both played without issues.

I think this should extend the capabilities of the current blu ray standards to improve the video quality a bit more.

cubicibo
16th December 2024, 08:48
Blu-ray Disc players manufacturers are free to support more than what the Blu-ray format requires. This includes HFR, AVC levels beyond 4.1 as well as other codecs and containers. Your disc will certainly not play appropriately in numerous commercial players, especially ancient ones.

In any case, a level 4.2 encode with bluray-compat=1 and slices=4 is nearly equal to a level 4.1 encode. You are simply lucky your player supports HFR, the manual even claims the opposite and specify a maximum framerate of 29.97. The truth is, these BD-only 2013+ players use SoCs with 3D capabilities disabled. However 3DBD SoCs have AVC (MVC) decoders that must support 59.94p, hence a rather widespread support.

javieracdc
17th December 2024, 21:00
Blu-ray Disc players manufacturers are free to support more than what the Blu-ray format requires. This includes HFR, AVC levels beyond 4.1 as well as other codecs and containers. Your disc will certainly not play appropriately in numerous commercial players, especially ancient ones.

In any case, a level 4.2 encode with bluray-compat=1 and slices=4 is nearly equal to a level 4.1 encode. You are simply lucky your player supports HFR, the manual even claims the opposite and specify a maximum framerate of 29.97. The truth is, these BD-only 2013+ players use SoCs with 3D capabilities disabled. However 3DBD SoCs have AVC (MVC) decoders that must support 59.94p, hence a rather widespread support.

Thanks for aclaration! :)