justdan96 / tsMuxer

tsMuxer is a transport stream muxer for remuxing/muxing elementary streams, EVO/VOB/MPG, MKV/MKA, MP4/MOV, TS, M2TS to TS to M2TS. Supported video codecs H.264/AVC, H.265/HEVC, VC-1, MPEG2. Supported audio codecs AAC, AC3 / E-AC3(DD+), DTS/ DTS-HD.
Apache License 2.0
853 stars 144 forks source link

[Bug] BD Transport stream bitrate is not limited #141

Open jcdr428 opened 4 years ago

jcdr428 commented 4 years ago

As per BD-Rom Part 3 Standards, the maximum reading rate of the BDAV MPEG-2 Transport Stream is 48Mbps for HD, 109 mbps for default UHD (cf. http://www.hughsnews.ca/faqs/authoritative-blu-ray-disc-bd-faq/8-recording-and-reading-speed)

This means that the minimum timegap between BD M2TS packets Arrival Time Stamps should be 846 for HD, 373 for UHD (base on PCR 27 Mhz). When the overall streams bitrate goes above this reading rate, the TS "smoothing buffer" absorbs the overflow.

tsMuxer does not limit the ATS timegap between packets to 846/373 for BD.

jcdr428 commented 4 years ago

The problem is if you try to introduce those limits in TSMuxer::processM2TSPCR, then the timegap between two PCR packets can become >100ms as tsMuxer puts the PCR packets at every second DTS change (i.e. at the end of second AV frames):

Standard situation for fps 23.976: PCR packet @ 0ms AV Frames packets 41.7ms AV Frames packets 41.7ms PCR packet @83.4ms

Possible situation where UHD bitrate increases to 130mbps over two frames: PCR packet @ 0ms AV Frames packets 51.6ms AV Frames packets 51.6ms PCR packet @ 103.2ms This creates a "PCR discontinuity error" on the player. PCR < 100ms should be checked at every packet writing, not at every AV frame writing. Edit: this would also allow to have less PCR packets in the stream, i.e. a slightly smaller M2TS file.

FilipeAmadeuO commented 4 years ago

@jcdr428 Have you tested FW or RW on Dolby Vision M2ts rebuilded files ? Because i have shutter image when the bitrate is high or higher speed FW/RW. Can this issue explain the problem ?

jcdr428 commented 4 years ago

@FilipeAmadeuO yes this issue and issue #108 might explain the image stutter on a standalone player.