To remove encryption information like PSSH boxes from DASH initialization segments and media segments, you'll need to parse and modify the MP4/ISOBMFF box structure. Here's how to approach this:
For Initialization Segments
The PSSH box is typically found in the moov box hierarchy. You'll need to:
- Parse the MP4 box structure to locate all PSSH boxes (box type 'pssh')
- Remove these boxes while maintaining the correct box hierarchy
- Update any box size fields that are affected by the removal
For Media Segments
In media segments, encryption-related boxes include:
senc (Sample Encryption) boxes
saio (Sample Auxiliary Information Offsets)
saiz (Sample Auxiliary Information Sizes)
Implementation Approaches
Using MP4Box/GPAC:
# Remove PSSH boxes
MP4Box -rem pssh input.mp4 -out output.mp4
Using ffmpeg with bento4:
# First decrypt if needed, then repackage without encryption info
mp4decrypt --key <key_id>:<key> input.mp4 decrypted.mp4
mp4fragment decrypted.mp4 fragmented.mp4
Programmatic approach (Python with pymp4):
import pymp4
def remove_encryption_boxes(input_data):
boxes = list(pymp4.parse(input_data))
# Filter out encryption-related boxes
filtered_boxes = []
for box in boxes:
if box.type not in [b'pssh', b'senc', b'saio', b'saiz']:
filtered_boxes.append(box)
# Rebuild the file
return b''.join(pymp4.build(box) for box in filtered_boxes)
Important considerations:
-
After removing encryption information, you'll need to update the trak boxes to remove references to encryption in the sinf (Protection Scheme Information) boxes
-
The stsd (Sample Description) box may contain encrypted sample entries (like 'encv' or 'enca') that should be converted back to their unencrypted equivalents ('avc1', 'mp4a', etc.)
-
Make sure to update all parent box sizes after removing child boxes
-
Some players may still expect certain box structures even for unencrypted content, so test thoroughly
Would you like me to elaborate on any specific part of this process or help with a particular implementation approach?