0

I can cut the video based on seconds, for example, I can cut the video from second 0 to second 10 and from second 10 to second 20. But I need to cut the video from frame 0 to frame 250 and from frame 250 to frame 500 because of some error due the counting of second. Does anyone has any idea about this?

Here is the code I use to cut based on seconds:

required_video_file = "H8.avi"

with open("Z:/temp/Letícia/Videos/teste/times.txt") as f:
    times = f.readlines()

times = [x.strip() for x in times] 

for time in times:
    starttime = int(time.split('-')[0])
    endtime = int(time.split("-")[1])
    ffmpeg_extract_subclip(required_video_file, starttime, endtime, targetname=str(times.index(time)+1)+".avi")
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
LEstvs
  • 1
  • 1
  • OpenCV? wrong library. use PyAV or `imageio`. OpenCV is for computer vision, not for video editing. – Christoph Rackwitz Dec 15 '22 at 15:56
  • Using FFmpeg CLI (shell command), you may use [select filter](https://superuser.com/a/1365055/635712), or [trim filter](https://stackoverflow.com/a/63661027/4926757). Example with re-encoding: `ffmpeg -y -i H8.avi -vf select="between(n\,20\,50),setpts=PTS-STARTPTS" -vcodec libx264 -pix_fmt yuv420p out.avi`. In case you want to cut the video without re-encoding it may be possible, depending on the video codec of `H8.avi`. What is the video codec of `H8.avi`? – Rotem Dec 15 '22 at 21:20

0 Answers0