Without re-encode, split by key frames using segment format, then concat 1st and last segments:
ffmpeg -i "input.mp4" -c copy -f segment -segment_times 5,25 -reset_timestamps 1 %d.mp4 -y
echo "file 0.mp4" > 1.txt
echo "file 2.mp4" >> 1.txt
ffmpeg -f concat -i 1.txt -c copy out.mp4 -y
If partial re-encode, work with middle part only, then concat 1st, converted, last parts.
-segment_times
seek keyframe after specified time, for example → will cut to 8.4444444 sec, then from 25.333333 sec.
Edit: Yesh, variant with outpoint inpoint without re-encoding split by key frames:
echo "file input.mp4
outpoint 5
file input.mp4
inpoint 25" > 2.txt
ffmpeg -f concat -i 2.txt -c copy out2.mp4
To add edited middle segment just add line file edited.mp4
between 1st and last inputs.
Outpoint will cut nearly at 5 sec, inpoint will cut, for example, at 16.888889 sec, and may have wrong time while playing
So, try to find next keyframe:
f="2024-06-06_14꞉30꞉10.MOV"
o="out.mp4"
ofs=$(ffprobe -read_intervals 25%35 -skip_frame nokey -select_streams v:0 -show_entries frame=pts_time -of default=nw=1:nk=1 -v quiet "$f" | head -n 2 | tail -n 1)
echo "file '$f'
outpoint 5
file '$f'
inpoint $ofs" > 1.txt
cat 1.txt
ffmpeg -f concat -safe 0 -i 1.txt -c copy "$o" -y
mpv --ab-loop-a=4 --ab-loop-b=6 --ab-loop-count=inf --no-config "$o"