當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。