I was trying to do something the other day and couldn’t figure it out, if anyone has any ideas.
The end goal is to provide a set of video files, with time stamps for each, splicing them into one file while removing parts I don’t want.
That is straightforward enough, as long as you’re willing to re-encode the whole file. Otherwise, it seems like ffmpeg is restricted to make cuts at key frames.
It’s rare for the key frame to be placed at the exact spot I would want to make a cut, so the section of the video around the cut would need to be re-encoded. Ideally that would be the only part hat is re-encoded - everything else would be a a straight transcode from key frame to key frame.
I believe this is called ‘smart rendering’, and the pages I could find in the past said ffmpeg isn’t really suited for it, or it’s very difficult.
Does anyone know if that has changed recently, or have found a way to do it?
Depending on the container format, you may not need to re-encode anything. .mp4 supports "edit lists". You can create a .mp4 file that starts at the latest key frame <= the starting timestamp of interest, onward through the ending timestamp of interest. And has an edit list that tells the player to skip the unwanted prefix. You can have arbitrarily many of these in one file. I do this as part of a larger program (security camera NVR), although directly writing the .mp4 rather than instructing ffmpeg to do so.
Afraid I don't know how to do what you want with the ffmpeg commandline tool, though, either by partial re-encoding or by edit lists.
Yes, this is possible, depending on the codec and container. I have done similar operations with h264+mp4.
It's good to be able to edit video without losing quality.
Are you sure you need sub-keyframe precision? In h264+aac+mp4, for example, if it's not keyframe aligned, the result is usually a stalled video frame for a split second, but since the audio continues smoothly, it's not that noticeable.
If you know the exact codec settings that were used to encode the video, you can create new pieces to be fit losslessly together. Otherwise, it is more difficult.
Contact me on twitter at @downpoured and I can describe more.
I was trying to do something the other day and couldn’t figure it out, if anyone has any ideas.
The end goal is to provide a set of video files, with time stamps for each, splicing them into one file while removing parts I don’t want.
That is straightforward enough, as long as you’re willing to re-encode the whole file. Otherwise, it seems like ffmpeg is restricted to make cuts at key frames.
It’s rare for the key frame to be placed at the exact spot I would want to make a cut, so the section of the video around the cut would need to be re-encoded. Ideally that would be the only part hat is re-encoded - everything else would be a a straight transcode from key frame to key frame.
I believe this is called ‘smart rendering’, and the pages I could find in the past said ffmpeg isn’t really suited for it, or it’s very difficult.
Does anyone know if that has changed recently, or have found a way to do it?