Yes, you can cast from the official YouTube app (or Revanced). You need to generate a code for connection in the SmartTube settings, then connect your phone through the cast menu. The option in the cast menu on the phone is called something like “Connect with code” IIRC.
There’s also a more lightweight alternative for recording tracks called OpenTracks. It can export the data in KMZ, KML, GPX or CSV format.