使用ffmpeg剪切视频,绝对位置

问题描述:

我想使用ffmpeg将视频分割为多个部分。我有两个绝对的“职位”,并且不是的开始和持续时间。所以我不能用它这样的:使用ffmpeg剪切视频,绝对位置

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

(再次,-t是不是一个持续时间后的时间)我要计算之间的持续时间位置还是有办法的ffmpeg一个能做到这一点为了我?

+0

http://*.com/questions/8488238/how-to-do-timecode-calculation是一个很好的解决方案,额外的计算 – nonsenz 2012-04-24 17:26:08

由于FFmpeg的1.2(发布2013年3月),更大的这些选项,该选项-to可以代替-t来代替指定结束时间持续时间。

随着-ss你标记你的开始和-t最后的持续时间。 -t选项表示您的两个绝对位置之间的差异,您必须计算。

使用此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