5

I would like to trim - cut off frames at the beginning and end - a video that can be in a variety of different formats, and then save the trimmed video.

Are there any libraries or suggestions on how to do this?

Thanks!

Albeit
  • 738
  • 10
  • 21
  • 3
    Maybe http://stackoverflow.com/questions/220866/best-video-manipulation-library-for-python offers something appropriate. – phimuemue Sep 03 '11 at 07:47

1 Answers1

3

I've been using ffmpeg and the subprocess module of python to extract video thumbnails, but it seems ffmpeg can do pretty much anything.

Once you install ffmpeg, you can trim off the first second of video like so

> ffmpeg -i sample.mov  -ss 1 trim.mov

So using the subprocess module of python

import subprocess
seconds = "1" # has to be a string
subprocess.call(['ffmpeg', '-i', inputfilename, '-ss', seconds, outputfilename])

will take off the first second. For specific frames, there are flags like -vframes and -dframes, but I haven't actually used them. Documentation of ffmpeg here.

There's also pyffmpeg, a python wrapper for ffmpeg. But I haven't used it.

Zach
  • 189
  • 2
  • 11
  • It works if you have a saved video. I want to trim live video using my webcam. I have written the code. It is saving frames in a video and i want to remove the first frame after 30 seconds of video. – MUK Sep 10 '20 at 06:28