Skip to content
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

Encrypted segment using MPEG-CENC method is not playable #950

Open
diogoazevedos opened this issue Apr 5, 2024 · 3 comments
Open

Encrypted segment using MPEG-CENC method is not playable #950

diogoazevedos opened this issue Apr 5, 2024 · 3 comments

Comments

@diogoazevedos
Copy link

I’m trying to encrypt the attached segment using mp4encrypt using MPEG-CENC method, but the resulting segment becomes unplayable:

mp4encrypt --method MPEG-CENC \
  --key 1:4a13a4c5449b903ca558716341531799:random \
  --property 1:KID:a167ef50633c27f314f36a038ef20d6e  \
  clear/154023527127780.mp4 cenc/154023527127780.mp4

Shaka Player throws MediaError(3,,CHUNK_DEMUXER_ERROR_APPEND_FAILED: Incorrect CENC subsample size.).
Decrypting the encrypted segment using mp4decrypt and checking the integrity using FFmpeg, results into:

mp4decrypt --key a167ef50633c27f314f36a038ef20d6e:4a13a4c5449b903ca558716341531799 \
  cenc/154023527127780.mp4 clear/154023527127780.mp4

ffmpeg -v error -i clear/154023527127780.mp4 -f null -
[h264 @ 0x14263a4c0] Invalid NAL unit size (337906356 > 1).
[h264 @ 0x14263a4c0] Error splitting the input into NAL units.
[vist#0:0/h264 @ 0x142612c60] Error submitting packet to decoder: Invalid data found when processing input
[h264 @ 0x14260a400] Invalid NAL unit size (1672766743 > 1).
[h264 @ 0x14260a400] Error splitting the input into NAL units.
[vist#0:0/h264 @ 0x142612c60] Error submitting packet to decoder: Invalid data found when processing input
[h264 @ 0x1426438d0] Invalid NAL unit size (-334245472 > 1).
[h264 @ 0x1426438d0] Error splitting the input into NAL units.
[vist#0:0/h264 @ 0x142612c60] Decoding error: Invalid data found when processing input
154023527127780.mp4
@barbibulle
Copy link
Contributor

When encrypting a segment by itself, you need to pass in a reference to the unit segment, where some of the encryption parameters are stored (that info is only in the init segment and not repeated in each individual segment).

@diogoazevedos
Copy link
Author

@barbibulle Yup, the attached file above is the concat of the init and fragment.

@diogoazevedos
Copy link
Author

diogoazevedos commented Jun 5, 2024

@barbibulle the original segment is in TS, which is remuxed into MP4 using FFmpeg. During the remuxing the PTS is also adjusted so we've an homogenous timeline provider-agnostic.

The remuxing is essentially the following FFmpeg:

ffmpeg -i video-stream-4_144979815.ts -c:v copy \
  -fflags '-autobsf' \
  -movflags 'frag_custom+dash+delay_moov' \
  154023527127780.mp4

Original TS segment: video-stream-4_144979815.ts.log

It's not allowed to attach .ts files, but appending a .log did the trick.

Worth mentioning that this issue happens only when we encrypt segments coming from partners which are using Synamedia encoders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants