Description
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.
- https://www.videohelp.com/software/VideoReDo
- https://forum.videohelp.com/threads/407142-VideoReDo-owner-passed-away-product-ceased-seeking-alternatives#post2668738
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.
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:
- Smart Cut - option to cut audio separately in whole, then combine with video result (Request) #1834
- Audio becomes "stretched" around cut from Smart cut only with H264+AAC MP4 files. #2050
subtitles
Other improvements
- Smart Cut Custom Settings #1824
- If there is no keyframe in a particular segment, re-encode the whole segment instead of erroring with
Cannot find any keyframe after the desired start cut point
, see #Smart cut failure: "Unable to find keyframe" #1190 (comment)
Done
- Implement a smart cut that re-encodes (lossy) the part between the cutpoint and next keyframe. (done)
- Video quality gets degraded when "smart cutting" (experimental) #1606
- Investigate using
aomav1
insteadlibsvtav1
instead ofaomav1
(ffmpeg default) (codec needs to compiled for mac in ffmpeg-build-script) Change smart cut AV1 encoder to libsvtav1 #1825 - custom bit rate SmartCut extreme quality degradation for encoded part due to incorrect detected bitrate from stream #1997
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