本文整理汇总了Python中moviepy.video.io.VideoFileClip.VideoFileClip.subclip方法的典型用法代码示例。如果您正苦于以下问题:Python VideoFileClip.subclip方法的具体用法?Python VideoFileClip.subclip怎么用?Python VideoFileClip.subclip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moviepy.video.io.VideoFileClip.VideoFileClip
的用法示例。
在下文中一共展示了VideoFileClip.subclip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cut_video
# 需要导入模块: from moviepy.video.io.VideoFileClip import VideoFileClip [as 别名]
# 或者: from moviepy.video.io.VideoFileClip.VideoFileClip import subclip [as 别名]
def cut_video(recording_path, datapack_dir):
# Read the start/end pattern
sr1, pattern_wav = wav.read('pattern.wav')
workingdir = tempfile.mkdtemp()
# Open the video file
clip = VideoFileClip(recording_path)
# Save its audio track temporarily on disk
clip.audio.write_audiofile(os.path.join(workingdir,"temp_audio.wav"))
# Read the audio samples, mix down to mono (if necessary), and delete the temporary audio track
sr2, recording_wav = wav.read(os.path.join(workingdir,"temp_audio.wav"))
if recording_wav.shape[1]>1:
recording_wav = numpy.mean(recording_wav,1)
shutil.rmtree(workingdir)
# Detect the start and end audio pattern
start, end = detect_start_end_times(pattern_wav, recording_wav, sr2, 4)
# Cut the video and write it into two separate video and audio files
clip.subclip(start+0.4, end).write_videofile(os.path.join(datapack_dir, 'video.mp4'), codec='libx264')
clip.subclip(start+0.4, end).audio.write_audiofile(os.path.join(datapack_dir,'audio.wav'))
示例2: summarize
# 需要导入模块: from moviepy.video.io.VideoFileClip import VideoFileClip [as 别名]
# 或者: from moviepy.video.io.VideoFileClip.VideoFileClip import subclip [as 别名]
def summarize(filepath, new_filename, hotclips):
"""
Inputs a filepath for a video and generates a new shorter video
in that same filepath.
"""
# Only open the file once!
video = VideoFileClip(filepath)
chunks = [video.subclip(start, end)
for (start, end) in hotclips]
final_clip = concatenate(chunks)
# txt_clip = ( TextClip("Generated by vSummarize",
# fontsize=20, color='white')
# .set_pos('bottom')
# .set_duration(5))
# final_clip = CompositeVideoClip([summarized_video, txt_clip])
# Use the to_videofile default codec, libx264
# libx264 is much better than mpeg4, and still writes .mp4
# Use the fps of the original video.
final_clip.to_videofile(new_filename,
fps=video.fps,
audio_codec='mp3')