Overview¶
We discuss here how to customize ISOBMFF files using box patches. Please first check the XML Box Patch syntax before reading.
Warning: the box patch does not allow modifications of fields of a box, it can only be used to insert new boxes or remove existing boxes. Box modifications must be done through available options of MP4Box or the ISOBMF multiplexer.
Applying a box patch to a file¶
You can use MP4Box to patch boxes of an existing file.
Warning: the method in this section only works for non fragmented files, see next section for alternate ways.
Injecting a box¶
Let's take the following patch:
<?xml version="1.0" encoding="UTF-8" />
<GPACBOXES>
<Box path="trak.tkhd+">
<BS fcc="GPAC"/>
<BS value="2" bits="32"/>
<BS value="1" bits="32"/>
</Box>
</GPACBOXES>
This patch describes insertion of a box after a track header box, with a 4CC value of GPAC
and a payload of 0x0000000200000001
.
This will inject the new box after the track header of the first track in the file.
This will inject the new box after the track header of the track with ID 4.
Removing a box¶
Let's take the following patch:
This patch describes removal of a box with a 4CC value GPAC
located in the trak
box.
This will remove the new box if present in the track header of the first track in the file.
This will remove the new box if present in the track header of the track with ID 4.
Injecting a box patch in your workflow¶
You may also want to customize your ISOBMFF files while they are being produced in a filter chain.
This can be done by specifying the -boxpatch option to the ISOBMFF multiplexer:
This can also be done on a per-PID basis; this is typically used to inject different boxes for different media types:
This will obviously also work in DASH mode:
You can also set globally the -boxpatch option to use with MP4Box dashing:
or when fragmenting a file with MP4Box: