To trim a video with ffmpeg without re-encoding (and affecting quality), use the this snippet:
ffmpeg -i in-file.mp4 -t 00:00:05 -c copy out-file.mp4
The -c copy
flag will copy data without re-encoding.
See this Stack Overflow post for other variations, including re-encoding. Also, see the official documentation.