Search code examples
pythonffmpegvideo-capture

FFMPEG Frame-exact Video Cropping


Goal: To crop a video at a specific frame using FFMPEG

Problem: Video freezes at the end for ~1s

I'm new to FFMPEG, so not sure if any other details are needed to debug this.

import subprocess
import datetime

# Calculate start and end times in hh:mm:ss.ms
start_frame, end_frame = (9553, 10181)
start_time = str(datetime.timedelta(seconds=start_frame/fps))
end_time = str(datetime.timedelta(seconds=end_frame/fps))
            
cmd = ['ffmpeg', '-y', '-ss', start_time, '-to', end_time, '-i', input_path, '-c', 'copy', clip_path]
subprocess.call(cmd)

Values:

Start Frame: 9553
End Frame: 10181
Start Time: 0:06:22.120000
End Time: 0:06:47.240000

Solution

  • You will have to cut on key frames only or remove -c copy and re-encode.