当前位置: 首页>>代码示例>>Python>>正文


Python VideoFileClip.subclip方法代码示例

本文整理汇总了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'))
开发者ID:chaosct,项目名称:repoVizzRecorder,代码行数:27,代码来源:repoVizzRecorder.py

示例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')
开发者ID:codelucas,项目名称:vsummarize,代码行数:27,代码来源:video.py


注:本文中的moviepy.video.io.VideoFileClip.VideoFileClip.subclip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。