'Mediapipe save longer Video python

i got this code to cap a holistic of a Gopro Video:

file = 'GH010020.mp4'
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
cap = cv2.VideoCapture(file)

if cap.isOpened() == False:
    print("Error opening video stream or file")
    raise TypeError

length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

data = np.zeros((3, len(mp_pose.PoseLandmark), length))    


frame_num = 0
while cap.isOpened():
    ret, image = cap.read()
    if not ret:
        break

    image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
    results = pose.process(image)
    
    landmarks = results.pose_world_landmarks.landmark
    
    for i in range(len(mp_pose.PoseLandmark)):
        data[:, i, frame_num] = (landmarks[i].x, landmarks[i].y, landmarks[i].z)  
    
    frame_num += 1
            
cap.release()
#out.release()

i got data.shape of:

(3, 33, 22295)

I would like to save the given Video as mp4 file. With the Following Code i got an output mp4 video with a length of ~ 5sec. The original .mp4 File has a length of 6 Min.

fig = plt.figure()
# fig.set_size_inches(5, 5, True)
ax = fig.add_subplot(projection='3d')

anim = nb_helpers.time_animate(data, fig, ax)

# anim.save('walking_wireframe.gif',writer=PillowWriter(fps = 30))

anim.save('walking_wireframe.mp4', extra_args=['-vcodec', 'libx264'], dpi=300)

Does any of you got a proper Solution to save this? I would be grateful for any help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source