Avidemux is the perfect tool for this. It's also free, open source and available for Windows, macOS and Linux. And is quite user-friendly compared to other similar softwares.
HAVC (H.264) and HHEVC (H.265) encoded videos have certain complete frames (keyframes) that are called I-frames or Intra Frames.
To ensure that you don't have to re-encode a video when you delete some some portions of it, just make sure that you select and delete the portion of video between two I-frames. In Avidemux, after opening the video:
(1) Ensure the output is lossless (without rencoding) by selecting Copy
in the drop-down menu under 'Video Output' and 'Audio Output' (on the left-hand sidebar).
(2) Then select (or delete) part of the videos between keyframes. Avidemux makes finding keyframes or I-Frames very easy - just open the video in it, and use the UP or DOWN arrow keys to move between keyframes. To select a portion of video between keyframes, use the UP and DOWN arrow keys on your keyboard to find the first keyframe of the video portion, and click the [A
button on AviDemux. Then use the UP and DOWN arrow keys to again move to the final key frame of the video portion, and click the ][B
button on Avidemux. This will select the portion of video between the 2 keyframes.
(3) You can now either delete this portion (and then save the rest of the video) or click save to just extract and save this selected portion of the video. NoIn both cases, if you have made sure to selected between the keyframes, no re-encoding will be done or Avidemux will warn you that you haven't selected between keyframes.
More information on how to cut or extract videos on Avidemux can be read here - Simple cutting on Avidemux.
Another free and opensource software that is capable of doing lossless video and audio editing is LosslessCut. It seems to have slightly better editing features like, for example, allowing you to rearrange the order of video / audio segments. It is regularly updated and available on all platforms too. The only con is that it is an Electron app and thus unnecessarily big and a resource hog on older computers.