axiomatic-systems / Bento4

Full-featured MP4 format, MPEG DASH, HLS, CMAF SDK and tools
http://www.bento4.com
2k stars 482 forks source link

Append new segment to existing mp4dash output #809

Closed finassaf closed 1 year ago

finassaf commented 1 year ago

Hi,

I'm looking for a way to add new segment to mp4dash encrypted (PlayReady) output without re-generating everything from scratch. My approach was to use mp4encrypt with the same key used in mp4dash and then to update the mediaPresentationDuration field in stream.mpd but it does not work - the player detects the new video length but fails to play the last segment and just skips it. The new segment I'm trying to append is the same size as the ones in the original encrypted video.

My steps are:

  1. mp4dash.bat --encryption-key=09e367028f33436ca5dd60ffe6671e70:b42ca3172ee4e69bf51848a59db9cd13 --playready-header=LA_URL:http://playready.directtaps.net/pr/svc/rightsmanager.asmx video_clear.mp4

  2. mp4encrypt.exe --method MPEG-CENC --key 1:09e367028f33436ca5dd60ffe6671e70:b42ca3172ee4e69bf51848a59db9cd13 --fragments-info init-enc.mp4 seg-xyz-clear.m4s seg-xyz-enc.m4s

What is the correct way of doing this? any help appreciated.

YannickFuereder commented 1 year ago

i dont think thats possible

when the browser decrypts a video it needs init.mp4 and any seg.mp4 the init.mp4 holds all important information like video length etc if the browser tries to decrypt a segment that is not compatible with the init.mp4 it fails

finassaf commented 1 year ago

Eventually I was able to make it work. There were two issues with my approach:

  1. mp4encrypt.exe --fragments-info init-enc.mp4 replaced with mp4encrypt.exe --fragments-info init.mp4 (no need to use the encrypted init section)
  2. Added to mp4encrypt the argument --pssh xxxxxxxxxxxxxxxxx:pssh_filename with the original pssh file. I had to modify mp4dash so it won't be deleted