HLS format video is perfectly fine for offline viewing. If that's all you need I'd research playing a local HLS manifest with Android's MediaPlayer or ExoPlayer.
If you absolutely need a .mp4:
Write your own Muxer that internally writes each packet to 2 muxers.
Convert the HLS stream into an MP4 on-demand when the user requests to "export" it. See this StackOverflow post related to re-encoding or muxing videos with FFmpeg.
Would it be possible to generate HLS format for live streaming and MP4 streaming for archival on phone simulaneously?
My use case is to generate HLS format for live streaming and using the MP4 on phone for offline viewing (in case use opts to)