The World’s Largest Online Community for Developers
I want to use ffmpeg to slice a video into parts. I have two absolute "positions" and not a start and a duration. So i can't use it like that:
ffmpeg -ss 00:00:12.12 -t 00:00:14.13 -i foo.mov...
(again, the time after -t is not a duration) Do i have to calculate the duration between the to positions or is there a way ffmpeg can do this for me?
As of FFmpeg 1.2 (released March 2013), the
-to option can be used in place of
-t to specify an end time instead of a duration.
Use this python script
#!/bin/python from sys import argv from os import system ffm = 'ffmpeg -i "' # input file aud = '" -acodec libfaac -aq 64 -ac 2 -ar 44100' vid = ' -vcodec libx264 -crf 25 -r 25 -subq 9' c=0 def encode(video,option=''): global c; c+=1 out = ' "'+ video + str(c) + '.mp4"' cmd = ffm + video + aud + vid + option + out print cmd; system(cmd) def seconds(time): t = [float(x) for x in time.split(':')] if len(t)==1: return t if len(t)==2: return t+t*60 if len(t)==3: return t+t*60+t*3600 def split(time): (start,end) = [seconds(x) for x in time.split()] return ' -ss %s -t %s' % (start,end-start) for slice in argv.split(','): encode(argv,split(slice)) # $ python split.py "video.mpg" "1:50 9:10,7:30 15:30,13:30 20:10"
Reading man ffmpeg i saw several accepted formats for -ss and -t
This let you slice with overlap. And can split with miliseconds precision.
$ python split.py "video.mpg" "55:30.356 1:01:10.895"
You have to edit acodec and vcodec with your preferences.
I recommend these options with a libx264 core greater than version 100.
With -ss you mark your start and with -t the final duration. The -t option indicates the diference between your two absolute positions, you have to calculate.