ffmpeg – Fast and relatively accurate cutting from a video

I’m trying to build an application, which cuts specific small sections from videos. To be more precise, it cuts out what the person is saying according to the timestamps in the subtitles. Cutting with the following command

ffmpeg -ss 346 -i input.avi -t 5 -c copy -y output.mp4

is very fast and accurate enough, but I’m not sure that it is memory-effecient due to the “faking” that MP4 performs. I’ve also tried cutting with the following command:

ffmpeg -i input.avi -ss 346 -t 5 -c copy output.mp4

In this case, ffmpeg can cut at non-keyframes, so videos often don’t play properly at the beginning, which is critical for me.

I was trying to avoid decoding and encoding because my application has to process multiple videos at a time, so it might be too slow this way. I’ve already thought about forcing ffmpeg to make a keyframe at the beginning of the required section and then use the first command, but I’m not sure if that would be fast. As far as I’m concerned, making keyframes is not an easy operation. And my top priorities are time-efficiency and relative accuracy. So now I don’t know which of these options works best for my case. I would appreciate any help.