2014-03-29 103 views
1

是否有一種簡單的方法來修剪Python中的視頻文件。如果我知道開始時間和結束時間,我想根據輸入將新文件保存爲多個較短的文件。Python視頻編輯 - 如何修剪視頻

示例僞代碼:

function cut_video(original_vid, start, stop): 
    original_vid.start_time(start) 
    original_vid.end_time(stop) 
    original_vid.trim() #based on times 
    new_vid = original_vid 
    return new_vid 

回答

2

實測值的溶液:

def get_ffmpeg_bin(): 
    ffmpeg_dir = helper_functions.get_ffmpeg_dir_path() 
    FFMPEG_BIN = os.path.join(ffmpeg_dir, "ffmpeg.exe") 
    return FFMPEG_BIN 


def split_vid_from_path(video_file_path, start_time, end_time): 
    ffmpeg_binary = get_ffmpeg_bin() 
    output_file_name = get_next_file_name(video_file_path) 
    pipe = sp.Popen([ffmpeg_binary,"-v", "quiet", "-y", "-i", video_file_path, "-vcodec", "copy", "-acodec", "copy", 
       "-ss", start_time, "-t", end_time, "-sn", output_file_name ]) 


    pipe.wait() 
    return True 


sample_vid = os.path.join(get_sample_vid_dir_path(), "Superman-01-The_Mad_Scientist.mp4") 
split_vid_from_path(sample_vid, "00:00:00", "00:00:17")