shaka-project / shaka-packager

A media packaging and development framework for VOD and Live DASH and HLS applications, supporting Common Encryption for Widevine and other DRM Systems.
https://shaka-project.github.io/shaka-packager/
Other
1.9k stars 496 forks source link

Failure with multiple slices per access unit (HEVC from Teradek) #1363

Open Brainiarc7 opened 3 months ago

Brainiarc7 commented 3 months ago

System info

Operating System: Ubuntu 22.04LTS Shaka Packager Version: git tip master

Issue and steps to reproduce the problem:

Packaging any UDP input from a Teradek encoder errors out with:

W0306 16:11:05.555587       7 es_parser_h26x.cc:272] Failure while parsing Mpeg2TS: EmitFrame(current_access_unit_position_, next_access_unit_position_ - current_access_unit_position_, current_video_slice_info_.is_key_frame, current_video_slice_info_.pps_id)
W0306 16:11:05.555622       7 es_parser_h26x.cc:255] Failure while parsing Mpeg2TS: EmitCurrentAccessUnit()
E0306 16:11:05.555645       7 mp2t_media_parser.cc:122] Parsing failed for pid = 100, type=3
W0306 16:11:05.555807       7 mp2t_media_parser.cc:246] Failure while parsing Mpeg2TS: it->second->PushTsPacket(*ts_packet)

If I re-encode the input stream on the fly via ffmpeg, shaka-packager works without a problem. Softvelum's Nimble streamer is also able to package this content on the fly without transcoding, only Shaka, for some reason, rejects it.

I cannot share the stream specifics here as it's copy-righted.

Any pointers?

cosmin commented 3 months ago

I believe there is a problem with parsing HEVC with slices in TS, at least some hardware encoders. I think I've seen something similar previously using Nvidia encoded HEVC with slices turned on. From what I recall repackaging the input as fMP4 didn't have an issue so there was something specific in the interaction of TS + HEVC with slices. Turning off slices in the encoder by using a different preset also didn't have any issues. But I never had a chance to dig into it beyond that.

A file to reproduce the problem would really help though.

Brainiarc7 commented 3 months ago

I'll request for permission on the streams sample, thank you.

On Thu, 7 Mar 2024, 20:04 Cosmin Stejerean, @.***> wrote:

I believe there is a problem with parsing HEVC with slices in TS, at least some hardware encoders. I think I've seen something similar previously using Nvidia encoded HEVC with slices turned on. From what I recall repackaging the input as fMP4 didn't have an issue so there was something specific in the interaction of TS + HEVC with slices. Turning off slices in the encoder by using a different preset also didn't have any issues. But I never had a chance to dig into it beyond that.

A file to reproduce the problem would really help though.

— Reply to this email directly, view it on GitHub https://github.com/shaka-project/shaka-packager/issues/1363#issuecomment-1984016747, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR7NB56BIZYWHQU6WHIOBLYXCM3DAVCNFSM6AAAAABELBWXQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBUGAYTMNZUG4 . You are receiving this because you authored the thread.Message ID: @.***>

Brainiarc7 commented 3 months ago

See the linked sample, @cosmin

Brainiarc7 commented 3 months ago

Confirm you have access to the media sample.

cosmin commented 3 months ago

@Brainiarc7 unfortunately I was traveling last week with minimal connectivity and I was not able to download the file. I tried a couple of times but it eventually timed out before the download completed (as the file was a few hundred MB). I'm back to proper internet but the download link has expired. Could you please re-share it?

Brainiarc7 commented 3 months ago

Here goes, @cosmin . Thank you!

cosmin commented 3 months ago

@Brainiarc7 thank you, I was able to download the sample and can repro the problem locally. I'll follow up once I determine what the problem is.

cosmin commented 3 months ago

Ok, doing a little digging through the debugger I believe the problem lies within EsParserH26x::EmitFrame

It pops the current_timing_desc from timing_desc_list_ which works for the single slice per frame case, however when multiple slices are being used the TimingDesc has already been consumed it ends up returning false in the

  if (current_timing_desc.pts == kNoTimestamp)
    return false;

which then results in the errors seen

es_parser_h26x.cc:276] Failure while parsing Mpeg2TS: EmitFrame(current_access_unit_position_, next_access_unit_position_ - current_access_unit_position_, current_video_slice_info_.is_key_frame, current_video_slice_info_.pps_id)
es_parser_h26x.cc:255] Failure while parsing Mpeg2TS: EmitCurrentAccessUnit()
cosmin commented 3 months ago

I believe this might require some structural changes to es_parser_h26x.cc to handle the case of multiple slices per access unit before calling EmitFrame.