Created
April 11, 2014 21:27
-
-
Save Robaum/10502969 to your computer and use it in GitHub Desktop.
Cut a movie second by second with ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clock starter | |
seconds = 0 | |
minutes = 0 | |
hours = 0 | |
frame=0 | |
movieFile = 'TheMovie.avi' | |
while True: | |
seconds +=1 | |
if seconds >= 60: | |
minutes += 1 | |
seconds = 0 | |
if minutes >= 60: | |
hours += 1 | |
minutes = 0 | |
second = 0 | |
frame+=1 | |
# Where is ffmpeg | |
FFMPEG_BIN = "ffmpeg.exe" | |
# Open an external process with python with the following parameters: | |
# -i The movie input | |
# -ss Second start, where the movie starts here we use the clock, H:M:S | |
# -t Play time, 1 second for this example, H:M:S | |
# -vcodec Force to use '.png' files | |
# -s Size of viewport is '640x480' (depends of the resolution of your movieFile) | |
# -r Starts a recording, 1 = true | |
# -f How is the file going to be read, in this case 'rawvideo' | |
# The last parameter is the output, in this case is frame + .png | |
subprocess.call([FFMPEG_BIN, "-i",movieFile, "-ss",str(hours)+":"+str(minutes)+":"+ str(seconds), "-t","00:00:01", "-vcodec","png", "-s","640x480", "-r","1", "-f","rawvideo", str(frame)+".png" ]) | |
# End of the movie timer, total time of the movie | |
if seconds == 00 and minutes == 00 and hours == 2: | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment