2012-04-24 179 views
2

我想使用ffmpeg將視頻分割爲多個部分。我有兩個絕對的「職位」,並且不是的開始和持續時間。所以我不能用它這樣的:使用ffmpeg剪切視頻,絕對位置

ffmpeg -ss 00:00:12.12 -t 00:00:14.13 -i foo.mov... 

(再次,-t是不是一個持續時間後的時間)我要計算之間的持續時間位置還是有辦法的ffmpeg一個能做到這一點爲了我?

+0

http://stackoverflow.com/questions/8488238/how-to-do-timecode-calculation是一個很好的解決方案,額外的計算 – nonsenz 2012-04-24 17:26:08

回答

2

由於FFmpeg的1.2(發佈2013年3月),更大的這些選項,該選項-to可以代替-t來代替指定結束時間持續時間。

0

隨着-ss你標記你的開始和-t最後的持續時間。 -t選項表示您的兩個絕對位置之間的差異,您必須計算。

1

使用此python腳本

#!/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" 

閱讀人的ffmpeg我看見幾個接受的格式爲-ss-t

這讓你有重疊片。並且可以以毫秒精度分割。

$ python split.py "video.mpg" "55:30.356 1:01:10.895" 

你必須與你的喜好編輯acodec了vcodec

我建議用libx264核心比版本100