nonsenz
nonsenz

Reputation: 371

cutting a video with ffmpeg with an absolute endposition

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?

Upvotes: 2

Views: 2161

Answers (3)

mark4o
mark4o

Reputation: 60843

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.

Upvotes: 2

giancarlo colasante
giancarlo colasante

Reputation: 76

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[0]
   if len(t)==2:  return t[1]+t[0]*60
   if len(t)==3:  return t[2]+t[1]*60+t[0]*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[2].split(','):
  encode(argv[1],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.

Upvotes: 1

Álvaro
Álvaro

Reputation: 2870

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.

Upvotes: 0

Related Questions