如何修改此脚本,使其可以利用 GPU 而不是 CPU - moviepy > VideoFileClip

问题描述 投票:0回答:0

我有以下脚本将视频分成块并获得一定数量的块。它运行良好,但使用 cpu 而不是我的 RTX 3090 GPU

如何让它在最终渲染中使用 GPU?非常感谢您的回答

import math
import moviepy.editor as mp
import subprocess
import sys


# Define the input video file path and desired output duration
input_file = "install_second_part_2x.mp4"
output_duration = 158  # in seconds

# Load the input video file into a moviepy VideoFileClip object
video = mp.VideoFileClip(input_file)

# Calculate the number of 5-second chunks in the video
chunk_duration = 5
num_chunks = math.ceil(video.duration / chunk_duration)

# Create a list to hold the selected chunks
selected_chunks = []

# Calculate the number of chunks to select
output_num_chunks = math.ceil(output_duration / chunk_duration)

# Calculate the stride between adjacent chunks to select
stride = num_chunks // output_num_chunks

# Loop through the chunks and select every stride-th chunk
for i in range(num_chunks):
    if i % stride == 0:
        chunk = video.subclip(i*chunk_duration, (i+1)*chunk_duration)
        selected_chunks.append(chunk)
    progress = i / num_chunks * 100
    sys.stdout.write(f"\rProcessing: {progress:.2f}%")
    sys.stdout.flush()

# Keep adding chunks until the output duration is reached
output = selected_chunks[0]
for chunk in selected_chunks[1:]:
    if output.duration < output_duration:
        output = mp.concatenate_videoclips([output, chunk])
    else:
        break


# Write the output video to a file
output_file = "install_part_cut.mp4"
output.write_videofile(output_file)
python moviepy pycuda
© www.soinside.com 2019 - 2024. All rights reserved.