<p>You can't do it simply, but here's a pretty good work around.</p>
<p>First, cut near the desired position (at keyframes) with stream copy and then re-encode the frame-exact part of the video. Let's say:</p>
<pre><code>ffmpeg -ss 120 -t 40 -i input.mp4 -c copy -y temp.mp4
ffmpeg -i temp.mp4 -vcodec h264 -crf 21 -acodec mp3 -ss 1.080 -t 38.480 -y final.mp4
</code></pre>
<p>Thus, temp.mp4 starts <em>before</em> 120 sec and has a duration of <em>at least</em> 40 seconds
and final.mp4 has a duration of <em>exactly</em> 38.48 seconds.</p>
<p>When processing my home videos and stuff recorded from television, I use (-2s) for the desired start position and (+4s) for the duration. During re-encoding, I use milliseconds.</p>

CC BY-SA 4.0
2023-02-21T11:17:51.473Z
2023-02-23T03:40:15.203Z
2023-02-23T03:40:15.203Z
ThatsMe
<h2>No</h2>
<p>There is no way to precisely cut a video with FFmpeg if you need to cut outside an I-frame without re-encoding.</p>
<p>You could try software that can handle &quot;smart rendering&quot;, but I am not aware of any such software for Linux. On Windows, you could use &quot;TMPGEnc MPEG Smart Renderer&quot; or SolveigMM Video Splitter. The latter has serious performance issues. I highly recommend TMPGEnc, but it is not free.</p>

CC BY-SA 4.0
2022-08-03T07:25:01.343Z
2022-08-03T07:25:01.343Z
Arete
<p>I'm trying to cut a video (a debate on TV) with FFmpeg without re-encoding, and I need to cut between 2 sentences a guy pronounce. I think the precise moment is between two keyframes, because whatever the timestamp I try to cut at, I always get too much sound (and video) or too few. Here is my ffmpeg command line :</p>

<pre><code>ffmpeg -i video.mp4 -ss 0:0:0.9 -vcodec copy -acodec copy videoB.mp4 -y
</code></pre>

<p>I'm aware that the position of the <code>-ss</code> option in the command line matters: here, it is supposed to give me all the accuracy FFmpeg can offer. I know I'm probably trying to cut my video neither on a I-frame, nor on P- or B-frames.</p>

<p>So is there a way to get the closest (P- or B-) frame, doing some calculations with the preceding I-frame to generate a new I-frame, then start the video with this brand new I-frame and no sound, until the correct timestamp is reached. Then the video could go on normally.</p>

<p>I really don't want to bother me with re-encoding (which is an use of FFmpeg I don't master on command line). I'm using FFmpeg version 2.5.8-0ubuntu0.15.04.1.</p>

<p>Thanks.</p>

CC BY-SA 3.0
2015-11-01T13:06:40.620Z
You only wish to re-encode the split GOPs - that's called smart rendering. AFAIK, that's tricky to do manually with ffmpeg. Try SolveigMM Video Splitter - http://www.videohelp.com/software/SolveigMM-Video-Splitter
Gyan
CC BY-SA 3.0
2015-11-01T17:08:12.643Z
Thanks but I'm under Linux. Any other tool which would be more suitable to my environment ?
natsirt
CC BY-SA 3.0
2015-11-02T13:59:55.127Z
Also SolveigMM video splitter seems to not be free anymore ;D
user3450548
CC BY-SA 4.0
2019-06-20T18:56:08.617Z
"without re-encoding". Not going to happen on any keyframe based file type, with any tool. Only possible on non-keyframe based files. Just re-encode with high fidelity. If you do this a lot, reconsider your workflow to include non-keyframe based files, or port directly from your source files to your end-user file with a single encode (difficult to create a workflow like that, but well worth it if you can).
user3643
<video><ffmpeg><editing>
Using ffmpeg to cut videos with more precision than key frames allow
natsirt
# Using ffmpeg to cut videos with more precision than key frames allow

(Asked by: username_0 on 2015-11-01)

I'm trying to cut a video (a debate on TV) with FFmpeg without re-encoding, and I need to cut between 2 sentences a guy pronounce. I think the precise moment is between two keyframes, because whatever the timestamp I try to cut at, I always get too much sound (and video) or too few. Here is my ffmpeg command line :
ffmpeg -i video.mp4 -ss 0:0:0.9 -vcodec copy -acodec copy videoB.mp4 -y

I'm aware that the position of the -ss option in the command line matters: here, it is supposed to give me all the accuracy FFmpeg can offer. I know I'm probably trying to cut my video neither on a I-frame, nor on P- or B-frames.
So is there a way to get the closest (P- or B-) frame, doing some calculations with the preceding I-frame to generate a new I-frame, then start the video with this brand new I-frame and no sound, until the correct timestamp is reached. Then the video could go on normally.
I really don't want to bother me with re-encoding (which is an use of FFmpeg I don't master on command line). I'm using FFmpeg version 2.5.8-0ubuntu0.15.04.1.
Thanks.

**Tags:** video, ffmpeg, editing

> **Comments:**
> **username_1**: You only wish to re-encode the split GOPs - that's called smart rendering. AFAIK, that's tricky to do manually with ffmpeg. Try SolveigMM Video Splitter - http://www.videohelp.com/software/SolveigMM-Video-Splitter  
> **username_0**: Thanks but I'm under Linux. Any other tool which would be more suitable to my environment ?  
> **username_2**: Also SolveigMM video splitter seems to not be free anymore ;D  
> **username_3**: "without re-encoding". Not going to happen on any keyframe based file type, with any tool. Only possible on non-keyframe based files. Just re-encode with high fidelity. If you do this a lot, reconsider your workflow to include non-keyframe based files, or port directly from your source files to your end-user file with a single encode (difficult to create a workflow like that, but well worth it if you can).  

---

## 2 answers

### Answer by username_4 on 2023-02-21. Score: 2 | Accepted answer

You can't do it simply, but here's a pretty good work around.
First, cut near the desired position (at keyframes) with stream copy and then re-encode the frame-exact part of the video. Let's say:
ffmpeg -ss 120 -t 40 -i input.mp4 -c copy -y temp.mp4
ffmpeg -i temp.mp4 -vcodec h264 -crf 21 -acodec mp3 -ss 1.080 -t 38.480 -y final.mp4

Thus, temp.mp4 starts before 120 sec and has a duration of at least 40 seconds
and final.mp4 has a duration of exactly 38.48 seconds.
When processing my home videos and stuff recorded from television, I use (-2s) for the desired start position and (+4s) for the duration. During re-encoding, I use milliseconds.


---

### Answer by username_5 on 2022-08-03. Score: 3

## No

There is no way to precisely cut a video with FFmpeg if you need to cut outside an I-frame without re-encoding.

You could try software that can handle "smart rendering", but I am not aware of any such software for Linux. On Windows, you could use "TMPGEnc MPEG Smart Renderer" or SolveigMM Video Splitter. The latter has serious performance issues. I highly recommend TMPGEnc, but it is not free.


---

