How to trim a video while preserving the metadata?

You can map metadata for a particular stream using the -map_metadata option with an index of the stream from which you want to copy the metadata. For example, if you want to copy metadata from only a video stream then you can use the following command

ffmpeg -i source.mp4 -map 0:v -map 0:a -map_metadata:s:v 0:s:v -c copy target.mp4

For more please visit this thread: How to trim videos with both ffmpeg and ffprobe?