We cannot cut between keyframes, it's a technical limitation of modern video codecs. So ffmpeg will choose the nearest keyframe, which will not be the exact time you requested.
Might be able to use avcut for h264 although it is experimental. See #372 (comment)
See also discussion in #13
Update: Have made an initial implementation of this. This experimental feature will re-encode the part of the video from the cutpoint until the next keyframe in order to attempt to make a 100% accurate cut while losslessly copying the rest of the segment.
VideoRedo
VideoRedo is a now-defunct software that had feature overlap with LosslessCut.
Recently built in order to replace VideoRedo
They open sourced their smart cutting algorithm, could take inspiration from it: https://github.com/skeskinen/smartcut
Remaining issues
Inaccurate seeking
Seeking is not always accurate, causing glitches and/or jumps in the stitch points. This is often because I haven't found a way to consistently seek to and cut on an exact frame. Sometimes it could be caused by the "audio samples" problem below. If you want to experiment, you can try to remove the audio track and cut only video to see if it makes a difference. Another thing to try is to first remux the file to MP4/MOV and then do the smart cut. See #126 (comment)
Audio samples problem
Cut time accuracy/glitches when audio samples are large? (try without audio and see if it makes a difference). A workaround seems to be to cut audio/video separately and then merge them, with the tradeoff of potential audio/video de-sync:
subtitles
Other improvements
Done
Limitations
- Only works on some files:
- I've had success with some h264 files, and only a few h265 files seem to work.
- Other codecs may or may not work.
- Only supports cutting a single video stream (track). All other video streams have to be disabled. We could still probably do multi-passes and then recreate a file with all the streams.
- Thumbnail stream will be dropped
- We scan up to 60 seconds to find a keyframe.
- It tries to auto-detect bitrate from input stream, however if it fails, then it will calculate bitrate from the whole file's
size/duration (may be wrong)
- Tries to copy timebase from source to destination
We cannot cut between keyframes, it's a technical limitation of modern video codecs. So ffmpeg will choose the nearest keyframe, which will not be the exact time you requested.
Might be able to use avcut for h264 although it is experimental. See #372 (comment)
See also discussion in #13
Update: Have made an initial implementation of this. This experimental feature will re-encode the part of the video from the cutpoint until the next keyframe in order to attempt to make a 100% accurate cut while losslessly copying the rest of the segment.
VideoRedo
VideoRedo is a now-defunct software that had feature overlap with LosslessCut.
Smart Media Cutter
Recently built in order to replace VideoRedo
They open sourced their smart cutting algorithm, could take inspiration from it: https://github.com/skeskinen/smartcut
Remaining issues
Inaccurate seeking
Seeking is not always accurate, causing glitches and/or jumps in the stitch points. This is often because I haven't found a way to consistently seek to and cut on an exact frame. Sometimes it could be caused by the "audio samples" problem below. If you want to experiment, you can try to remove the audio track and cut only video to see if it makes a difference. Another thing to try is to first remux the file to MP4/MOV and then do the smart cut. See #126 (comment)
Audio samples problem
Cut time accuracy/glitches when audio samples are large? (try without audio and see if it makes a difference). A workaround seems to be to cut audio/video separately and then merge them, with the tradeoff of potential audio/video de-sync:
subtitles
Other improvements
Cannot find any keyframe after the desired start cut point, see #Smart cut failure: "Unable to find keyframe" #1190 (comment)Done
aomav1insteadlibsvtav1instead ofaomav1(ffmpeg default) (codec needs to compiled for mac in ffmpeg-build-script) Change smart cut AV1 encoder to libsvtav1 #1825Limitations
size/duration(may be wrong)