The
M2P has firmware that detects and corrects for magnetic errors provided certain conditions are met. Specifically, it must be powered up and not moved before launch. When it takes off and the magnetic heading changes as it leaves the region of magnetic interference while the rate gyros detect no rotation, it resets the heading to match the new magnetic heading. This post and thread illustrates the process:
Ok my apologies, I don’t own a Mavic but I know how my phantom standard and i1 reacted in these exact same locations, pix below. With a compass error. I was totally wrong for flying in these areas but I clearly remember how my drones reacted after take off. I had to walk out of the block to keep...
mavicpilots.com
But that's not what your video appears to show, since the initialized heading before takeoff seems to be correct. The magnetic error is likely due to the magnetic modulus being out of range. That functionality is explained in this post:
BACKGROUND The aircraft compass is often misunderstood, both in terms of function and purpose, but it is important to understand what the compass measures, why, and what happens to that information. At the most basic level the purpose of the compass is to measure the earth’s magnetic field in...
mavicpilots.com