New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
playback issue of HEVC content with CENC cbcs encryption in AVplayer #717
Comments
@astinus-1 Can you try if we can re-pro? |
I compared cbcs result of Shaka packager against another packager. There are occasional differences in detected hevc slice header lengths. I suspect your hevc slice length parsing code has a bug. You might want to compare your hevc slice parsing results against ffmpeg. |
@avrecko Thanks for doing the comparison. Would you mind sharing one or a few slice headers that have different results? That will help us identify the problem sooner. |
@kqyang sure thing. I created a comparison file. This is from my own sample file and not the one linked in the ticket. Available here: https://gist.github.com/avrecko/404b5cff4f79f4fc82e3dc33753de637 The values in the file should be self explanatory. I suggest you include some of this in your unit tests. Happy hunting. |
@avrecko Thanks very much for your help! Can you include codec configuration record which includes SPS and PPS in the gist too? |
@kqyang Maybe you already figured it out. But if you look closely, at the arbitrarily chosen 256 bytes, the first sample is an IDR. It has aud, vps, sps, pps, 3x sei and then finally the partial slice. It should have 95 bytes of slice nal left. This is enough bytes to be sure that the slice header is complete. You can use this data to test your nal parsing, vps, sps, pps parsing and slice header parsing. There are a few more IDR frames together with non-IDR frames in the gist. You should use the vps/sps/pps from the first frame until another IDR frames comes along. |
@jingke2000 Yes, that is the plan. As for this issue, we'll try to address it this month. |
No. We have not looked into it yet. |
OK. I can also do some analysis toward it and will report back here with any of my findings. |
@jingke2000 That will be great. Thanks. We welcome pull request too! If you find out where the problem is, you are very welcomed to submit a PR to us to fix it. |
Sure. Will do. |
Gpac might not be the best reference to compare with. I've just debugged Gpac code by looking what it does with the first P frame. It creates a pair 32|x while Shaka 48|x and an in-house solution I am working on 48|x. Also looked at the FFmpeg hevc slice structure state and indeed it matches with our own.
I'll look what is going on with the rest of the frames soon. Will keep you posted. |
@avrecko Thanks! Btw, have you tested the stream generated by Gpac, does it play correctly in AVPlayer? |
@kqyang Not yet. First I want to verify that the pairs are correct. I am cross comparing the slice header parsing with FFmpeg. I'll post results soon. |
I deleted the gist with comparison with Gpac. It is useless as in my testing and comparison with openHEVC (FFmpeg with just the hevc part) they are both inaccurate (edit: Both Shaka and Gpac). Here is one difference I found when comparing Shaka output, my own hevc parser and openHEVC. edit: deleted the gist as this sample works correctly. Please verify that you respect the following in your code:
|
@avrecko Do you infer Shaka's slice header length through subsample size? That is adjusted by rounding cipher size to multiple of 16 bytes.
Yes: https://github.com/google/shaka-packager/blob/master/packager/media/codecs/h265_parser.h#L263
Yes: https://github.com/google/shaka-packager/blob/master/packager/media/codecs/h265_parser.cc#L296. |
@kqyang For the sample in gist. Shaka generated a pair P(49|X) while the in-house cbcs implementation I just finished P(48|X). I verified the hevc slice length using openHEVC for all of the samples in the sample video. For this particular sample in gist the length should be 23. I suspect that Shaka is seeing a different slice header length. Would just like to know if that is the case. Now for the fun part. I'll be playing shaka, gpac and the in-house cbcs packaged videos on some devices. |
I had an incorrect statement in my earlier comments:
This is incorrect. The subsample size is not adjusted by
Great. Keep us updated. |
@kqyang I've updated the in-house cbcs support. Now the results are a bit different. I have 5 production hevc streams as samples. In automated testing comparison between in-house cbcs and shaka. 3 streams match with the lengths. Including the sample from the gist. I played the sample from the gist successfully on Safari. Both in-house and Shaka play without visual glitches, GPac fails to play on Safari. I'll look into the difference with the other 2 streams soon. Ball parking it. The difference is a few frames per 100 frames. In one stream the differences in plain length are pretty substantial. The other stream differs in 1 byte plain length. In 3 out of 5 streams there are no differences so this is very good start. Looking forward to get to the bottom of this. |
@kqyang I have a sample made with the in-house cbcs and one with shaka. With shaka there are some visual glitches while with the in-house there is smooth playback on Safari. I've extracted the first frame where in-house and shaka differ in plain length. 40 pain bytes for Shaka vs 36 bytes for in-house. https://gist.github.com/avrecko/0ce67d5a570f5b9bb8deed7f54968d64 What is your slice header length calculation? |
@avrecko Great. Thanks for nail down the problematic slice! Here is our slice header parsing logic: Can you help us check where the problem is? |
@kqyang I found the problem. Made a fix. But will make a pull request when I track down one more difference between shaka and in-house. Basically you always use default value while it can be set explicitly in the slice header. |
@jingke2000 I looked at your sample. You have 2x vps,sps and pps per irap frame. Are you sure this makes sense? |
@kqyang There is at least 1 more problem after the fix is applied. With in-house cbcs it plays fine on Safari. Shaka has glitches. Occasionally Shaka makes a slightly larger plain size for irap frames before the fix the differences were all over the place. |
@avrecko You are right. That doesn't make sense. We changed it to single set of vps/sps/pps. I'll capture and upload a correct sample here. Thanks! |
Re avrecko/shaka-packager@a4362bb, great finding! Thanks.
@avrecko Will you be able to help us track it down as well? Appreciated! |
@kqyang I found the problem but you will have to fix it. The EOS_NUT unit is added at the start of the next frame instead at the end of the previous frame. This looks to be a generic problem unrelated to cbcs? New issue? Except for this Shaka cbcs works with the samples I tested on. |
@avrecko Great that you found the problem.
Can you be more specific? I don't think we would add NAL units to the frame. |
@kqyang I am using the word frame a bit loosely. I was not referring to slice if that is what you mean. I had in mind the whole sample. Maybe this will be more helpful:
|
|
I'll prepare a sample soon. Looking at ts file: Sample N: has AUD, Prefix SEI, Trail_R, EOS_NUT While for Shaka: |
@kqyang Regarding EOS_NUT. The problem is in the mp4 file and not in Shaka. What happened is this:
I did not expect this from ffmpeg. Now the 5 samples I have all match with Shaka. |
I see. Thanks for checking. |
Thanks @avrecko for addressing the issue. @jingke2000 You may compile Shaka Packager with 15934d6, or wait for Shaka Packager v2.4.3 release, which should happen next week. Let us know if you are still experiencing playback problems with the fix. |
@jingke2000 Out of curiosity. Could you share a few details about your transcoder? Do you use ffmpeg for the actual encoding or do you have an in-house hevc encoder? I think that the biggest complexity in transcoding is in making a good balance between low delay and good compression. Would that be accurate? As for regular VOD you can do a 2 pass and have lookahead at 50-60 frames. Not something you can afford if you want to keep the delay low? |
@avrecko |
@avrecko @kqyang Hi, I finally got chance to test the fix. However, this fix doesn't solve the bug I ran into. I still see the same video artifacts every 1 -2 seconds. For the sample: https://hls-demo-s3.s3.us-east-2.amazonaws.com/4k_cbcs_testing/PEDRO_E_INES_TRAILER_4KUHD_PRORES_04022019_UHD20_L1.mp4, function 'SkipReferencePictureListModification' is never called because the sample's 'pps->lists_modification_present_flag' is always 0. So the code changes in the function 'SkipReferencePictureListModification' have no impact on this sample's slice header parsing. @avrecko Were you able to see the difference in the slice header or parameter sets between my sample above and yours? |
@jingke2000 I looked at your sample. You still have duplicated VPS, SPS and PPS entries. I don't think you should expect 3rd party software to work well with a sample like that. I made ts from the provided file using ffmpeg copy codec. Shaka crashes on the ts file with:
Please provide sample with non duplicated VPS, SPS, PPS and I'll take a look again. |
@jingke2000 Besides the duplicated stuff. I've decided to run this sample against the in-house cbcs packager. I just need to put it in the samples directory and run some scripts. On frame 105 it crashes with input exhausted. I've dumped the offending frame to hevc file and ran it against libde265 and openHEVC. They both crash as well. Libde265: openHEVC: I suggest you first verify that your output can be successfully decoded by libde265 or openHEVC. A good test is also transcoding with ffmpeg. You can see that it reports errors in decode. @kqyang I suggest you close this. We can reopen if @jingke2000 sample passes decoding by ffmpeg/libde265 without errors but shaka produces cbcs output that doesn't play well. |
@avrecko You are right. There are two sets of VPS/SPS/PPS in front of each IDR slice in my sample content. To make it worse, I found these two sets of parameter sets are not even the same. That would certainly cause trouble. So I agree this content is invalid. @kqyang I made the statement of "this fix doesn't solve the bug I ran into" too early. Sorry about that. I'm working with the content provider to get it corrected. I'll test it again when they come back to me. I'll keep you updated. |
@avrecko Thanks for looking into it! @jingke2000 Thanks for the update. I am closing this bug. Feel free to reply if there is an update. |
Cherry-picked to v2.4.x branch for v2.4.3 release. |
Fixes #717: playback issue of HEVC content with cbcs encryption in AVplayer.
System info
Operating System: macOS High Sierra, V10.13.4
Shaka Packager Version: version v2.3.0-5bf8ad5-release
playback device: iPad with iOS 13.3.1
Issue and steps to reproduce the problem
We have 4K video conent encoded in HEVC packaged in HLS fmp4. The playback from the AVplayer in an iPad with iOS 13.3.1 is fine. However, after CENC cbcs encryption, the playback shows macroblocking issue every 1 or 2seonds. We used Shaka Packager to package or encrypt the 4K content in both cases. Here are the links to the sample conent:
Clear (playback is OK):
https://hls-demo-s3.s3.us-east-2.amazonaws.com/4k_cbcs_testing/3/video.m3u8
Encrypted (playback has macroblocking issue):
https://hls-demo-s3.s3.us-east-2.amazonaws.com/4k_cbcs_testing/4/video.m3u8
Packager Command:
"
packager-osx 'in=PEDRO_E_INES_TRAILER_4KUHD_PRORES_04022019_UHD20_L1.mp4 ,stream=video,init_segment=4k_cbcs_shaka_clr_key/video/init.mp4,segment_template=4k_cbcs_shaka_clr_key/video/$Number$.m4s,playlist_name=video.m3u8,iframe_playlist_name=iframe.m3u8' 'in=PEDRO_E_INES_TRAILER_4KUHD_PRORES_04022019_UHD20_L1.mp4,stream=audio,init_segment=4k_cbcs_shaka_clr_key/audio/init.mp4,segment_template=4k_cbcs_shaka_clr_key/audio/$Number$.m4s,playlist_name=audio.m3u8,hls_group_id=audio,hls_name=ENGLISH' --protection_scheme cbcs --enable_raw_key_encryption --keys key_id=55fa9a934d7f3cbebf99b644612598c9:key=03030303030303030303030303030303 --protection_systems FairPlay --iv CC06DA420052BA12925E96EBF98C2F4E --hls_master_playlist_output 4k_cbcs_shaka_clr_key/master.m3u8 --hls_key_uri <key_url>
"
What is the expected result?
Playback of the CENC cbcs encrypted 4K content without visual defects;
What happens instead?
Playback of the CENC cbcs encrypted 4K content shows macroblocking issue every 1~2 seconds;
Source Content
Source content can be downloaded here:
https://hls-demo-s3.s3.us-east-2.amazonaws.com/4k_cbcs_testing/PEDRO_E_INES_TRAILER_4KUHD_PRORES_04022019_UHD20_L1.mp4
The text was updated successfully, but these errors were encountered: